Jump to content
  • Advertisement
Sign in to follow this  
cabbar

dragging - getting depth info

This topic is 4075 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 posted this on beginner forums but got no answer, looks like its more challenging then i thought of :) I'm trying to get the depth information of an object i picked .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 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 jacobian 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. 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
Quote:
Original post by cabbar
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
That URL doesn't work unless you're signed in - it hides all of the content (stupid expert sex change website [rolleyes]).

I assume you meant D3DXVec3Project() (3D object-space coordinate to screenspace + depth) and D3DXVec3Unproject(). I've used D3DXVec3Project() to implement a rather inefficient frustum culling algorithm in the past and I know it returns the correct Z depth...

hth
Jack

Share this post


Link to post
Share on other sites
Thanks that was what i meant. I can finally start ik calculations. You really don't like ee do you :)

Share this post


Link to post
Share on other sites
Quote:
Original post by cabbar
You really don't like ee do you :)
Well the alternative take on their URL popped up in a joke email I got at work a while back and I can't look at the site without it being the first thing I think of [lol]

In general I've nothing against the place, but the sharing and freedom of knowledge is important to me and things that hide it (even if its just a free 30 second registration) sometimes irritate me!


Happy coding!

Jack

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!