Crenna

Hello,

I'm curious about the behaviour of my camera class. It is a simple class that controls camera view. It behaves like it should, except when the radius happens to be the maximum value that I've set in code (farPlaneDistance). When the mouse wheel is moved, this changes the near and far plane distance:

// don't get too far
if (radius < nearPlaneDistance)
{
     radius = nearPlaneDistance;
}

// don't get too close
if (radius > farPlaneDistance)
{
     radius = farPlaneDistance;
}

And I use the radius to update the position vector of the camera:

// update position vector
position.X = (float)(radius * Math.Cos(vertical) * Math.Cos(horizontal));
position.Y = (
float)(radius * Math.Sin(vertical));
position.Z = (
float)(radius * Math.Cos(vertical) * Math.Sin(horizontal));

And, last but not least, the public property for the camera projection matrix is:

public
Matrix Projection
{
    
get
     {
         
return Matrix.CreatePerspectiveFieldOfView(fieldOfView, AspectRatio, nearPlaneDistance, farPlaneDistance);
     }
}

The field of view is PiOver4, and doesn't change.

My model objects are using stock code with basic effects. What I find odd is that if I reduce the radius to below what I've set as my far plane distance, then objects render fine. It doesn't seem to matter about model scale compared to hard values, etc., if I change values then the weird rendering just follows when radius == farPlaneDistance, it seems to be value agnostic.

Any suggestions as to where I'm going wrong, or if I should be looking at other code




Re: XNA Game Studio Express Issue with far plane distance vs. radius in a camera component

Shawn Hargreaves - MSFT

Could you describe the "weird rendering" you get in a bit more detail Maybe post a screenshot that shows your problem





Re: XNA Game Studio Express Issue with far plane distance vs. radius in a camera component

Crenna

Hi Shawn,

Here is a link to a video of my debug window. In it I show rotating the model when the value of farPlaneDistance is at maximum, and then I zoom out to show regular movement. I imagine that it has to do with culling and my far plane. I thought it was just the model size extending out of view but the issue scales with the model so it must be something else I'm doing wrong. Do I need to implement my own frustum culling

Daniel






Re: XNA Game Studio Express Issue with far plane distance vs. radius in a camera component

Leaf.

just from watching the ideo, that looks like near plane clipping. How do you calculate the nearPlaneDistance variable

Cheers,
Leaf.






Re: XNA Game Studio Express Issue with far plane distance vs. radius in a camera component

Crenna

Hi Leaf,

My near and far plane distances are just constraints on radius, so they aren't calculated, they're set at design time. I should not have said that the far plane distance changes, these values don't change, only the value of radius changes. I have tried adjusting these values but they scale with the camera, so if I use a different set of values, I get the same clipping at maximum radius, and I don't get the clipping at a lower radius.

Daniel





Re: XNA Game Studio Express Issue with far plane distance vs. radius in a camera component

Crenna

I wasn't paying attention to the values, I had them reversed in my head; I just changed the nearPlaneDistance to something closer to zero. It was definitely clipping.

So now I'm confused: am I near-sighted or far-sighted :)

Daniel