sourcez

07-29-2011, 01:18 PM

Hi everyone - I found this tutorial on devmaster.

<a href="http://read.pudn.com/downloads117/sourcecode/windows/opengl/498282/schatten.cpp__.htm

" rel="nofollow" target="_blank">tutorial</a>

I managed to get it into my project.

Here's the Problem. I have a Plane I'm casting the shadow "onto" - now if there's a shadow that goes over the edge of this plan - it casts a shadow in the air,..

Since I don't understand what's going on in the code - maybe one of you guys could help me out? Hint?!

The relevant part:

void glShadowProjection(float * l, float * e, float * n)

{

float d, c;

float mat[16];

// These are c and d (corresponding to the tutorial)

d = sNormal[0]*l[0] + sNormal[1]*l[1] + sNormal[2]*l[2];

c = sPlane[0]*sNormal[0] + sPlane[1]*sNormal[1] + sPlane[2]*sNormal[2] - d;

// Creating matrix. (Column by column ordering)

mat[0] = sLight[0]*sNormal[0]+c;

mat[4] = sNormal[1]*sLight[0];

mat[8] = sNormal[2]*sLight[0];

mat[12] = -sLight[0]*c-sLight[0]*d;

mat[1] = sNormal[0]*sLight[1];

mat[5] = sLight[1]*sNormal[1]+c;

mat[9] = sNormal[2]*sLight[1];

mat[13] = -sLight[1]*c-sLight[1]*d;

mat[2] = sNormal[0]*sLight[2];

mat[6] = sNormal[1]*sLight[2];

mat[10] = sLight[2]*sNormal[2]+c;

mat[14] = -sLight[2]*c-sLight[2]*d;

mat[3] = sNormal[0];

mat[7] = sNormal[1];

mat[11] = sNormal[2];

mat[15] = -d;

// Multiply the matrices together.

glMultMatrixf(mat);

}

Thanks a lot!

<a href="http://read.pudn.com/downloads117/sourcecode/windows/opengl/498282/schatten.cpp__.htm

" rel="nofollow" target="_blank">tutorial</a>

I managed to get it into my project.

Here's the Problem. I have a Plane I'm casting the shadow "onto" - now if there's a shadow that goes over the edge of this plan - it casts a shadow in the air,..

Since I don't understand what's going on in the code - maybe one of you guys could help me out? Hint?!

The relevant part:

void glShadowProjection(float * l, float * e, float * n)

{

float d, c;

float mat[16];

// These are c and d (corresponding to the tutorial)

d = sNormal[0]*l[0] + sNormal[1]*l[1] + sNormal[2]*l[2];

c = sPlane[0]*sNormal[0] + sPlane[1]*sNormal[1] + sPlane[2]*sNormal[2] - d;

// Creating matrix. (Column by column ordering)

mat[0] = sLight[0]*sNormal[0]+c;

mat[4] = sNormal[1]*sLight[0];

mat[8] = sNormal[2]*sLight[0];

mat[12] = -sLight[0]*c-sLight[0]*d;

mat[1] = sNormal[0]*sLight[1];

mat[5] = sLight[1]*sNormal[1]+c;

mat[9] = sNormal[2]*sLight[1];

mat[13] = -sLight[1]*c-sLight[1]*d;

mat[2] = sNormal[0]*sLight[2];

mat[6] = sNormal[1]*sLight[2];

mat[10] = sLight[2]*sNormal[2]+c;

mat[14] = -sLight[2]*c-sLight[2]*d;

mat[3] = sNormal[0];

mat[7] = sNormal[1];

mat[11] = sNormal[2];

mat[15] = -d;

// Multiply the matrices together.

glMultMatrixf(mat);

}

Thanks a lot!