• Create Account

### #ActualLil_Lloyd

Posted 08 February 2013 - 09:26 AM

RENDERING A FRUSTUM

So I found some code on rendering a frustum in old school style fixed pipeline GL


void Frustum::DrawFrustum(){
mat4x4 temp = m_projMatrix * m_modView;
mat4x4 inv = temp._inverse();

vec4 fr[8]=
{
// near
vec4(-1, -1, -1, 1), vec4( 1, -1, -1, 1), vec4( 1,  1, -1, 1),  vec4(-1,  1, -1, 1),
// far
vec4(-1, -1, 1, 1),	vec4( 1, -1, 1, 1),	vec4( 1,  1, 1, 1),  vec4(-1,  1, 1, 1)
};
// Transform all vertices:
// multiply vertex array (fr) by matrix. result is transformed vertex array (tfr)

for(int i = 0; i < 8; i++)
fr[i] = inv * fr[i];

for (int i=0; i<8; i++)
{
fr[i].x /= fr[i].w;
fr[i].y /= fr[i].w;
fr[i].z /= fr[i].w;
fr[i].w = 1.0f;
}

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[1][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[2][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[3][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[0][0]));

glVertex4fv(&(fr[4][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[5][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[6][0]));
glVertex4fv(&(fr[7][0]));

glVertex4fv(&(fr[7][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[7][0]));
glEnd();
}


It seems solid to me, and I have a new 'debug' mode where I detach the camera from the frustum and can control it from above in an orthographic view. However, I'm getting behaviour that is odd. There is no frustum being rendered but only odd lines of varying length depending on camera rotation and sometimes the line doesn't even render unless the camera is in a certain location. Bizarre.

### #2Lil_Lloyd

Posted 08 February 2013 - 09:18 AM

RENDERING A FRUSTUM

So I found some code on rendering a frustum in old school style fixed pipeline GL


void Frustum::DrawFrustum(){
mat4x4 temp = m_projMatrix * m_modView;
mat4x4 inv = temp._inverse();

vec4 fr[8]=
{
// near
vec4(-1, -1, -1, 1), vec4( 1, -1, -1, 1), vec4( 1,  1, -1, 1),  vec4(-1,  1, -1, 1),
// far
vec4(-1, -1, 1, 1),	vec4( 1, -1, 1, 1),	vec4( 1,  1, 1, 1),  vec4(-1,  1, 1, 1)
};
// Transform all vertices:
// multiply vertex array (fr) by matrix. result is transformed vertex array (tfr)

for(int i = 0; i < 8; i++)
fr[i] = inv * fr[i];

for (int i=0; i<8; i++)
{
fr[i].x /= fr[i].w;
fr[i].y /= fr[i].w;
fr[i].z /= fr[i].w;
fr[i].w = 1.0f;
}

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[1][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[2][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[3][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[0][0]));

glVertex4fv(&(fr[4][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[5][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[6][0]));
glVertex4fv(&(fr[7][0]));

glVertex4fv(&(fr[7][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[7][0]));
glEnd();
}


It seems solid to me, and I have a new 'debug' mode where I detach the camera from the frustum and can control it from above in an orthographic view. However, I'm getting behaviour that is odd. There is no frustum being rendered but only odd lines of varying length depending on camera rotation and sometimes the line doesn't even render unless the camera is in a certain location. Bizarre. I'll try and get a video of it up.

### #1Lil_Lloyd

Posted 08 February 2013 - 09:15 AM

RENDERING A FRUSTUM

So I found some code on rendering a frustum in old school style fixed pipeline GL


void Frustum::DrawFrustum(){
mat4x4 temp = m_projMatrix * m_modView;
mat4x4 inv = glm::inverse(temp);

vec4 fr[8]=
{
// near
vec4(-1, -1, -1, 1), vec4( 1, -1, -1, 1), vec4( 1,  1, -1, 1),  vec4(-1,  1, -1, 1),
// far
vec4(-1, -1, 1, 1),	vec4( 1, -1, 1, 1),	vec4( 1,  1, 1, 1),  vec4(-1,  1, 1, 1)
};
// Transform all vertices:
// multiply vertex array (fr) by matrix. result is transformed vertex array (tfr)

for(int i = 0; i < 8; i++)
fr[i] = inv * fr[i];

for (int i=0; i<8; i++)
{
fr[i].x /= fr[i].w;
fr[i].y /= fr[i].w;
fr[i].z /= fr[i].w;
fr[i].w = 1.0f;
}

glColor3f(1.0f,0.0f,0.0f);
glBegin(GL_LINES);

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[1][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[2][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[3][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[0][0]));

glVertex4fv(&(fr[4][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[5][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[6][0]));
glVertex4fv(&(fr[7][0]));

glVertex4fv(&(fr[7][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[0][0]));
glVertex4fv(&(fr[4][0]));

glVertex4fv(&(fr[1][0]));
glVertex4fv(&(fr[5][0]));

glVertex4fv(&(fr[2][0]));
glVertex4fv(&(fr[6][0]));

glVertex4fv(&(fr[3][0]));
glVertex4fv(&(fr[7][0]));
glEnd();
}


It seems solid to me, and I have a new 'debug' mode where I detach the camera from the frustum and can control it from above in an orthographic view. However, I'm getting behaviour that is odd. There is no frustum being rendered but only odd lines of varying length depending on camera rotation and sometimes the line doesn't even render unless the camera is in a certain location. Bizarre. I'll try and get a video of it up.

PARTNERS