Add wheel shadows
by Kage · 12/18/2005 (6:51 pm) · 9 comments
Several changes:
Header Files
Source Files
List of changes.
You can define the LOD_WHEEL_SHADOW to enable LOD wheel shadows.
Header Files
[b]ShapeBase.h[/b] virtual void addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow); [b]Vehicle.h[/b] void addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow); [b]WheeledVehcile.h[/b] void addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow);
Source Files
List of changes.
[b]ShapeBase.cc[/b]
void ShapeBase::addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow)
{
// empty stuff
}
and importantly, in
void ShapeBase::renderShadow(F32 dist, F32 fogAmount)
{
.
.
.
[i]after this line, and before the end of this condition code, add a call to addShadowDetail [/i]
if (mShadow->needBitmap())
{
[b] addShadowDetail(dist, fogAmount, mShadow);[/b]
}
.
.
.
}
[b][vehicle.cc][/b]
void Vehicle::addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow)
{
//empty for now
}
[b][wheeledvehicle.cc][/b]
void WheeledVehicle::addShadowDetail(F32 dist, F32 fogAmount, Shadow *shadow)
{
Parent::addShadowDetail(dist, fogAmount, shadow);
if ( shadow )
{
Wheel* wend = &mWheel[mDataBlock->wheelCount];
for (Wheel* wheel = mWheel; wheel < wend; wheel++)
{
if (wheel->shapeInstance)
{
MatrixF mat = getRenderTransform();
Point3F rdpos = mat.getPosition();
// Steering & spring extension
MatrixF hub(EulerF(0,0,mSteering.x * wheel->steering));
Point3F pos = wheel->data->pos;
pos.z -= wheel->spring->length * wheel->extension;
hub.setColumn(3,pos);
mat.mul(hub);
// 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));
mat.mul(wrot);
// shadow details
#ifdef LOD_WHEEL_SHADOW
shadow->selectShapeDetail(wheel->shapeInstance, dist, 1.0f);
#else
wheel->shapeInstance->setCurrentDetail(0);
#endif
// render shadow
shadow->renderToBitmap(wheel->shapeInstance, mat, rdpos, Point3F(1,1,1));
}
}
}
}You can define the LOD_WHEEL_SHADOW to enable LOD wheel shadows.
About the author
Professional gameplay programmer and have worked in the industry since 2004. Specialized in: animation system, player control, weapon system, AI, combat, camera, physics - ODE/Havok, optimization, and networking.
#2
12/22/2005 (10:29 am)
Exactly where in the header files should those lines go?
#3
12/22/2005 (6:23 pm)
@BigPapa - anywhere in the function definition section. From the looks of the function I'm guessing they belong after a "protected:" keyword. If that causes a compiler error, try after "public:"
#4
I think i placed the code in the correct locations but i'm baffled.
12/27/2005 (12:12 pm)
Can't get it to compile. I get this error:Compiling...
wheeledVehicle.cc
..\engine\game\vehicles\wheeledVehicle.cc(1465) : error C2027: use of undefined type 'Shadow'
../engine\game/shapeBase.h(38) : see declaration of 'Shadow'
..\engine\game\vehicles\wheeledVehicle.cc(1465) : error C2227: left of '->renderToBitmap' must point to class/struct/union/generic typeI think i placed the code in the correct locations but i'm baffled.
#6
Thanks :)
01/04/2006 (11:42 am)
I noticed this, but it was really far down on my todo list. Added it with no problemsThanks :)
#7
01/09/2006 (4:14 am)
#8
03/13/2006 (7:52 am)
#9
01/04/2008 (4:52 am)
having problems adding this in... everything seems fine but when i look in the direction of the vehicle the engine crashes 
Torque Owner Trenton Shaffer