Advertisement Jump to content
Sign in to follow this  

[DirectX] Rotating a sprite relative to a fixed position

This topic is 2590 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

I'm trying to rotate a textured quad like in the image below:


This is the code i'm using to rotate the arrow:

//copies the current square position to a new vector
moveTo = cursor;

//these 2 floats store the magnitude of each vector
part1 = D3DXVec3Length(&unit.pos);
part2 = D3DXVec3Length(&moveTo);

//tried to use both these formulae to calculate the angle
//angle = acos((D3DXVec3Dot(&unit.pos,&moveTo)/(part1 * part2)));
angle = atan2(moveTo.y,moveTo.x)- atan2(unit.pos.y,unit.pos.x);

D3DXMATRIX center, rotate, reposition;
//move to 0,0 -> Rotate -> reposition
world = center *rotate * reposition;

//just draws the primitive with the selected Texture


The problem is that the arrow rotates, ofc, relative to the origin instead of the position of the tank, so that if the arrow would be perpendicular to the tank, it is not. I'm probably missing something in my calculation, but i cannot figure out what's missin so that i can modify the behaviour of the rotation relative to the Tank.

The tanks are Dynamically created during the game.

Thanks in advance

Share this post

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

  • Advertisement

Important Information

By using, you agree to our community Guidelines, Terms of Use, and Privacy Policy. 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!