Archived

This topic is now archived and is closed to further replies.

More lighting problems

This topic is 5006 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hey guys, I''ve got a snooker table made up of loads of QUADS and a camera which moves around it. The lighting goes to pot though when I start moving the camera around the table. Its because I''ve not calculated the normal that I''m pretty sure of but I don''t know how I''m supposed to do it. Do I need to calculate the normal of each vertex just once or will it need to be done each time the camera moves? Cheers

Share this post


Link to post
Share on other sites
Chuffy_345,

If you are updating your loads of QUADS, then you need to recalculate the normal. otherwise, calculating it once will do.

To calculate the normal for a point, lets think of these quads as a plane in the xz plane (assuming x is the horizontal with respect to the monitor, y is vertical, and z is in and out of the monitor). Our normal is the cross product between two vectors, so if we take the cross product of this xz plane, its either in the +/- y direction.

For a more advanced algorithm to calculate normals, lets take a triangle like this:

...x1----------x2.....
.....\............/.......
......\........../........
.......\......../.........
........\....../..........
.........\..../...........
..........\../............
...........x3.............

First thing we need to know the culling direction, this will determine which direction the normal is pointing (in this case, either in or out of the screen). to calculate the normal at point x1 assuming clockwise rotation and using a righthand rule, we need to take the cross product of (x1-x3)x(x1-x2), which gives us the normal. For x2, we will calculate the normal by (x2-x1)x(x2-x3). Finally for x3, it is (x3-x2)x(x3-x1).

Hope that helps you out,

-brad

EDIT - sorry, stupid ascii art isn't workin right for me

[edited by - Galapaegos on March 26, 2004 6:43:55 AM]

[edited by - Galapaegos on March 26, 2004 6:44:56 AM]

Share this post


Link to post
Share on other sites
Guest Anonymous Poster
If you don''t want to calculate normals yourself, let opengl calculate them for you (glEnable(GL_AUTO_NORMAL))

I hope this helped you

Share this post


Link to post
Share on other sites