Advertisement

Calculating Shadows

Started by April 03, 2001 12:36 PM
2 comments, last by steveharper101 23 years, 10 months ago
Hi i have purchased the OpenGL superbible and although it''s a good book for begnning to learn openGL it doesn''t go into much derail on the maths. Please could somebody help me with the function belo. How does it work?? I don''t know how to calculate Dot product or do back substitution. // Creates a shadow projection matrix out of the plane equation // coefficients and the position of the light. The return value is stored // in destMat[][] void MakeShadowMatrix(GLfloat points[3][3], GLfloat lightPos[4], GLfloat destMat[4][4]) { GLfloat planeCoeff[4]; GLfloat dot; // Find the plane equation coefficients // Find the first three coefficients the same way we // find a normal. calcNormal(points,planeCoeff); // Find the last coefficient by back substitutions planeCoeff[3] = - ( (planeCoeff[0]*points[2][0]) + (planeCoeff[1]*points[2][1]) + (planeCoeff[2]*points[2][2])); // Dot product of plane and light position dot = planeCoeff[0] * lightPos[0] + planeCoeff[1] * lightPos[1] + planeCoeff[2] * lightPos[2] + planeCoeff[3] * lightPos[3]; // Now do the projection // First column destMat[0][0] = dot - lightPos[0] * planeCoeff[0]; destMat[1][0] = 0.0f - lightPos[0] * planeCoeff[1]; destMat[2][0] = 0.0f - lightPos[0] * planeCoeff[2]; destMat[3][0] = 0.0f - lightPos[0] * planeCoeff[3]; // Second column destMat[0][1] = 0.0f - lightPos[1] * planeCoeff[0]; destMat[1][1] = dot - lightPos[1] * planeCoeff[1]; destMat[2][1] = 0.0f - lightPos[1] * planeCoeff[2]; destMat[3][1] = 0.0f - lightPos[1] * planeCoeff[3]; // Third Column destMat[0][2] = 0.0f - lightPos[2] * planeCoeff[0]; destMat[1][2] = 0.0f - lightPos[2] * planeCoeff[1]; destMat[2][2] = dot - lightPos[2] * planeCoeff[2]; destMat[3][2] = 0.0f - lightPos[2] * planeCoeff[3]; // Fourth Column destMat[0][3] = 0.0f - lightPos[3] * planeCoeff[0]; destMat[1][3] = 0.0f - lightPos[3] * planeCoeff[1]; destMat[2][3] = 0.0f - lightPos[3] * planeCoeff[2]; destMat[3][3] = dot - lightPos[3] * planeCoeff[3]; } Cheers Steve
Hi Steve,
I too have just purchased the Super Bible, but haven''t reached the chapther on lighting yet.
I will try to explain what is happening, but you will have to correct me if I am wrong coz it has been a while since I had last touched math.
I will try to explain what a dot product is. I don''t have a math book nearby, so certain points may not be correct!
Let us take two vectors A and B.
Let C = A.B (dot product) ---(1)
=> C = A*B*cos(theta) ---(2) //theta is the angle between the two vectors.
What is the physical meaning of C.
C is the projection of vector A on vector B. Let me put it into English.
From equation (2) you can see that as the angle approaches 90 degrees or PI/2 radians, the value of C becomes smaller.
This means that if A is perpendicular to B the C = 0.
This is the way a shadow is created. As the angle between the ray of light and a plane approaches 90 degrees (angle of incidence approaches 0), the shadow becomes smaller.
You would have observed this effect everday of your life (Hope the sun shines every day in the UK or does it vanish for 6 months like in places above the 60 degree lattitude).

Sorry Steve, I have to go for a meeting (time here is 9:00 AM and I have a meeting to attend), I will come back to this later in the day.
If you do find any flaws in the explaination, please let me know, I will go and buy a book on 3D mathematics.

Amresh
ramresh@dsqsoft.com
dArkteMplaR of Delphi
Advertisement
Thanks alot for the post
Thanks alot for the post any idea how cross product formula works in english

Thanks

Steve

This topic is closed to new replies.

Advertisement