Jump to content
  • Advertisement


This topic is now archived and is closed to further replies.


Anyone know about 2d coord->3d coord or Ray.?

This topic is 6936 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 I am feeling very pain to find a ray with 2d screen coord(x,y). Actually I want to implement picking object routine which is in D3DRM by myself in D3D IM. But my intention is stopped at first stage which is finding Ray(line from screen toward 3d-z direction) with screen x,y. Here is a my code. But it's not working correctly. when I call this function and draw Ray into 3d space, the apperance is quite different from my expectation. It's absolutely something wrong. Is there anyone to fix this code ?. //=============== Code for Ray picking ==================== void RayPick(LPDIRECT3DDEVICE7 pDev, float fovy, // fovy in projection float fNearZ, // distance to Near Clip plane float fFarZ, // distance to Far Clip plane int x, // 2D Screen Coord X int y, // 2D Screen Coord Y D3DVECTOR &p1, // Output:Start vector of Ray. D3DVECTOR &p2) // Output:End vector of Ray. { float fAspect, w, h; RECT rect; GetClientRect(m_hwndMain, &rect); w = (float)(rect.right-rect.left); h = (float)(rect.bottom-rect.top); fAspect = w/h; float dx,dy, t; D3DMATRIX invMatrix,viewMatrix; t = tanf( fFov * 0.5f ) dx = t * ( (float)x / (w * 0.5f) - 1.0f) / fAspect; dy = t * ( 1.0f- (float)y / (h * 0.5f) ); pDDev->GetTransform(D3DTRANSFORMSTATE_VIEW, &viewMatrix); D3DUtil_MatrixInvert(invMatrix,viewMatrix); p1 = D3DVECTOR( dx*fNearZ, dy*fNearZ, fNearZ ); p2 = D3DVECTOR( dx*fFarZ, dy*fFarZ, fFarZ ); // here, final results(p1,p2) is being returned.. D3DUtil_VectorMatrixMultiply( p1, p1, invMatrix); D3DUtil_VectorMatrixMultiply( p2, p2, invMatrix); } Edited by - willy9532 on 4/28/00 3:19:55 PM

Share this post

Link to post
Share on other sites
That message("Direct3D Screen Coordinates / Projection") is about converting 3d coord to 2d cood (3d->2d).

But what I want to know is 2D->3D.

That is 2d point to 3D line... actually..

Can anyone help me?


Share this post

Link to post
Share on other sites

  • 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!