Jump to content
  • Advertisement
Sign in to follow this  
KMD

world to screen dimensions

This topic is 3631 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 all, I'm having a little bit of trouble working out how to find the relationship between world co-ordinates and screen dimensions. Basically what I'm trying to do is make a sprite demo where an alien ship flies across one edge of the screen and ends up at the opposite edge. (For example, the ship flies across the top edge of the screen, and ends up at the bottom of the screen) The way I was going about doing this is trying to convert world coordinates into screen dimensions, testing whether y < 0 and then converting the bottom coordinate (say 600) back into world coordinates with the same z value, and giving the ship the new position at the bottom of the screen (the demo is in 3d but looking overhead like 2d.) I'm wondering if there's any easy way of doing this? 1. Does GetClientRect(hMainWnd, &rect) produce the screen dimensions? 2. Are there D3D matrices that can convert between world coordinates and screen coordinates and vice versa? 3. Is there a better way of doing this? edit: I was looking through the directx documentation and found D3DXVec3Project. Maybe this is what I need? Thanks for any input! Much appreciated!

Share this post


Link to post
Share on other sites
Advertisement
Your current approach won't really work in any robust way so yes, you want to be using D3DXVec3Project() - it's pretty much designed for this [cool]

Alternatively, you could look into using projection space for your geometry - you get all the benefits of the pipeline (that is, you don't disable transformations like you would for pre-transformed data) and it's resolution-independent 2D. Simply set your matrices to identity and define your geometry in the [-1,+1] coordinate range.

hth
Jack

Share this post


Link to post
Share on other sites
I'm trying to use D3DXVec3Project now with the following code:

D3DXMATRIX proj, view, world;
D3DVIEWPORT9 vp;
D3DXVECTOR3 result;

gd3dDevice->GetViewport(&vp);
gd3dDevice->GetTransform(D3DTS_PROJECTION, &proj);
gd3dDevice->GetTransform(D3DTS_VIEW, &view);
gd3dDevice->GetTransform(D3DTS_WORLD, &world);

D3DXVec3Project(&result, &mShipPos, &vp, &proj, &view, &world);

mShipPos is a D3DXVECTOR3 holding the ship's x, y and z world coordinates. I get strange results:

result.x = 796, result.y = 1.69873e-005 and result.z = 1

x never seems to change from 796 regardless of the ships position, and y sometimes turns into 0.

Am I using this function correctly? I've read that it wont work with a pure device, and if that is the problem, is there any way around it? Why wouldn't it work with a pure device?

Share this post


Link to post
Share on other sites
Quote:
Original post by KMD
Am I using this function correctly? I've read that it wont work with a pure device, and if that is the problem, is there any way around it? Why wouldn't it work with a pure device?
Because GetTransform() will fail on a pure device, so your matrices will be garbage.

Make sure you're using the Debug Runtimes to help catch errors like this.

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.

Participate in the game development conversation and more when you create an account on GameDev.net!

Sign me up!