#### Archived

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

# glNormal must DIe

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

## Recommended Posts

im using this function to get my normals for polygons Point3 normal(Point3 p1, Point3 p2, Point3 p3) { Point3 tmp1 = {p1.x - p2.x, p1.y - p2.y, p1.z - p2.z}; Point3 tmp2 = {p2.x - p3.x, p2.y - p3.y, p2.z - p3.z}; Point3 tmp3 = {tmp1.y*tmp2.z - tmp1.z*tmp2.y, tmp1.z*tmp2.x - tmp1.x*tmp2.z, tmp1.x*tmp2.y - tmp1.y*tmp2.x}; float length = (float)sqrt( tmp3.x*tmp3.x + tmp3.y*tmp3.y + tmp3.z*tmp3.z); tmp3.x /= length; tmp3.y /= length; tmp3.z /= length; return tmp3; } it is not workin good, only half of the polygons im rendering are shaded correctly, i''m doing something wrong. Can''t opengl just specify a camera and do all light bloking testing and all taht stuff, its killing me!!

##### Share on other sites
try changing this:

Point3 tmp1 = {p1.x - p2.x, p1.y - p2.y, p1.z - p2.z};
Point3 tmp2 = {p2.x - p3.x, p2.y - p3.y, p2.z - p3.z};

to this:

Point3 tmp1 = {p2.x - p1.x, p2.y - p1.y, p2.z - p1.z};
Point3 tmp2 = {p3.x - p1.x, p3.y - p1.y, p3.z - p1.z};

other from that I think everything else looks good.
If only OpenGL would do all the lighting and camera stuff for us that would be great Sadly, we are left with all that dirty work

Edited by - blueEbola on February 20, 2002 9:03:42 PM

##### Share on other sites
another thing you can do is enable normalising. This way you don''t have to change the normal i,j,k to a range of -1 to 1. saves code and its faster than what you have.
quote:

float length = (float)sqrt( tmp3.x*tmp3.x + tmp3.y*tmp3.y + tmp3.z*tmp3.z);
tmp3.x /= length;
tmp3.y /= length;
tmp3.z /= length;

btw, you could have used a bunch of if statements instead of the sqrt call aswell, but using normalise will let you not bother about it.

Beer - the love catalyst
good ol'' homepage

##### Share on other sites
Enabling normalising is a bad plan if you can store normals in your game data already, this way your comp only needs to calculate normals once instead of every frame.

1. 1
2. 2
3. 3
Rutin
20
4. 4
frob
18
5. 5

• 32
• 13
• 10
• 11
• 9
• ### Forum Statistics

• Total Topics
632561
• Total Posts
3007088

×