B_old

04-06-2003, 05:08 AM

Hello.

I am trying implent stencil shadows in my program and I need the Pinf-matrix badly.

The problem though, is that I can't get it working in any reasonable way. (That means that I cannot see anything)

I hope you can find some error in my code thanks a lot!

float Near = 2.0;

double tangent = tan(Config.ScreenFOV / 2.0);

float y = tangent * Near;

float x = (3 / 4) * y;

float right = x;

float left = -x;

float bottom = -y;

float top = y;

float Pinf[4][4];

const float NUDGE = 0.9999f;

// zero out the matrix

Pinf[0][0] = Pinf[1][0] = Pinf[2][0] = Pinf[3][0] = 0.f;

Pinf[0][1] = Pinf[1][1] = Pinf[2][1] = Pinf[3][1] = 0.f;

Pinf[0][2] = Pinf[1][2] = Pinf[2][2] = Pinf[3][2] = 0.f;

Pinf[0][3] = Pinf[1][3] = Pinf[2][3] = Pinf[3][3] = 0.f;

// create view matrix with infinite far plane

Pinf[0][0] = 2.0 * Near / (right - left);

Pinf[1][1] = 2.0 * Near / (top - bottom);

Pinf[2][2] = -2.f * Near;

Pinf[2][2] = NUDGE * -1.f;

Pinf[2][3] = -1.f;

Pinf[3][2] = Near * NUDGE * -2.f;

Pinf[2][0] = (right + left) / (right - left);

Pinf[2][1] = (top + bottom) / (top - bottom);

glLoadIdentity();

glMatrixMode(GL_PROJECTION); glLoadMatrixf(&Pinf[0][0]);

glMatrixMode(GL_MODELVIEW);

gluLookAt(ViewMat[12],ViewMat[13], ViewMat[14],

ViewMat[8] + ViewMat[12],

ViewMat[9] + ViewMat[13],

ViewMat[10] + ViewMat[14],

ViewMat[4], ViewMat[5], ViewMat[6]);

Thanks for the help!

I am trying implent stencil shadows in my program and I need the Pinf-matrix badly.

The problem though, is that I can't get it working in any reasonable way. (That means that I cannot see anything)

I hope you can find some error in my code thanks a lot!

float Near = 2.0;

double tangent = tan(Config.ScreenFOV / 2.0);

float y = tangent * Near;

float x = (3 / 4) * y;

float right = x;

float left = -x;

float bottom = -y;

float top = y;

float Pinf[4][4];

const float NUDGE = 0.9999f;

// zero out the matrix

Pinf[0][0] = Pinf[1][0] = Pinf[2][0] = Pinf[3][0] = 0.f;

Pinf[0][1] = Pinf[1][1] = Pinf[2][1] = Pinf[3][1] = 0.f;

Pinf[0][2] = Pinf[1][2] = Pinf[2][2] = Pinf[3][2] = 0.f;

Pinf[0][3] = Pinf[1][3] = Pinf[2][3] = Pinf[3][3] = 0.f;

// create view matrix with infinite far plane

Pinf[0][0] = 2.0 * Near / (right - left);

Pinf[1][1] = 2.0 * Near / (top - bottom);

Pinf[2][2] = -2.f * Near;

Pinf[2][2] = NUDGE * -1.f;

Pinf[2][3] = -1.f;

Pinf[3][2] = Near * NUDGE * -2.f;

Pinf[2][0] = (right + left) / (right - left);

Pinf[2][1] = (top + bottom) / (top - bottom);

glLoadIdentity();

glMatrixMode(GL_PROJECTION); glLoadMatrixf(&Pinf[0][0]);

glMatrixMode(GL_MODELVIEW);

gluLookAt(ViewMat[12],ViewMat[13], ViewMat[14],

ViewMat[8] + ViewMat[12],

ViewMat[9] + ViewMat[13],

ViewMat[10] + ViewMat[14],

ViewMat[4], ViewMat[5], ViewMat[6]);

Thanks for the help!