Jump to content
  • Advertisement
Sign in to follow this  
cabbar

[directx]getting depth info

This topic is 4079 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 get the depth information of a target i picked (will use it later for dragging) But i always get the same result (1) Here's my code
// startpos in world space
D3DXVECTOR3 pos = D3DXVECTOR3(0.0f,0.0f,0.0f);			
D3DXMATRIX worldTrans = selectedJoint->GetWorldMatrix();
D3DXVec3TransformCoord(&pos,&pos,&worldTrans);

// startpos in view space
D3DXMATRIX view;
SFGetDevice()->GetTransform(D3DTS_VIEW, &view);
D3DXVec3TransformCoord(&pos,&pos,&view);

// startpos in projection space
D3DXMATRIX projection;
SFGetDevice()->GetTransform(D3DTS_PROJECTION, &projection);
D3DXVec3TransformCoord(&pos,&pos,&projection);

/////////target pos////////////
D3DXVECTOR3 target;
D3DVIEWPORT9 vp;
SFGetDevice()->GetViewport(&vp);

// target in projection space (xpos, ypos = mouse position)
target.x = ((( 2.0f*xPos) / vp.Width)  - 1.0f) / projection(0, 0);
target.y = (((-2.0f*yPos) / vp.Height) + 1.0f) / projection(1, 1);
target.z = pos.z;
...
Here's the piece of code i'm trying to implement -Mark3DCursorPosition method- (unfortunately couldnt find project/unproject equivalent for unmanaged directx) http://www.experts-exchange.com/Programming/Game/Q_21257512.html Thanks for your help

Share this post


Link to post
Share on other sites
Advertisement
Hmm I think this isn't as beginner level as i thought it might be :) Here's what i am trying to do: On WM_LeftButtonDown event, pick the an object and record it as selectedJoint. Picking process works just fine. On WM_LeftButtonUp, find the position of the mouse in 3d space (using the z value of selected object). And then I will use mouseposin3dspace - objectpos as force for inverse kinematics calculations. However:

D3DXMATRIX projection;
SFGetDevice()->GetTransform(D3DTS_PROJECTION, &projection);
D3DXVec3TransformCoord(&pos,&pos,&projection);

pos.z is always 1 after here. (I thought objects preserved their z-value after projection transformation?) I couldn't find out what i am doing wrong.

If you have any suggestions other than finding z value for finding the position of the mouse in 3d space, it might help as well.

Thanks for your help

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.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!