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

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

1. 1
2. 2
Rutin
25
3. 3
4. 4
5. 5

• 11
• 10
• 13
• 20
• 14
• ### Forum Statistics

• Total Topics
632950
• Total Posts
3009378
• ### Who's Online (See full list)

There are no registered users currently online

×