Sign in to follow this  
Rob_The_Wise

Word co-ords to screen co-ords

Recommended Posts

Rob_The_Wise    100
Hi guys

I'm, coding a 3D top down shooter and I want the player to fire in a direction relative to where the mouse and avatar are in screen space.

I thought once I have the two positions I can calculate an angle between them and have the player shoot in that direction.

But I don't know how to convert the world position of the avatar to it's position on screen.

Any insight would be greatly appreciated.

Cheers!
Rob

Share this post


Link to post
Share on other sites
Erik Rufelt    5901
For D3DX there's [url="http://msdn.microsoft.com/en-us/library/bb205516(VS.85).aspx"]D3DXVec3Project[/url] and [url="http://msdn.microsoft.com/en-us/library/bb205526(VS.85).aspx"]D3DXVec3Unproject[/url], to go from world coords to screencords and screencoords to world coords.
For XNAMath the functions are called [url="http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.transformation.xmvector3project%28VS.85%29.aspx"]XMVector3Project[/url] and [url="http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.transformation.xmvector3unproject%28VS.85%29.aspx"]XMVector3Unproject[/url], and for C# XNA there's [url="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.project.aspx"]Viewport.Project[/url] and [url="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.unproject.aspx"]Viewport.Unproject[/url].

Share this post


Link to post
Share on other sites
Rob_The_Wise    100
[quote name='Erik Rufelt' timestamp='1302455169' post='4796731']
For D3DX there's [url="http://msdn.microsoft.com/en-us/library/bb205516(VS.85).aspx"]D3DXVec3Project[/url] and [url="http://msdn.microsoft.com/en-us/library/bb205526(VS.85).aspx"]D3DXVec3Unproject[/url], to go from world coords to screencords and screencoords to world coords.
For XNAMath the functions are called [url="http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.transformation.xmvector3project%28VS.85%29.aspx"]XMVector3Project[/url] and [url="http://msdn.microsoft.com/en-us/library/microsoft.directx_sdk.transformation.xmvector3unproject%28VS.85%29.aspx"]XMVector3Unproject[/url], and for C# XNA there's [url="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.project.aspx"]Viewport.Project[/url] and [url="http://msdn.microsoft.com/en-us/library/microsoft.xna.framework.graphics.viewport.unproject.aspx"]Viewport.Unproject[/url].
[/quote]

PERFECT!

Thank you very much :-)

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this