Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- GUMatrix4 buildShadowMatrix(GLfloat groundplane[4], GLfloat lightpos[4])
- {
- GLfloat dot;
- GLfloat shadowMat[4][4];
- int X = 0, Y = 1, Z = 2, W = 3;
- dot = groundplane[X] * lightpos[X] + groundplane[Y] * lightpos[Y] + groundplane[Z] * lightpos[Z] + groundplane[W] * lightpos[W];
- shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
- shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
- shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
- shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
- shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
- shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
- shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
- shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
- shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
- shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
- shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
- shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
- shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
- shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
- shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
- shadowMat[3][3] = dot - lightpos[W] * groundplane[W];
- GUVector4 temp[4];
- for (int i = 0; i < 4; i++)
- temp[i] = GUVector4(shadowMat[i][0], shadowMat[i][1], shadowMat[i][2], shadowMat[i][3]);
- GUMatrix4 shadowMatrix = GUMatrix4(temp[0], temp[1], temp[2], temp[3]);
- return shadowMatrix;
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement