Projection Matrix Issue

Started by
3 comments, last by Wilhelm van Huyssteen 11 years ago

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

camera_issue.jpg

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]

Thanx in Advance!

Advertisement

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.

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!

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.
Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

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).

This topic is closed to new replies.

Advertisement