コード例 #1
0
/*
================
idSplineList::initPosition
================
*/
void idSplineList::initPosition(long bt, long totalTime) {

	if (dirty) {
		buildSpline();
	}

	if (splinePoints.Num() == 0) {
		return;
	}

	baseTime = bt;
	time = totalTime;

	// calc distance to travel ( this will soon be broken into time segments )
	splineTime.Clear();
	splineTime.Append(bt);
	double dist = totalDistance();
	double distSoFar = 0.0;
	idVec3 temp;
	int count = splinePoints.Num();
	//for(int i = 2; i < count - 1; i++) {
	for(int i = 1; i < count; i++) {
		temp = *splinePoints[i-1];
		temp -= *splinePoints[i];
		distSoFar += temp.Length();
		double percent = distSoFar / dist;
		percent *= totalTime;
		splineTime.Append(percent + bt);
	}
	assert(splineTime.Num() == splinePoints.Num());
	activeSegment = 0;
}
コード例 #2
0
ファイル: splines.cpp プロジェクト: Diskutant/RTCW-SP
float idSplineList::totalDistance()
{

	// FIXME: save dist and return
	//
	if(controlPoints.Num() == 0)
	{
		return 0.0;
	}

	if(dirty)
	{
		buildSpline();
	}

	float dist = 0.0;
	idVec3 temp;
	int count = splinePoints.Num();

	for(int i = 1; i < count; i++)
	{
		temp = *splinePoints[i - 1];
		temp -= *splinePoints[i];
		dist += temp.Length();
	}

	return dist;
}
コード例 #3
0
ファイル: splines.cpp プロジェクト: Fixman/metnum-TP3
PixelTiempo Splines::alentarPixel(const PixelTiempo &P, int c0, int c1) const
{
	int q = (c1 - 1) / (c0 - 1);

	PixelTiempo r(c1);

	bool finish = false;
	for (int f = 0; f <= (c0 - 1) / reset && !finish; f++)
	{
		int first = f * reset;
		int last = std::min(reset * (f + 1), (int) P.size() - 1);

		if (std::min(reset * (f + 2), (int) P.size() - 1) - last < 2)
		{
			last = P.size() - 1;
			finish = true;
		}

		std::vector <Polynomial> z = buildSpline(Vector(P.begin() + (f * reset), P.begin() + last), q);
		for (int i = 0; i < last - (f * reset); i++)
		{
			for (int j = 0; j < q; j++)
			{
				double x = ((f * reset + i) * q) + j;
				r[x] = toPixel(z[i].a + z[i].b * j + z[i].c * std::pow(j, 2) + z[i].d * std::pow(j, 3));
			}
		}
	}
	r[c1 - 1] = P[c0 - 1];

	return r ;
}
コード例 #4
0
/*
================
idSplineList::validTime
================
*/
bool idSplineList::validTime() {
	if (dirty) {
		buildSpline();
	}
	// gcc doesn't allow static casting away from bools
	// why?  I've no idea...
	return (bool)(splineTime.Num() > 0 && splineTime.Num() == splinePoints.Num());
}
コード例 #5
0
ファイル: splines.cpp プロジェクト: 3ddy/Jedi-Academy
void idSplineList::draw(bool editMode) {
	int i;
	vec4_t yellow(1, 1, 0, 1);
        
	if (controlPoints.Num() == 0) {
		return;
	}

	if (dirty) {
		buildSpline();
	}


	qglColor3fv(controlColor);
	qglPointSize(5);
	
	qglBegin(GL_POINTS);
	for (i = 0; i < controlPoints.Num(); i++) {
		qglVertex3fv(*controlPoints[i]);
	}
	qglEnd();
	
	if (editMode) {
		for(i = 0; i < controlPoints.Num(); i++) {
			glBox(activeColor, *controlPoints[i], 4);
		}
	}

	//Draw the curve
	qglColor3fv(pathColor);
	qglBegin(GL_LINE_STRIP);
	int count = splinePoints.Num();
	for (i = 0; i < count; i++) {
		qglVertex3fv(*splinePoints[i]);
	}
	qglEnd();

	if (editMode) {
		qglColor3fv(segmentColor);
		qglPointSize(3);
		qglBegin(GL_POINTS);
		for (i = 0; i < count; i++) {
			qglVertex3fv(*splinePoints[i]);
		}
		qglEnd();
	}
	if (count > 0) {
		//assert(activeSegment >=0 && activeSegment < count);
		if (activeSegment >=0 && activeSegment < count) {
			glBox(activeColor, *splinePoints[activeSegment], 6);
			glBox(yellow, *splinePoints[activeSegment], 8);
		}
	}

}