I don't know if I understand everything right...
But basically in TANX I did those kind of calculations by just having some values for speed, angle, turretangle, position etc. Nearly all calculations are done in 2D in Tanx, because I had a plain terrain there. Only when things exploded, the Z-value came into calculation for position (things flying to camera).
So, when pressing left/right keys you should alter angle. When moving the mouse left/right you should alter turretangle. Pressing up/down would alter speed (velocity).
Thats all you need in the first place.
Calculation of new position would be something like this:
Pos.x := Pos.x + sin(angle) * speed;
Pos.y := Pos.y + cos(angle) * speed;
Thats all to move the tank.
rotation of you model is given by angle, too.
rotation of your turret is given by angle+turretangle, because you want the turret to move too when you turn the tank, don't you?
Then when rendering the model its just something like this:
ClearWorldMatrix;
RotateWorldY(tank.angle);
TranslateWorld(tank.x,tank.y,tank.z);
DrawTankCorpse;
ClearWorldMatrix;
RotateWorldY(tank.angle+tank.turretangle);
TranslateWorld(tank.x,tank.y,tank.z);
DrawTankTurret;
All this is written out of my head in PseudoCode. I did not test anything, but basically this should enable you to turn and move your tank.
Hope that helps. If there are further questions... you know where to find me
Bookmarks