# OpenGL Projection Matrix Issue

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

## Recommended Posts

Hi.

I dont understand the math behind generating the projection matrix so please bear with me (infact im not even 100% sure if the projection matrix is the culprit).

Here is an screenshot demonstrating my issue

Note the piece of wall on the right of the building thats being clipped.

My issue is that geometry is being clipped too soon. The camera is inside the room and thus the wall should be fully visible.

This is how I calculate the projection matrix. I copied the math from the opengl implementation documentation. I tried to tweak the parameters but had no success.

[source]

//in the screenshot the values are as follow

//l = -1.0;

//r = 1.0;

//b = -768.0 / 1024.0;    //-height / width

//t = 768.0 / 1024.0;      //height / width

//n = 1.0;                       //near clipping pane

//f = 10000.0;                //far clipping pane

public static Matrix4 glFrustum(float l, float r, float b, float t, float n,float f)
{
FloatBuffer fb = FloatBuffer.allocate(16);

fb.put((2*n)/(r-l));
fb.put(0);
fb.put(0);
fb.put(0);
fb.put(0);
fb.put((2*n)/(t-b));
fb.put(0);
fb.put(0);
fb.put((r+l)/(r-l));
fb.put((t+b)/(t-b));
fb.put(-(f+n)/(f-n));
fb.put(-1);
fb.put(0);
fb.put(0);
fb.put((-2*f*n)/(f-n));
fb.put(0);

return new Matrix4(fb);
}

[/source]

Edited by Wilhelm van Huyssteen

##### Share on other sites

It's probably the near clip plane clipping the wall. Pull the clip plane closer, but keep in mind that you need to scale the l, r, b and t parameters accordingly if you scale the near clip plane.

Edited by Brother Bob

##### Share on other sites

Hi.

So I scaled everything 10 times smaller and it gives the desired effect. But now everything in the scene that moves became "jumpy" or "jittery". would seem to be due to some numbers becoming too small and losing precision in the process (I think). How should I go about improving this?

Thanx!

Edited by Wilhelm van Huyssteen

##### Share on other sites
alternatively, you could ensure the camera can't get so close to the wall. if you treat your camera as a collidable sphere, and give it a small radius, your physics engine should take care of keeping your camera from getting too close to walls to see through them.

lastly, your ratio between far/near plane is pretty large, i'd recommend reducing it a bit. Edited by slicer4ever

##### Share on other sites

I would have done so except that the camera needs to zoom close to the character as well which causes the same problem (character gets clipped). And I kind of want the camera to be able to get at least that close to the wall (as in the screenshot). I have tried moving the far clipping pane closer but that doesn't help.

If i went and scaled everything in the world 10 times larger it should solve the problem. but at this point that will be alot of work and only a last option. (atm 1 unit = 1 meter on client and on server).

Edited by Wilhelm van Huyssteen

1. 1
2. 2
Rutin
20
3. 3
khawk
18
4. 4
A4L
14
5. 5

• 12
• 16
• 26
• 10
• 44
• ### Forum Statistics

• Total Topics
633761
• Total Posts
3013724
×