# Strange Camera Problem (objects disappearing close to camera)

## Recommended Posts

richiwatson    122
I have been working with managed directx the last few evenings and have encountered an interesting problem, if i create my vertex buffer like this
vb = new VertexBuffer(device, 3 * PositionColored.StrideSize, Usage.WriteOnly, PositionColored.Format, Pool.Default, null);
GraphicsBuffer<PositionColored> buffer = vb.Lock<PositionColored>(0, 0, LockFlags.None);
buffer.Write(new PositionColored(-1.0f, -1.0f, 5.0f, Color.Red));
buffer.Write(new PositionColored(-1.0f, 1.0f, 5.0f, Color.Yellow));
buffer.Write(new PositionColored(1.0f, -1.0f, 5.0f, Color.Green));
vb.Unlock();


and then try and zoom in on my triangle it disappears when my camera gets close to it, if i create the triangle at 0.0f on the z axis i can zoom up to it properly, not too sure whats going on

##### Share on other sites
blaze02    100
Long Answer: When you render objects, Direct3D will clip things that are not in your view frustrum. Anything left of the screen gets chopped off, anything right of the screen, etc. Anything that is further away than the far clip plane or closer than the near clip plane will also be chopped off. When you set up the projection matrix, you specify what the near and far clip planes are. Careful with what you set these, because your ZBuffer only has so much resolution. Typically, objects disappearing when they are too close is fine because you don't want the camera to get blocked. Although, you don't want the player to see through the wall :( Its up to you how to fix this.

Short Answer: Check your projection matrix. The objects are probably closer than the near clip plane.

Edit: Oh yeah.. you also have to worry about Gimbal lock - when your up vector and lookat vector are parallel. When you compute the projection matrix, these vectors get crossed. If they are parallel, the projection matrix gets bad values and stuff doesn't render properly. The typical way to fix this is to limit the lookat vector so that it can't be parallel to the up vector. You could also look into quaternions. Or you could rotate the player's up vector with the forward vector (like in a space game, there is not standard up direction).

Hope that helps.

##### Share on other sites
Halaster    122
Im not to sure about MDX but you want to try disabling backface culling to see if your triangle is being culled.

##### Share on other sites
richiwatson    122
Here is how I am setting up my projection matrix

device.Transform.Projection = Matrix.PerspectiveFieldOfViewLeftHanded((float)Math.PI / 4.0f, aspect, 0.1f, 200.0f);

but say for example the object is at 5.0f, it disappears when my cameras position is at 1.0f surely with a 0.1f clipplane it should do this at 4.9f?

I also tried to disable culling but that had no effect