OpenGL Frustum Culling Problem

Started by
24 comments, last by n0obAtroN 14 years, 10 months ago
Try this, if it isn't working, I won't reply any more:

static struct Matrix4x4 proj, modl, clip;    static struct Plane * p;    glGetFloatv(GL_PROJECTION_MATRIX, &proj.m[0]);    glGetFloatv(GL_MODELVIEW_MATRIX, &modl.m[0]);    clip = multiplyMatrix4x4(proj, modl);    clip = getInvertedMatrix4x4(clip);....


It's based on a shadow mapping code I downloaded.
And try to use own multiplication code with correct indexing (as mentioned).
Advertisement
With using your matrix multiplication code and inverting the clip matrix **everything** (including off-screen objects) is now rendered.

    clip = multiplyMatrix4x4(proj, modl);    clip = getInvertedMatrix4x4(clip);


/** thanks to szecs at GameDev.net **/FASTCALL struct Matrix4x4 multiplyMatrix4x4(struct Matrix4x4 a, struct Matrix4x4 b){    struct Matrix4x4 c;    c.m[0]  = a.m[0] * b.m[0]  + a.m[4] * b.m[1]  + a.m[8]  * b.m[2]  + a.m[12] * b.m[3];    c.m[1]  = a.m[1] * b.m[0]  + a.m[5] * b.m[1]  + a.m[9]  * b.m[2]  + a.m[13] * b.m[3];    c.m[2]  = a.m[2] * b.m[0]  + a.m[6] * b.m[1]  + a.m[10] * b.m[2]  + a.m[14] * b.m[3];    c.m[3]  = a.m[3] * b.m[0]  + a.m[7] * b.m[1]  + a.m[11] * b.m[2]  + a.m[15] * b.m[3];    c.m[4]  = a.m[0] * b.m[4]  + a.m[4] * b.m[5]  + a.m[8]  * b.m[6]  + a.m[12] * b.m[7];    c.m[5]  = a.m[1] * b.m[4]  + a.m[5] * b.m[5]  + a.m[9]  * b.m[6]  + a.m[13] * b.m[7];    c.m[6]  = a.m[2] * b.m[4]  + a.m[6] * b.m[5]  + a.m[10] * b.m[6]  + a.m[14] * b.m[7];    c.m[7]  = a.m[3] * b.m[4]  + a.m[7] * b.m[5]  + a.m[11] * b.m[6]  + a.m[15] * b.m[7];    c.m[8]  = a.m[0] * b.m[8]  + a.m[4] * b.m[9]  + a.m[8]  * b.m[10] + a.m[12] * b.m[11];    c.m[9]  = a.m[1] * b.m[8]  + a.m[5] * b.m[9]  + a.m[9]  * b.m[10] + a.m[13] * b.m[11];    c.m[10] = a.m[2] * b.m[8]  + a.m[6] * b.m[9]  + a.m[10] * b.m[10] + a.m[14] * b.m[11];    c.m[11] = a.m[3] * b.m[8]  + a.m[7] * b.m[9]  + a.m[11] * b.m[10] + a.m[15] * b.m[11];    c.m[12] = a.m[0] * b.m[12] + a.m[4] * b.m[13] + a.m[8]  * b.m[14] + a.m[12] * b.m[15];    c.m[13] = a.m[1] * b.m[12] + a.m[5] * b.m[13] + a.m[9]  * b.m[14] + a.m[13] * b.m[15];    c.m[14] = a.m[2] * b.m[12] + a.m[6] * b.m[13] + a.m[10] * b.m[14] + a.m[14] * b.m[15];    c.m[15] = a.m[3] * b.m[12] + a.m[7] * b.m[13] + a.m[11] * b.m[14] + a.m[15] * b.m[15];}


*sigh*. Any ideas?
Turns out the matrix multiplication code is the problem, still working to fix it however.

The clip matrix is being returned as the following values:
{{1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0} {1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0} {1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0} {1.#QNAN0, 1.#QNAN0, 1.#QNAN0, 1.#QNAN0}}


I have since re-written the matrix multiplication code:
FASTCALL struct Matrix4x4 multiplyMatrix4x4(struct Matrix4x4 a, struct Matrix4x4 b){    struct Matrix4x4 c;    s32 i, j, k;    for (i = 0; i < 4; i++)        for (j = 0; j < 4; j++)            for (k = 0; k < 4; k++)                c.m += a.m * b.m[k * 4 + j];<br><br>    return c;<br>}<br></pre><br><br>This new multiplyMatrix4x4() function does not give weird values.<br><br>Now the inverted clip matrix is being returned as the following values:<br><pre><br>{{0.000000, -1.#IND00, 0.000000, 0.000000}<br> {0.000000, -1.#IND00, 0.000000, 0.000000}<br> {0.000000, 0.000000, 0.000000, 0.000000}<br> {-1.#IND00, -1.#IND00, 0.000000, -1.#IND00}}<br></pre><br><br>Any ideas?
Just a quick comment on your matrix multiplication code: you're not zeroing out c before you perform the multiplication, which means that the result may or may not be correct. (This may not be causing you any problems currently - for example, it may be that the memory just happens to be zeroed already for whatever reason - but it's something that should be fixed nonetheless.)
I don't know. I thought functions cannot return arrays, just single values or pointers.
So he uses arrays that's really just pointers, that had been deallocated after returning from the functions. But it worked in some parts of his code for some reason, so I don't know.
Should use output params as pointers in the param. list. (void functions of course)
That really shouldn't have be a problem, but it was. I simply made the structures in the functions static. Now everything is being culled yet again.

The following data was extracted with the camera at (0, 0, 0), rotated by (60, 90, 0).

Projection matrix:{{2.414214, 0.000000, 0.000000, 0.000000} {0.000000, 2.414214, 0.000000, 0.000000} {0.000000, 0.000000, -1.001955, -1.000000} {0.000000, 0.000000, -2.001955, 0.000000}}Model-view matrix:{{0.000000, 0.866025, -0.500000, 0.000000} {0.000000, 0.500000, 0.866025, 0.000000} {1.000000, 0.000000, 0.000000, 0.000000} {0.000000, -12.500000, -21.650633, 1.000000}}Clip matrix before invertion:{{0.000000, 2.090770, 0.500977, 0.500000} {0.000000, 1.207107, -0.867718, -0.866025} {2.414213, 0.000000, -0.000000, -0.000000} {0.000000, -30.177671, 19.691006, 21.650633}}Clip matrix after invertion:{{0.000000, -0.000000, 0.414214, -0.000000} {0.358719, 0.207107, -0.000000, -0.000000} {-0.000000, -12.487791, 0.000000, -0.499512} {0.500000, 11.646179, -0.000000, 0.500488}}Right Plane before normalization: {-0.000000, -0.358719, -0.499511, -0.000488}Right Plane after normalization: {-0.000000, -0.457433, -0.636968, -0.000622}Left Plane before normalization: {0.000000, 0.358719, -0.499512, -1.000489}Left Plane after normalization: {0.000000, 0.457432, -0.636968, -1.275804}Bottom Plane before normalization: {-0.000000, 0.207107, -12.987303, -12.146667}Bottom Plane after normalization: {-0.000000, 0.057465, -3.603561, -3.370311}Top Plane before normalization: {0.000000, -0.207107, 11.988279, 11.145691}Top Plane after normalization: {0.000000, -0.059811, 3.462151, 3.218816}Back Plane before normalization: {-0.414214, 0.000000, -0.499512, -0.500488}Back Plane after normalization: {-0.514200, 0.000000, -0.620088, -0.621300}Front Plane before normalization: {0.414214, -0.000000, -0.499512, -0.500488}Front Plane after normalization: {0.514200, -0.000000, -0.620088, -0.621300}

This topic is closed to new replies.

Advertisement