[b][red]This message was edited by the Cyt at 2002-2-15 9:44:44[/red][/b][hr]
I'm trying to calculate some decent normal vectors for some triangles. However, the current state is quite miserable.
My initial object is quite simple: It's simply an z(x,y) grid where x and y both range from 0 to 10. I've decided to draw the triangles using GL_TRIANGLE_STRIP, which works perfectly. However, the lights are causing me lot's of problems - and it seems to be the normal vector calculus that is simply wrong :-(
Say, I have three 3D points: Point0,Point1, and Point2: I then calculate Point2-Point0 and Point1-0 and put them in the 3D Points P1m0, and P2m0 (This code could probably be more efficient, but that matter can wait):
From my beatiful Schaum, I then use these two vectors to get a Scalar product, which, AFAIK, is the normal vector of the surface:
NormalX,NormalY,NormalZ are doubles.
And then I normalise:
NormalScaler=1./sqrt(NormalX*NormalX + NormalY*NormalY + NormalZ*NormalZ);
glVertex3s(Point2.X,Point2.Y,Point2.Z); // The two last ones were of course Point0 and Point1
In the lighting, I then do this:
glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
// Make some arbitrary light values...
float fLightPos =
glLightfv(GL_LIGHT0, GL_POSITION, fLightPos);
// Rotate the b*tch
Can anyone find out why it looks like crap from this?
And please forgive me if it turns out that I've misunderstood something completely. This is only my second day of OpenGL...
I found out about it... I've even made a small normal vector routine. If anybody's interested:
void MakeNormalVectorf(float Ax,float Ay,float Az,float Bx,float By,float Bz)
fTemp=Ay*Bz-Az*By; // X
Bz=Az*Bx-Ax*Bz; // Y
Az=Ax*By-Ay*Bx; // Z
Ax=1.f/(float)sqrt(fTemp*fTemp + Bz*Bz + Az*Az); // Scaler