# More Turret Rotation Woes

## Recommended Posts

ankhd    2304

Hi All.

I rotate my turrets based of how the animation manager does is if it was exported with the animation. This works fine when there is no

turrets on top of another turret Like this image here. Its shooting at a target the main big turret is pointing at it but the small one on top is out. Ther small turret looks like its out by the amout the main turret is rotated to face target.

Any Ideas how to update my matrix now.

the turrets are pointing to the front of the vehicle when exported

and the small turrets base bone is linked to the main turrets base bone so it should be offset correct.

Image....

this is how Im doing it in code;

//make a rotation matrix

//animation manager does this
//Anim->m_Bone->TransformationMatrix *= mInvBindPose;// matRotation;

D3DXMatrixIdentity(&temp);

temp *= mSpin;
temp *= FrameTurretBase[ctr]->TransformationMatrix;

FrameTurretBase[ctr]->TransformationMatrix = temp;

//end turret base

//now do the elevation rotation axis is  X elevation and Z Spin

//make the elevation rotation

D3DXMatrixIdentity(&temp);

temp *= mSpinElevation;
temp *= FrameTurretElevation[ctr]->TransformationMatrix;
FrameTurretElevation[ctr]->TransformationMatrix = temp;//

//end elevation
///////////////////////////////////////////////////////////////////////////////////////////////



##### Share on other sites
Jacob Mnasin    160

My guess is that if the small turret is linked to the larger turrets bone or rotation then u would have to subtract the rotation of the main gun when u want to rotate it independently.

Or you can link the smaller turret to the root of the tank this way you can rotate it independently.

Edited by JacobM

##### Share on other sites
ankhd    2304

I know whats happening now the small turret inheritance the main turrets rotation as well as its own rotation.

How would the the app know when the turrets are linked(to root bone or a turret base bone) like so because some turrets would be linked to otheres and some not.

The only way I can think of is in the asset manager for each vehicles turret set a flag to true if it inheritance from another turret

but that would only work for the two turrets if shooting at the same target.

Is the a mathematical way to do this.

##### Share on other sites
ankhd    2304

Ok. I think its working 100% now, said that a couple of times now lol.

I went with the flag idea now when you create a vehicle type in the assetmanager you set a flag when you load the mesh.

if that turret has a turret on top. This allows the vehicle to have turrets any where on the vehicle and turrets on top of them anywhere aswell.

that was a lot of work for such a small affect. It was fun but THANKS ALL.

then in the first post's code, I use this flag like so

//if this turret inheritance is true then we dont add the spin

//only if where shooting meaning we have a target

if(targetobj)

{

//if we have no Inheritance then add the spin. turret is randomly spinning(Idel turret)

if(TurretInheritance[ctr] == false)

temp *= mSpin;

}

else//if we are not attacking then where Idel so add the spin

temp *= mSpin;

temp *= FrameTurretBase[ctr]->TransformationMatrix;

FrameTurretBase[ctr]->TransformationMatrix = temp;