Game Development Community

Strange Billboard orientation

by Wesley Hopson · in Torque 3D Professional · 10/23/2011 (4:31 am) · 3 replies

I ran across some weird seeming behavior in the manner that billboards would orientate themselves to the camera often causing them to twist oddly. Looking through the code I found in tsMesh.cpp at about line 173

if (getFlags(Billboard))
   {
      Point3F camPos = state->getDiffuseCameraPosition();
      Point3F objPos;
      objToWorld.getColumn(3, &objPos);
      Point3F targetVector = camPos - objPos;
      if(getFlags(BillboardZAxis))
         targetVector.z = 0.0f;
      targetVector.normalize();
      MatrixF orient = MathUtils::createOrientFromDir(targetVector);
      orient.setPosition(objPos);
      orient.scale(objToWorld.getScale());

      coreRI->objectToWorld = renderPass->allocUniqueXform( orient );
   }
   else
      coreRI->objectToWorld = renderPass->allocUniqueXform( objToWorld );

I find this really odd because this is orientating the billboard based on the cameras position in relation to the billboard mesh. It does not take into account where we happen to be looking. So does not orientate to face the camera. Anyway it is a really quick and simple fix to change it so that it does face the camera.

if (getFlags(Billboard))
   {
      //Point3F camPos = state->getDiffuseCameraPosition();
      Point3F objPos;
      objToWorld.getColumn(3, &objPos);
      //Point3F targetVector = camPos - objPos;
	  Point3F targetVector = state->getVectorEye();
      if(getFlags(BillboardZAxis))
         targetVector.z = 0.0f;
      targetVector.normalize();
      MatrixF orient = MathUtils::createOrientFromDir(targetVector);
      orient.setPosition(objPos);
      orient.scale(objToWorld.getScale());

      coreRI->objectToWorld = renderPass->allocUniqueXform( orient );
   }
   else
      coreRI->objectToWorld = renderPass->allocUniqueXform( objToWorld );

Now the reason I am posting this, is that I am really baffled as to why it is setup like this. Is there some feature that uses billboards aligned in this manner, I am messing up or is it just a bug in the code?

FYI: this change also apparently flips the side of the billboard that is facing the camera easy to flip it back perhaps by reversing the vectors magnitude if you have too.

#1
10/23/2011 (5:39 am)
You can replace:
Point3F targetVector = camPos - objPos;

with:
MatrixF T = state->getCameraTransform();
Point3F targetVector;
T.getColumn(1,&targetVector);
targetVector.neg();

so they should face the camera.
#2
10/23/2011 (4:36 pm)
This is the old billboard feature within the TSShape class... its been that way forever and i can't say why. Ths change looks ok to me, but it probably will affect some old legacy DTS files.

Note this won't affect anything in the forest or an TSLastDetail (aka autobillboard) imposters which use a completely different system.
#3
10/23/2011 (5:11 pm)
hmm considering I made this change so that my billboard objects would act the same as they did in TGE i think it is probably safe to say legacy is fine.

Plus if it does not effect anything else all the better in my book.