MCPcopy Create free account
hub / github.com/GarageGames/Torque3D / value

Method value

Engine/source/T3D/cameraSpline.cpp:292–395  ·  view source on GitHub ↗

-----------------------------------------------------------------------------

Source from the content-addressed store, hash-verified

290
291//-----------------------------------------------------------------------------
292void CameraSpline::value(F32 t, CameraSpline::Knot *result, bool skip_rotation)
293{
294 // Do some easing in and out for t.
295 if(!gBuilding)
296 {
297 F32 oldT = t;
298 if(oldT < 0.5f)
299 {
300 t = 0.5f - (mSin( (0.5 - oldT) * M_PI ) / 2.f);
301 }
302
303 if((F32(size()) - 1.5f) > 0.f && oldT - (F32(size()) - 1.5f) > 0.f)
304 {
305 oldT -= (F32(size()) - 1.5f);
306 t = (F32(size()) - 1.5f) + (mCos( (0.5f - oldT) * F32(M_PI) ) / 2.f);
307 }
308 }
309
310 // Verify that t is in range [0 >= t > size]
311// AssertFatal(t >= 0.0f && t < (F32)size(), "t out of range");
312 Knot *p1 = getKnot((S32)mFloor(t));
313 Knot *p2 = next(p1);
314
315 F32 i = t - mFloor(t); // adjust t to 0 to 1 on p1-p2 interval
316
317 if (p1->mPath == Knot::SPLINE)
318 {
319 Knot *p0 = (p1->mType == Knot::KINK) ? p1 : prev(p1);
320 Knot *p3 = (p2->mType == Knot::KINK) ? p2 : next(p2);
321 result->mPosition.x = mCatmullrom(i, p0->mPosition.x, p1->mPosition.x, p2->mPosition.x, p3->mPosition.x);
322 result->mPosition.y = mCatmullrom(i, p0->mPosition.y, p1->mPosition.y, p2->mPosition.y, p3->mPosition.y);
323 result->mPosition.z = mCatmullrom(i, p0->mPosition.z, p1->mPosition.z, p2->mPosition.z, p3->mPosition.z);
324 }
325 else
326 { // Linear
327 result->mPosition.interpolate(p1->mPosition, p2->mPosition, i);
328 }
329
330 if (skip_rotation)
331 return;
332
333 buildTimeMap();
334
335 // find the two knots to interpolate rotation and velocity through since some
336 // knots are only positional
337 S32 start = (S32)mFloor(t);
338 S32 end = (p2 == p1) ? start : (start + 1);
339 while (p1->mType == Knot::POSITION_ONLY && p1 != front())
340 {
341 p1 = prev(p1);
342 start--;
343 }
344
345 while (p2->mType == Knot::POSITION_ONLY && p2 != back())
346 {
347 p2 = next(p2);
348 end++;
349 }

Callers 2

interpolateMatMethod · 0.45
resetMethod · 0.45

Calls 8

mSinFunction · 0.85
mCosFunction · 0.85
mFloorFunction · 0.85
mCatmullromFunction · 0.85
sizeFunction · 0.50
nextFunction · 0.50
prevFunction · 0.50
interpolateMethod · 0.45

Tested by

no test coverage detected