Jump to content
  • Advertisement
Sign in to follow this  

3D projection algorithms using the near/far planes?

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

Hey everyone-- I have a question about 3D projection equations. I've come across the usual ones, these: ScreenX = 256 * ((PntX - CameraX) / ((PntZ - CameraZ) + zCenter)) + (xRes / 2) ScreenY = 256 * ((PntY - CameraY) / ((PntZ - CameraZ) + zCenter)) + (yRes / 2) ...But I'm using a ststem that uses a camera defining the frustum with a near and far plane, and I'm not sure how to implement the values DistanceToNearPlane and DistanceToFarPlane in these equations. Does anyone know how? --j_k

Share this post

Link to post
Share on other sites
Hi ranak,

The way this is done is by mapping the view frustum to a cube.

You would normally construct the mapping such that the cube is centered on the origin, and the corners extend from -1 to +1 on each axis. Let's say this mapping is represented by matrix M (I can't remember what it is, I'm afraid - might have to look that one up).

You transform a point v = (x,y,z,w) from world space into homogeneous clip space (that's the name given to the cube) like this:

v' = M(v)

And now, you can very easily tell whether v was visible or not. The point v was visible if it was in the frustum, and hence it was visible if it is inside the cube.

For v to be visible, the following must hold:

-1 <= v'.x <= 1 && -1 <= v'.y <= 1 && -1 <= v'.z <= 1

As you can see, the only complicated bit is coming up with the matrix M.

Also, you might realise that you need to know all the boundaries on the frustum, not just the near and far clipping planes.

However, if you want to just work out how to map a z coordinate z to the range [-1,1], then you can do this:

z' = (2 * n * f) / ((f - n) * z) + ((f + n) / (f - n))

(somebody better double-check that for me!)

here, z is the z-coordinate of the point you're interested in, n is the distance to the near clipping plane, and f is the distance to the far clipping plane.

Then, z was visible if -1 <= z' <= 1.

Hope that helps.

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!