View Culling Problem LWGL

Now it is blatantly obvious that I messed up somewhere and pretty badly because I managed to turn perfect piece of code into huge pile of crap.

When I’m at the position 0,0,1 facing towards up vector 0,1,0 it works ok, except that it can’t render some of the balls that go beside it.

Now the biggest problem is that it doesn’t work as it is supposed to and I can’t figure out what the hell is wrong with the planes.

I’ve re-written them about 1000 000^7 times, but they still keep messing up. This is grabbed directly from gametutorials com. At first I thought they worked, but I had the camera positioned wrong and no mouse move. But when the mousemove is included it craps up. Hence there must be something wrong with the panes.

Now I beg you, please can you check the pane code that it is at least seemingly right?

I’m thinking about turning the frustum into one single array instead of logical array, but that is not supposed to be the matter since it works like that in gametuts examples, unless there is some major difference between c++ and java arrays that I’m unaware of.


Matrix4f.mul(modl, proj, clip);             
            // This will extract the RIGHT side of the frustum
            m_Frustum[RIGHT][A] = clip.m30 - clip.m00;
            m_Frustum[RIGHT][B] = clip.m31 - clip.m01;
            m_Frustum[RIGHT][C] = clip.m32 - clip.m02;
            m_Frustum[RIGHT][D] = clip.m33 - clip.m03;
      
            // Now that we have a normal (A,B,C) and a distance (D) to the plane,
            // we want to normalize that normal and distance.
      
            // Normalize the RIGHT side
            normalizePlane(m_Frustum, RIGHT);
      
            // This will extract the LEFT side of the frustum
            m_Frustum[LEFT][A] = clip.m30 + clip.m00;
            m_Frustum[LEFT][B] = clip.m31 + clip.m01;
            m_Frustum[LEFT][C] = clip.m32 + clip.m02;
            m_Frustum[LEFT][D] = clip.m33 + clip.m03;
      
            // Normalize the LEFT side
            normalizePlane(m_Frustum, LEFT);
      
            // This will extract the BOTTOM side of the frustum
            m_Frustum[BOTTOM][A] = clip.m30 + clip.m10;
            m_Frustum[BOTTOM][B] = clip.m31 + clip.m11;
            m_Frustum[BOTTOM][C] = clip.m32 + clip.m12;
            m_Frustum[BOTTOM][D] = clip.m33 + clip.m13;
      
            // Normalize the BOTTOM side
            normalizePlane(m_Frustum, BOTTOM);
      
            // This will extract the TOP side of the frustum
            m_Frustum[TOP][A] = clip.m30 - clip.m10;
            m_Frustum[TOP][B] = clip.m31 - clip.m11;
            m_Frustum[TOP][C] = clip.m32 - clip.m12;
            m_Frustum[TOP][D] = clip.m33 - clip.m13;
      
            // Normalize the TOP side
            normalizePlane(m_Frustum, TOP);
      
            // This will extract the BACK side of the frustum
            m_Frustum[BACK][A] = clip.m30 - clip.m20;
            m_Frustum[BACK][B] = clip.m31 - clip.m21;
            m_Frustum[BACK][C] = clip.m32 - clip.m22;
            m_Frustum[BACK][D] = clip.m33 - clip.m23;
      
            // Normalize the BACK side
            normalizePlane(m_Frustum, BACK);
      
            // This will extract the FRONT side of the frustum
            m_Frustum[FRONT][A] = clip.m30 + clip.m20;
            m_Frustum[FRONT][B] = clip.m31 + clip.m21;
            m_Frustum[FRONT][C] = clip.m32 + clip.m22;
            m_Frustum[FRONT][D] = clip.m33 + clip.m23;
      
            // Normalize the FRONT side
            normalizePlane(m_Frustum, FRONT);            

Here is how I do it. I’ve been using it for a long time with no problems.


// Left
frustum[0] = matrix.m03 + matrix.m00;
frustum[1] = matrix.m13 + matrix.m10;
frustum[2] = matrix.m23 + matrix.m20;
frustum[3] = matrix.m33 + matrix.m30;

// Right
frustum[4] = matrix.m03 - matrix.m00;
frustum[5] = matrix.m13 - matrix.m10;
frustum[6] = matrix.m23 - matrix.m20;
frustum[7] = matrix.m33 - matrix.m30;

// Top
frustum[8] = matrix.m03 - matrix.m01;
frustum[9] = matrix.m13 - matrix.m11;
frustum[10] = matrix.m23 - matrix.m21;
frustum[11] = matrix.m33 - matrix.m31;

// Bottom
frustum[12] = matrix.m01 + matrix.m03;
frustum[13] = matrix.m11 + matrix.m13;
frustum[14] = matrix.m21 + matrix.m23;
frustum[15] = matrix.m31 + matrix.m33;

// Near
frustum[16] = matrix.m02 + matrix.m03;
frustum[17] = matrix.m12 + matrix.m13;
frustum[18] = matrix.m22 + matrix.m23;
frustum[19] = matrix.m32 + matrix.m33;

// Far
frustum[20] = matrix.m03 - matrix.m02;
frustum[21] = matrix.m13 - matrix.m12;
frustum[22] = matrix.m23 - matrix.m22;
frustum[23] = matrix.m33 - matrix.m32;

Of course with the normalizations in between.

Spasi

You mention that you have this working in Gl4Java? There rumours that Gl4Java flips a couple of matricies when it shouldn’t. Or possibly you’re expecting row-major and getting coloumn major. Try flipping you matrix on its main diagonal and see if that helps.

I made transformation grid on paper so the cells of the matrices should correspond to one another.

When I use the LWGL load, does it really load the cells into right places?

I’m going to go through the code for awhile and perhaps report the code from markmoley.com

Have a look at Cas’ SPL over at sourceforge, theres a Frustum class that I used as an example when I did my view culling Frustum…

My bad… I will go blast my brains out…

Never ever copy and paste same code over and over… NEVER EVER!!!

Well ok ok I was tired, but this post will remain as mark of my stupidity.

My problem still remains, the matrix code is now 100% correct, but due the fact that my result looks different from GT result I can’t be sure whether my mathematics is correct. I drew the planes on paper and they seemed to be fine, now if you know what the GT code is supposed to look like, you know that the speheres are supposed to go behind you.

In my example they don’t.

Would someone bother to take look at my code? it will be hosted suicidesolutions.com/fos3d.zip

I will give birth to your manbabies if you’d do so.

The rendering code is verry dirty and in GameEngine, viewfrustum is the frutum,

Matrix4f.mul(proj, modl, clip);

had to be changed in order it works properly. Most likely I had the math right from the very beginning then I got it wrong myself, and fell deeper into the hole. Oh so dreamy!
Now the occlusion culling… HAR HAR.

My own math library does things other way around, but now it works perfectily. THX MR. GOATSE.