lsdi

02-19-2002, 07:46 PM

This way to calc normals is the correct way?

typedef struct fvect{

float x;

float y;

float z;

};

fvect cnormal(fvect vert_1,fvect vert_2)

{

/*

Produto vetorial: <v1,v2,v3> e <u1,u2,u3> = <a, b, c> onde:

a = (v2*u3)-(v3*u2)

b = -(v1*u3)+(u1*v3)

c = (v1*u2)-(v2*u1)

Normalização:

len=sqrt(nx*nx+ny*ny+nz*nz)

if (len>0) {

nx*=(1/len)

ny*=(1/len)

nz*=(1/len)

*/

fvect norm;

float len;

norm.x=(vert_1.y*vert_2.z)-(vert_1.z*vert_2.y);

norm.y=-(vert_1.x*vert_2.z)+(vert_2.x*vert_1.z);

norm.z=(vert_1.x*vert_2.y)-(vert_1.y*vert_2.x);

len=sqrt(norm.x*norm.x+norm.y*norm.y+norm.z+norm.z );

if(len>0) {

norm.x*=1/len;

norm.y*=1/len;

norm.z*=1/len;

}

return norm;

}

typedef struct fvect{

float x;

float y;

float z;

};

fvect cnormal(fvect vert_1,fvect vert_2)

{

/*

Produto vetorial: <v1,v2,v3> e <u1,u2,u3> = <a, b, c> onde:

a = (v2*u3)-(v3*u2)

b = -(v1*u3)+(u1*v3)

c = (v1*u2)-(v2*u1)

Normalização:

len=sqrt(nx*nx+ny*ny+nz*nz)

if (len>0) {

nx*=(1/len)

ny*=(1/len)

nz*=(1/len)

*/

fvect norm;

float len;

norm.x=(vert_1.y*vert_2.z)-(vert_1.z*vert_2.y);

norm.y=-(vert_1.x*vert_2.z)+(vert_2.x*vert_1.z);

norm.z=(vert_1.x*vert_2.y)-(vert_1.y*vert_2.x);

len=sqrt(norm.x*norm.x+norm.y*norm.y+norm.z+norm.z );

if(len>0) {

norm.x*=1/len;

norm.y*=1/len;

norm.z*=1/len;

}

return norm;

}