Jump to content
• Advertisement

# canculate distance from camera to view plane ?

This topic is 4833 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

My intention is to map a 2D(screen)coordinate(x,y) to 3D cooridnate(x,y,z)to draw in 3D screen by using Perspective projection. my solution is to calculate these values base on the Distance from camera to view plane(D) as i read from a 3D book : x(3D) = (1 - z(3D)/D)*x(2D) y(3D) = (1 - z(3D)/D) *y(2D) my question is if i had to calcute D value or Direct3D have already support function to get this value? are there any better solution in this case?

#### Share this post

##### Share on other sites
Advertisement
Well, that's the problem, isn't it? you know the X and Y coordinates, but you don't know the Z coordinates. You could be indicating any one of an infinite number of points, which radiate out in a straight line from the eyepoint.

To do picking, you need more information about the particular point you're interested in. Sometimes, everything you care about will be in the same plane. Sometimes, all you'll know is that the point you want is on a given mesh... or on one of a number of meshes. In this latter case, you can read back from the Z-buffer, but it's generally not recommended, due to low precison and the efficiency hit from doing a readback. More commonly, you'll do an intersection test to figure out whether that line of possible points intersects a given object, and if so, where on that object.

#### Share this post

##### Share on other sites
no, my problem is not the z value, i can manual add and tweak this value.
what i mean is the D distance, how to calculate it or if Direct3D have already support function to get this value?

#### Share this post

##### Share on other sites
What exactly do you mean by view plane? Your near or far plane? If that is what you mean, I don´t see a problem, because you´ve used those distance values to generate your projection matrix.

If you want the exact z-position of a given point S on any plane p (given by something like a*x + b*y + c*z + d = 0), you´ll need to create a ray representing the possible 3D coordinates behind S. When you have that ray you do a ray-plane-intersection to calculate the 3D coordinates of a point that lies behind your original point S on the plane p.
I guess informations on how to generate the ray would be found most easily in any tutorial / article about "picking", so try to google for that. Ray-plane-intersection should also be found with google.

If you want the distance of your camera C from the plane p (as above) you should simply insert the (x,y,z) coordinates of C into p´s equation, the result is the distance of C to p, like that: a* x(C) + b* y(C) + c* z(C) + d.

#### Share this post

##### Share on other sites

• Advertisement
• Advertisement

• ### Popular Contributors

1. 1
Rutin
40
2. 2
3. 3
4. 4
5. 5
• Advertisement

• 18
• 20
• 14
• 14
• 9
• ### Forum Statistics

• Total Topics
633368
• Total Posts
3011531
• ### Who's Online (See full list)

There are no registered users currently online

×

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