glNormal must DIe

Started by
2 comments, last by cb007sax 22 years, 1 month ago
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!!
Advertisement
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
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
Beer - the love catalystgood ol' homepage
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.
Ignorance is bliss but some people are just stupid.

This topic is closed to new replies.

Advertisement