• Create Account

### #ActualWilhelm van Huyssteen

Posted 27 March 2013 - 02:49 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

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


### #1Wilhelm van Huyssteen

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

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;
//f = 1.0;
//b = -768.0 / 1024.0;    //-height / width
//t = 768.0 / 1024.0;      //height / width
//n = 1.0;                       //near clipping pane
//t = 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);
}