Game Development Community

Wheel shadows in TGEA

by Adternative · in Torque Game Engine Advanced · 09/18/2007 (6:30 am) · 3 replies

Hi!

My vehicle wheels are not projecting shadows, I have reviewed the C++ code and it seems that this feature is not implemented. The wheels are rendered in the WheeledVehicle::prepBatchRender, but I can't find any place where their shadows are taken into account. Am I missing something?

The TGE starter racing demo projects wheel shadows, but I suppose that this was a feature done in TGE not ported to TGEA. Am I right?

Anyway, what method can you recommend me to solve this problem? I would like to know how to configure an object in 3dsmax so that it projects shadows but it is not rendered.

Thank you!!!

#1
09/18/2007 (4:33 pm)
I added this to the end of sgShadowProjector::sgRenderShadowBuffer()...

WheeledVehicle *vehicle = dynamic_cast<WheeledVehicle*>(sgParentObject);
if ( vehicle )
{
   const U32 wheels = vehicle->getWheelCount();
   for ( U32 i=0; i < wheels; i++ )
   {
         MatrixF shapeworld;
         TSShapeInstance *wheelinst;
         vehicle->getWheelInstAndTransform( i, &wheelinst, &shapeworld );

         lightspace.mul(sgWorldToLightY, shapeworld);
         lightspace.scale(Point3F(sgProjectionScale, sgProjectionScale, sgProjectionScale));
         
         Point3F pos = lightspace.getPosition();
         pos.convolve(Point3F(sgProjectionScale, sgProjectionScale, sgProjectionScale));
         lightspace.setPosition(pos);
         
         newmat.mul(proj, lightspace);
         sgRenderShape(wheelinst, newmat, 0, newmat, -1);
    }
}

And added this to WheeledVehicle....

void WheeledVehicle::getWheelInstAndTransform( S32 index, TSShapeInstance** inst, MatrixF* xfrm )
{
   Wheel* wheel = &mWheel[index];
   *inst = wheel->shapeInstance;
 
   if ( !wheel->shapeInstance )
      return;
 
   MatrixF world = getRenderTransform();
   world.scale( mObjScale );
 
   // Steering & spring extension
   F32 angle = mSteering.x;
   if (  ( angle < 0 && wheel->data->pos.x > 0 ) ||
         ( angle > 0 && wheel->data->pos.x < 0 ) )
      angle *= mDataBlock->ackermannRatio;
   MatrixF hub(EulerF(0,0,angle));
   Point3F pos = wheel->data->pos;
   pos.z -= wheel->spring->length * wheel->extension;
   hub.setColumn(3,pos);
   world.mul(hub);
 
   // Wheel rotation
   MatrixF rot(EulerF(wheel->apos * M_2PI,0,0));
   world.mul(rot);
 
   // Rotation the tire to face the right direction
   // (could pre-calculate this)
   MatrixF wrot(EulerF(0,0,(wheel->data->pos.x > 0)? M_PI/2: -M_PI/2));
   world.mul(wrot);
 
   *xfrm = world;
}
#2
10/09/2007 (4:54 am)
It works perfectly, thanks mate!!!

btw, what is that ackermannRatio??

It seems like a modification you have done to the standard car model. We are currently doing a car game, and it seems that you have quite experience in this kind of game. We are experiencing some problems with the collision system, can we ask you some questions about how you resolved it?

Thank you!!!
#3
10/09/2007 (12:23 pm)
@Adternative - Ackermann steering geometry.

We had issues with the collision system as well... i can't say we have a perfect solution yet. We had a thread over here that discussed the issues and some fixes.