Help me to understand Clipping & Z-Buffer

Started by
12 comments, last by MJP 15 years, 9 months ago
This is really really simple:

D3DXVECTOR3 vPlanetPosViewSpace;D3DXVec3TransformCoord(&vPlanetPosViewSpace, &vPlanetPos, &mView);D3DXMatrixPerspectiveFovLH(... ,vPlanetPosViewSpace.z - radius, vPlanetPosViewSpace.z + radius);
Advertisement
Quote:Original post by MJP
This is really really simple:

D3DXVECTOR3 vPlanetPosViewSpace;D3DXVec3TransformCoord(&vPlanetPosViewSpace, &vPlanetPos, &mView);D3DXMatrixPerspectiveFovLH(... ,vPlanetPosViewSpace.z - radius, vPlanetPosViewSpace.z + radius);


God bless the united states! :)
It works!

Thank you!
Quote:Original post by Buckeye

EDIT: that will only be appox., now that I think about it. It doesn't take into account the vertical angle above/below centerline.

Is your camera upvector always (0,1,0)?


No, you're in space and you can rotate on all three axis.

Anyway the solution of mjp seems to works.
I've to do a little adjustment with constant value (pheraps some precision problem with big number), but now it works.

Thank you anyway!
Just a little explanation of what I did there...

The zNear and zFar parameters you pass to D3DXMatrixPerspectiveFovLH specify distance to two planes, which are perpendicular to the camera. Like this:



Since these planes are perpendicular, every point on one of these planes has the same z-coordinate with respect to the camera (the coordinate space relative to the camera is view-space). However while they have the same view-space z value, they don't have the same distance (as you've already noticed). So when we're trying to find good values for those two planes, we're looking for view-space z values rather than distance. Fortunately, it's very easy to calculate hits (as you saw in the code I posted).

This topic is closed to new replies.

Advertisement