Jump to content

  • Log In with Google      Sign In   
  • Create Account

We need your feedback on a survey! Each completed response supports our community and gives you a chance to win a $25 Amazon gift card!


Projection Matrix Issue


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
4 replies to this topic

#1 Wilhelm van Huyssteen   Members   -  Reputation: 1012

Like
0Likes
Like

Posted 27 March 2013 - 02:47 PM

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.

 

 
//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);
}

 

Thanx in Advance!


Edited by Wilhelm van Huyssteen, 27 March 2013 - 02:49 PM.


Sponsor:

#2 Brother Bob   Moderators   -  Reputation: 8633

Like
0Likes
Like

Posted 27 March 2013 - 06:53 PM

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, 27 March 2013 - 06:53 PM.


#3 Wilhelm van Huyssteen   Members   -  Reputation: 1012

Like
0Likes
Like

Posted 28 March 2013 - 12:40 PM

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, 28 March 2013 - 12:44 PM.


#4 slicer4ever   Crossbones+   -  Reputation: 3991

Like
0Likes
Like

Posted 29 March 2013 - 04:41 AM

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, 29 March 2013 - 04:41 AM.

Check out https://www.facebook.com/LiquidGames for some great games made by me on the Playstation Mobile market.

#5 Wilhelm van Huyssteen   Members   -  Reputation: 1012

Like
0Likes
Like

Posted 29 March 2013 - 10:07 AM

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, 29 March 2013 - 11:01 AM.





Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS