I have a world that consists of many quads and polygons, it has also some lighting. In order OpenGL to lit everything correctly, it needs normals with glNormal3f(float X,float Y,float Z); Yes, I used it but some walls are lightened up, some not(some are black). .?.
Here are my functions:
VPoint cross(VPoint v1,VPoint v2){ VPoint normal; normal.x=(v1.y*v2.z)-(v1.z*v2.y); normal.y=(v1.z*v2.x)-(v1.x*v2.z); normal.z=(v1.x*v2.y)-(v1.y*v2.x); return normal;} // float Magn(VPoint n){ float m; m=(float)sqrt((n.x*n.x)+(n.y*n.y)+(n.z*n.z)); return m;} // VPoint Normalise(VPoint n){ float m=Magn(n); n.x/=m; n.y/=m; n.z/=m; return n;} // VPoint GetNormal(VPoint v[QUAD_P]){ VPoint v1=v[2]-v[0]; VPoint v2=v[1]-v[0]; VPoint n=cross(v1,v2); n=Normalise(n); return n;}
And here is VPoint structure:
struct VPoint{ float x,y,z; VPoint(){} VPoint(float X,float Y,float Z){ x=X; y=Y; z=Z;} VPoint operator+(VPoint v){ return VPoint(x+v.x, y+v.y, z+v.z);} VPoint operator-(VPoint v){ return VPoint(x-v.x, y-v.y, z-v.z);} VPoint operator*(float v){ return VPoint(x*v, y*v, z*v);} VPoint operator/(float v){ return VPoint(x/v,y/v,z/v);} };
I think the normal coordinates come wrong when I use GetNormal(); function, how to make it working?
Any suggestions are welcome…