Game Development Community

No rotation clamping in Camera class?

by Chad Hall · in Torque 3D Professional · 12/17/2014 (9:07 pm) · 3 replies

I notice that the camera rotation (more specifically the mRot values) don't get clamped. If you start a mission and go into the fly cam mode (alt+c) while printing out the camera rotation values it just keeps going until it maxes/mins out the float. From what I understand it should be clamped as there is never a reason for it's value to go to those ranges and floating point precision issues will occur. Player objects, for example, clamp rotation between 0 and 6.28.

Noticed this when I was trying to compare camera rotation values in orbit mode. I added a clamp to mRot.z in the processTick for the Camera class and haven't noticed any issues.

Is there a reason the values are not clamped already?

Code I added was:

...
      pos += posVec;
   }

   // Clamp rotation value between 0 and M_2PI_F. ---
   while (mRot.z < 0.0f)
      mRot.z += M_2PI_F;
   while (mRot.z > M_2PI_F) 
      mRot.z -= M_2PI_F;
   // ---

   _setPosition(pos,mRot);

   // If on the client, calc delta for backstepping
   if (serverInterpolate || isClientObject())
   {
...

#1
12/21/2014 (9:31 am)
Not necessarily, bacause rotation is based on periodic functions.
They don't clamp, because "while" will force an eventual compiler optimization.
#2
12/21/2014 (2:27 pm)
While loops are used in other places to clamp values, and I think clamping these values is a good idea, to avoid, as you say, a lack of precision in extreme cases where a large angle accumulates.
#3
12/29/2014 (6:17 am)
I would prefer to clamp using fmod(mRot.z, 2*M_PI) btw..