Advertisement
macko9393

Untitled

Apr 21st, 2016
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.40 KB | None | 0 0
  1. GUMatrix4 buildShadowMatrix(GLfloat groundplane[4], GLfloat lightpos[4])
  2. {
  3.  
  4. GLfloat dot;
  5. GLfloat shadowMat[4][4];
  6. int X = 0, Y = 1, Z = 2, W = 3;
  7. dot = groundplane[X] * lightpos[X] + groundplane[Y] * lightpos[Y] + groundplane[Z] * lightpos[Z] + groundplane[W] * lightpos[W];
  8. shadowMat[0][0] = dot - lightpos[X] * groundplane[X];
  9. shadowMat[1][0] = 0.f - lightpos[X] * groundplane[Y];
  10. shadowMat[2][0] = 0.f - lightpos[X] * groundplane[Z];
  11. shadowMat[3][0] = 0.f - lightpos[X] * groundplane[W];
  12. shadowMat[X][1] = 0.f - lightpos[Y] * groundplane[X];
  13. shadowMat[1][1] = dot - lightpos[Y] * groundplane[Y];
  14. shadowMat[2][1] = 0.f - lightpos[Y] * groundplane[Z];
  15. shadowMat[3][1] = 0.f - lightpos[Y] * groundplane[W];
  16. shadowMat[X][2] = 0.f - lightpos[Z] * groundplane[X];
  17. shadowMat[1][2] = 0.f - lightpos[Z] * groundplane[Y];
  18. shadowMat[2][2] = dot - lightpos[Z] * groundplane[Z];
  19. shadowMat[3][2] = 0.f - lightpos[Z] * groundplane[W];
  20. shadowMat[X][3] = 0.f - lightpos[W] * groundplane[X];
  21. shadowMat[1][3] = 0.f - lightpos[W] * groundplane[Y];
  22. shadowMat[2][3] = 0.f - lightpos[W] * groundplane[Z];
  23. shadowMat[3][3] = dot - lightpos[W] * groundplane[W];
  24. GUVector4 temp[4];
  25. for (int i = 0; i < 4; i++)
  26. temp[i] = GUVector4(shadowMat[i][0], shadowMat[i][1], shadowMat[i][2], shadowMat[i][3]);
  27.  
  28.  
  29. GUMatrix4 shadowMatrix = GUMatrix4(temp[0], temp[1], temp[2], temp[3]);
  30.  
  31. return shadowMatrix;
  32. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement