Skip to main content
GameDev.net gamedev.net
🔒 Locked

More lighting problems

Started by Chuffy_345 Mar 26, 2004 at 5:25 AM 1 replies 650+ views
Original Post
Chuffy_345
Chuffy_345
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
Galapaegos
Galapaegos
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]
-brad

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.