Jump to content
  • Advertisement
Sign in to follow this  

Object targeting

This topic is 3626 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi.. Ive been strugling with this all day, so any feedback would be much appriciated. Im trying to have a turret in my 3d scene target the camera in this example. This is my current code wich works fine until I add some X and Z rotation to the source object, then it seems like the target vector dont get transformed into the source orientation.
D3DXVECTOR3 A = D3DXVECTOR3( 0.0f, 0.0f, 0.0f );  // camera is always at 0,0,0
D3DXVec3TransformCoord( &A, &A, &ship_entity.matrix ); // transformation matrix

D3DXVECTOR3 B = D3DXVECTOR3( 0.0f, 0.0f, -1.0f );          // Source object
D3DXVec3TransformCoord( &B, &B, &ship_entity.matrixRot );  // Rotation matrix


float Dot = D3DXVec3Dot(&A,&B);

float angle = acosf(Dot);

D3DXVECTOR3 cross;

if( cross.y > 0.0f )


Share this post

Link to post
Share on other sites
Sign in to follow this  

  • Advertisement

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!