# Computing the depth value of a point

This topic is 3336 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hi ! I've got a little question : I have a 3 dimensional point (in the world space) and I'd like to compute its depth (between 0 and 1 if I'm not mistaken) And I also would like to have a confirmation : when using D3DXVec3UnProject, the 2 first values (x and y) of the input vector are the x and y coordinate in screenspace, and the z value is the desired depth ? To be a little more precise, what I want to do is : I have a "screen space" 2D point, and a "world space" 3D point. Imagine a plane containing the 3D point and parallel to the camera. I want to project the 2D point onto that plane and get the coordinates :) So I thought : get the depth of the 3D point, create a vector with the 2D point and the previously computed depth, and unproject. But it doesn't seem to work ... Any idea ? PS: If you don't understand what I asked, don't hesitate to say it, english is not my mother language, so I know I might be confusing sometimes :)

##### Share on other sites
transform the world vector by camera view matrix and then by projection matrix. The z value of transformed vector will be the vectors depth in screen space normalized between 0-1 allready.

##### Share on other sites
Quote:
 Original post by JohnnyCodetransform the world vector by camera view matrix and then by projection matrix. The z value of transformed vector will be the vectors depth in screen space normalized between 0-1 allready.

try using this
D3DXVECTOR3 * D3DXVec3Project(
D3DXVECTOR3 *pOut,
CONST D3DXVECTOR3 *pV,
CONST D3D10_VIEWPORT *pViewport,
CONST D3DXMATRIX *pProjection,
CONST D3DXMATRIX *pView,
CONST D3DXMATRIX *pWorld
);

[Edited by - e3d_ALiVE on October 24, 2009 3:27:46 AM]

1. 1
2. 2
3. 3
Rutin
15
4. 4
5. 5

• 9
• 9
• 11
• 11
• 23
• ### Forum Statistics

• Total Topics
633678
• Total Posts
3013290
×