# Calculating normals with set vertexes?

say i have these 3 verticies…
int v1 = {-5,1,0};
int v2 = {-5,1,35};
int v3 = {5,1,35};
int v4 = {5,1,0};

i make a GL_QUADS with these 4 verticies…
how do i find the normal? (i want to have a separate function that i could send 3 of the verticies to and have it return the normal…
someone help me?

I am looking for the same information, if i find i will post it here, if you do could you do the same?

thanks.

Here is for normal of a triangle, as long as the quad is flat it may work ok using only three sides.

float n1;

getFaceNormal(n1, v1, v2, v3);
glNormal3fv( n1 );

void normalize(float * vect) //scales a vector a length of 1
{
float length;
int a;

``````length=sqrt(					//A^2 + B^2 + C^2 = length^2
pow(vect,2)+
pow(vect,2)+
pow(vect,2)
);

for (a=0;a&lt;3;++a)				//divides vector by its length to normalise
{
vect[a]/=length;
}
``````

}

void crossProduct(float *c,float a, float b) //finds the cross product of two vectors
{
c=a*b - b*a;
c=a*b - b*a;
c=a*b - b*a;
}

void getFaceNormal(float *norm,float pointa,float pointb,float pointc)
{
float vect;
int a,b;
float point;

for (a=0;a<3;++a)
{
point[a]=pointa[a]; //copies points into point[][]
point[a]=pointb[a];
point[a]=pointc[a];
}

``````for (a=0;a&lt;2;++a)        //calculates vectors from point to point
``````

{ //and point to point
for (b=0;b<3;++b)
{
vect[a][b]=point[2-a][b]-point[b];
}
}

crossProduct(norm,vect,vect); //calculates vector at 90° to to 2 vectors
normalize(norm); //makes the vector length 1
}

Originally posted by ImpactDNI:
[b]say i have these 3 verticies…
int v1 = {-5,1,0};
int v2 = {-5,1,35};
int v3 = {5,1,35};
int v4 = {5,1,0};

i make a GL_QUADS with these 4 verticies…
how do i find the normal? (i want to have a separate function that i could send 3 of the verticies to and have it return the normal…
someone help me?[/b]

Yeah, what Nex said … but break the quad into two triangles and compute a normal for each triangle … problem solved … I promise you that you really don’t want to go off doing this for quads, even the slightest aberation in the surface flatness will hose a lit model.

When i try to send getFaceNormal(n1, v1, v2, v3); it has a problem, it says it cant convert the v1 to v1

heres my code (look for ********)

float normal(int num, float v1, float v2, float v3){
float newvects;
float points;
for (int a = 0; a<3; a++){
points[a] = v1[a];
points[a] = v2[a];
points[a] = v3[a];
}
}

int v1 = {-5,1,0};
int v2 = {-5,1,35};
int v3 = {5,1,35};
int v4 = {5,1,0};
int v5 = {-5,-1,0};
int v6 = {-5,-1,35};
int v7 = {5,-1,35};
int v8 = {5,-1,0};
int v9 = {0,0,45};
glPolygonMode(GL_FRONT_AND_BACK, GL_FILL);
glColor3f(.8,.8,.8);
float n1;
********** normal(1, v1, v2, v3);
glVertex3iv(v1);
glVertex3iv(v2);
glVertex3iv(v3);
glVertex3iv(v4);

``````	glVertex3iv(v5);
glVertex3iv(v6);
glVertex3iv(v7);
glVertex3iv(v8);

glVertex3iv(v1);
glVertex3iv(v5);
glVertex3iv(v6);
glVertex3iv(v2);

glVertex3iv(v4);
glVertex3iv(v8);
glVertex3iv(v7);
glVertex3iv(v3);

glVertex3iv(v1);
glVertex3iv(v5);
glVertex3iv(v8);
glVertex3iv(v4);
glEnd();
glBegin(GL_TRIANGLES);
glVertex3iv(v2);
glVertex3iv(v3);
glVertex3iv(v9);

glVertex3iv(v6);
glVertex3iv(v7);
glVertex3iv(v9);

glVertex3iv(v2);
glVertex3iv(v6);
glVertex3iv(v9);

glVertex3iv(v3);
glVertex3iv(v7);
glVertex3iv(v9);
glEnd();
glutSwapBuffers();
``````

}

the first entry “1” is just for which n# the normal is…