# View/Projection matrix in ortho woes!

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

## Recommended Posts

I have spend days literally on this, I have now come to a conclusion, but the logic seems strange, therefore could some one in the know please confirm if my understanding is correct, thank you very much. My problem area is that the near and far clipping planes, are changing in a major way depending on the position of the camera. Some code to demonstrate:
Me.Device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, 0), New Vector3(0, 0, 1), New Vector3(0, 1, 0))

Me.Device.Transform.Projection = Matrix.OrthoLH(Me.Width, Me.Height), -50, 50)

'Clipping occurs
Dim mesh As Mesh = Mesh.Cylinder(Me.Device, 20, 10, 101, 20, 1)

'Clipping does not occur
Dim mesh As Mesh = Mesh.Cylinder(Me.Device, 20, 10, 99, 20, 1)

Being ortho rather than perspective projection, we are dealing with a view cube as opposed to a viewing frustum. Leaving the view matrix for a moment, all seems straight forward, we have a cube 100 units deep, so to test I draw a cylinder 99 in the Z and no clipping occurs, if I use a cylinder 101 in the Z clipping occurs, so far so good! But the code below produces exactly the same results:
Me.Device.Transform.View = Matrix.LookAtLH(New Vector3(0, 0, -25), New Vector3(0, 0, 1), New Vector3(0, 1, 0))

Me.Device.Transform.Projection = Matrix.OrthoLH(Me.Width, Me.Height), -25, 75)

I have positioned the camera at -25 this time and what seems to be happening is that the near and far clipping plane is relative to the cameraPosition. The cameraTarget value makes no difference as long as it indicates the direction. There you go, I can’t see any documentation to back this up, but I would be grateful if someone could confirm either way if am on the right track!! Julian

##### Share on other sites
This is what is expected, aside from negative near plane values not being useful.

The near and far plane refer to the view space Z values (ie: after the world and view transforms). They represent how near and far something can be to the camera to be rendered. If these value were in world space, you'd have trouble quickly. Imagine turning your camera 90 degrees, looking down + or - X. How far would we see if near/far were referring to world space Z? No distance clipping would occur, instead it would become left/right clipping. Right there we can see that the values are not world space.

Since the near and far are based on Z distance from camera, a near value of less than 0 isn't useful. Anything less than 0 is behind the camera. A value of 0 is on the camera. A value greater than 0 is in front of the camera.

Due to how the math works, you actually want the near plane set to as high a value as you can. A value of 0 will break depth buffering. Very small values will introduce precision problems. The far plane can be large without affecting precision much.

This is the same for perspective cameras too, not just ortho cameras.

##### Share on other sites
Thank you very much, your explanation was very clear

Cheers

1. 1
Rutin
24
2. 2
3. 3
JoeJ
18
4. 4
5. 5

• 38
• 23
• 13
• 13
• 17
• ### Forum Statistics

• Total Topics
631710
• Total Posts
3001846
×