Game Development Community

FIX: fxLight flares not spinning

by Jeff Faust · in Torque Game Engine Advanced · 10/19/2007 (1:30 pm) · 1 replies

Recently discovered that the flares in fxLight and objects inheriting from it (sgLightObject and VolumeLight) were not spinning.

A quick look at the code revealed that the old TGE code which used glrotatef() to do the work, was commented out and nothing was put in it's place.

Here is a fix which goes in engine/game/fx/fxLight.cpp in the renderObject() method around line 1510:
// Only draw if needed.
if (BBRadius > 0)
{
   [b]if (mDataBlock->mUseRotation)
   {
      // Initialize points with basic info
      Point3F points[4];
      points[0] = Point3F(-BBRadius, 0.0, -BBRadius);
      points[1] = Point3F( BBRadius, 0.0, -BBRadius);
      points[2] = Point3F( BBRadius, 0.0,  BBRadius);
      points[3] = Point3F(-BBRadius, 0.0,  BBRadius);

      F32 sy, cy;
      mSinCos(mDegToRad(-mAnimationRotation), sy, cy);

      // Finalize points
      for(int i = 0; i < 4; i++)
         points[i].set(cy * points[i].x - sy * points[i].z, 0.0, sy * points[i].x + cy * points[i].z);

      // Draw Billboard.
      PrimBuild::begin(GFXTriangleFan, 4);
      PrimBuild::texCoord2f(0, 1);
      PrimBuild::vertex3fv(points[0]);
      PrimBuild::texCoord2f(1, 1);
      PrimBuild::vertex3fv(points[1]);
      PrimBuild::texCoord2f(1, 0);
      PrimBuild::vertex3fv(points[2]);
      PrimBuild::texCoord2f(0, 0);
      PrimBuild::vertex3fv(points[3]);
      PrimBuild::end();
   }
   else
   {[/b]
      // Rotate, if we have a rotation.
      //if (mAnimationRotation != 0.0f) glRotatef(mAnimationRotation, 0, 1, 0);

      // Draw Billboard.
      //glBegin(GL_QUADS);
      PrimBuild::begin(GFXTriangleFan, 4);
      PrimBuild::texCoord2f(0, 0);
      PrimBuild::vertex3f(-BBRadius, 0, BBRadius);
      PrimBuild::texCoord2f(1, 0);
      PrimBuild::vertex3f(BBRadius, 0, BBRadius);
      PrimBuild::texCoord2f(1, 1);
      PrimBuild::vertex3f(BBRadius, 0, -BBRadius);
      PrimBuild::texCoord2f(0, 1);
      PrimBuild::vertex3f(-BBRadius, 0, -BBRadius);
      PrimBuild::end();
      //glEnd();
   [b]}[/b]
}

I've checked this solution against the TGE implementation and speed of rotation, direction, and image orientation all appear to match.