void TrainView::drawTrack(bool doingShadows, int typeCubic)
{
	if(!doingShadows)
		glColor3d(0.0,0.0,1.0);

	float tensionScale = 1 - static_cast<float>(tw->tens->value());

	size_t numPoints = world->points.size();

	pointsOfLine.resize((numSegs+0)*numPoints);
	//go thru all the control points
	// figure out the points of the segments that make it up.
	for(size_t i = 0; i < numPoints; i++)
	{
		glBegin(GL_LINE_STRIP);
		//get the nearby control points that define the curve...
		Pnt3f p0 = world->points[i].pos;
		Pnt3f p1 = world->points[(i+1) % numPoints].pos;
		Pnt3f p2 = world->points[(i+2) % numPoints].pos;
		Pnt3f p3 = world->points[(i+3) % numPoints].pos;

		for(int j = 0; j <= numSegs; j++)
		{
			//how far into the curve we are
			float percentIn = (float)j/numSegs;

			Pnt3f tmpPoint;
			//compute the points on the curve using linear interpolation...
			if(typeCubic == LINEAR)
			{
				tmpPoint.x = getLinear(percentIn, p0.x, p1.x);
				tmpPoint.y = getLinear(percentIn, p0.y, p1.y);
				tmpPoint.z = getLinear(percentIn, p0.z, p1.z);
			}
			//...or the much prettier cardinal cubic points
			else if(typeCubic == CARDINALCUBIC)
			{
				tmpPoint.x = getValueAt(percentIn, tensionScale, p0.x, p1.x, p2.x, p3.x);
				tmpPoint.y = getValueAt(percentIn, tensionScale, p0.y, p1.y, p2.y, p3.y);
				tmpPoint.z = getValueAt(percentIn, tensionScale, p0.z, p1.z, p2.z, p3.z);
			}

			//we need to store all but the last points for later on,
			// so just copy them over to a more permenant place.
			if(j != numSegs)
			{
				pointsOfLine[i*numSegs + j] = tmpPoint;
			}

			glVertex3fv(tmpPoint.v());
		}
		glEnd();
	}
}
//get the value at a point using the Cardinal Cubic spline
float TrainView::getValueAt(float u, float t, float p0, float p1, float p2, float p3)
{
	float a0 = p1;
	float a1 = (-t)*(p0) + t*(p2);
	float a2 = ( (2*t) * p0) + ( (t - 3)* p1 ) + ( ( 3- (2*t) ) * p2 ) + ( (-t)*p3 );
	float a3 = (-t)*p0 + (2-t)*p1 + (t-2)*p2 + (t)*p3;

	return a0 + a1*u + (a2*powf(u,2)) + (a3*powf(u,3));
}

// get the value at the point for the linear "spline"
float TrainView::getLinear(float u, float p0, float p1)
{
	float a0 = p0;
	float a1 = p1 - p0;
	return a0 + u * a1;
}