PDA

View Full Version : normal funkyness



BlackSoftware
05-28-2003, 10:25 AM
I'm getting some strange bugs when I compute my normals I'm not sure whats going on.

BlackSoftware
05-28-2003, 10:30 AM
shape="tetra";
static GLfloat verts1[12]={0,1,0, 0,-.5,-1,-.86,-.5,.5,.86,-.5,.5};
static GLfloat vertNorms1[12];//={0,1,0,0,-.5,-1,-.86,-.5,.5,.86,-.5,.5};
static GLint polys1[12]={0,2,1,1,2,3,2,0,3,3,0,1};
static GLint vertsPolys1[12]={0,2,3,0,1,3,0,1,2,1,2,3};
static GLfloat tFlatNorms[12];

/*
CFloatArray is a pointer to a 1d array
with a higher level interface to allow you to treat it like a 2d array whose bounds are determined in the constructor
*/

verts= CFloatArray(4,3,&verts1[0]);
vertNorms=CFloatArray(4,3,&vertNorms1[0]);
polys=CIntArray(4,3,&polys1[0]);
vertsPolys=CIntArray(4,3,&vertsPolys1[0]);
polyNorms=CFloatArray(4,3,&tFlatNorms[0]);


void CMesh::getPolyNorms()
{
GLfloat nverts[3][3];
GLfloat u[3];
GLfloat v[3];
total: "<<polys.w<<'\n';

for(int i=0;i<polys.w;i++)
{
for(int j=0;j<3;j++)
{

nverts[j][0]=verts.get(polys.get(i,j),0);
nverts[j][1]=verts.get(polys.get(i,j),1);
nverts[j][2]=verts.get(polys.get(i,j),2);
}

u[0]=nverts[0][0]-nverts[1][0];
u[1]=nverts[0][1]-nverts[1][1];
u[2]=nverts[0][2]-nverts[1][2];

v[0]=nverts[1][0]-nverts[2][0];
v[1]=nverts[1][1]-nverts[2][1];
v[2]=nverts[1][2]-nverts[2][2];

polyNorms.write(i,0,(u[2]*v[1])-(u[1]*v[2]));
polyNorms.write(i,1,(u[2]*v[0])-(u[0]*v[2]));
polyNorms.write(i,2,(u[0]*u[1])-(u[1]*v[0]));
}
}