Jump to content
  • Advertisement
Sign in to follow this  
EternityZA

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.

If you intended to correct an error in the post then please contact us.

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

 

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!

Edited by Wilhelm van Huyssteen

Share this post


Link to post
Share on other sites
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.

Edited by Brother Bob

Share this post


Link to post
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 this post


Link to post
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 this post


Link to post
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

Share this post


Link to post
Share on other sites
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!