Jump to content
  • Advertisement
Sign in to follow this  

Rotate DXSprite to cursor, frame of reference.

This topic is 3677 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 have a little demo running, and I’m trying to make a little top down shooter where the player sprite rotates to face the cursor (i.e. where to fire). I have the rotation calculations ok, but my problem is that how I’m positioning the DXSprite is not in the same frame of reference to the mouse position. Here's how I’m getting the cursor position;
void CInputHandler::UpdateMouseInfo(HWND hWnd, int screenWidth, int screenHeight)
	//Get the current position
	ScreenToClient( hWnd, &m_mousePos );

	POINT center;
	center.x = screenWidth/2;
	center.y = screenHeight/2;

	m_mousePosFromCenter.x = m_mousePos.x - screenWidth/2;
	m_mousePosFromCenter.y = m_mousePos.y - screenHeight/2;

To position the sprite I’m using the D3DXSprite function SetTransform, and it works when both the sprite and the cursor are near the centre of the screen. But as we get further away the become out of sync and the sprite starts rotating around a point that’s not the cursor. I know it’s because an x value of 300 for the mouse is a different position to 300 x pos for the sprite. But I’m confused as to how i can alter the values. Is it because I’m using the D3DXSPRITE_OBJECTSPACE flag when drawing the sprite? I think i should probably be using pixels for the position, but I’m not sure how to do that. Any help would be much appreciated. [Edited by - JimmyDeemo on November 24, 2008 5:54:20 AM]

Share this post

Link to post
Share on other sites
Suddenly thought that this might be better off in the DirectX section. If a mod comes across this and thinks so also. Please move it. Thanks.

Edit: I think what I’m looking for is the mouse position in object space. Or to draw the sprite using screen coordinates. I have tried it without the D3DXSPRITE_OBJECTSPACE flag and it doesn’t render anything. I think that’s because oh how my camera is set up. Perhaps my problem is that i modified this from a 3D demo i had and its a bit silly doing something in 2d using a 3d methods i guess.

[Edited by - JimmyDeemo on November 25, 2008 3:21:17 AM]

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!