Each corner of the cube has 3 vertices for the 3 touching faces. How do I get the normals for each vertice of each corner? Thank you for your help,
-Corillian
How do you calculate normals for a cube?
Started by Corillian, Jul 19 2001 02:26 PM
8 replies to this topic
Ad:
#2 Moderators - Reputation: 1315
Posted 19 July 2001 - 03:32 PM
Check out Nehe''s lesson 7/8 tut. That should help you out a lot (http://nehe.gamedev.net in case u didn''t know)
------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
#5 Moderators - Reputation: 1315
Posted 19 July 2001 - 04:40 PM
Corillian: uhh, he asked how to calculate hte normals for a cube, and what does lesson 7 do? Calculate the normals for a cube, so it can be LIGHTED.
------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
------------------------------
Trent (ShiningKnight)
E-mail me
OpenGL Game Programming Tutorials
#6 Members - Reputation: 122
Posted 19 July 2001 - 08:29 PM
Take the average of the face normals of every face that uses the vertex.
There are better ways of calculating like weighting by face angle. You can read in the 3D Studio Max SDK how this method works.
Edited by - bobo on July 20, 2001 3:31:14 AM
There are better ways of calculating like weighting by face angle. You can read in the 3D Studio Max SDK how this method works.
Edited by - bobo on July 20, 2001 3:31:14 AM
#7 Anonymous Poster_Anonymous Poster_* Guests - Reputation:
Posted 20 July 2001 - 02:53 AM
Each face has 4 vertices and 4 lines (vectors) ajoining them.
To calculate the normal get the cross product of
any 2 of the 4 vectors.
I have included code for a cube with the surface
normals stated explicitly.
This works for shading etc.
The normal to the top face is the unit vector pointing up
(0,1,0)
The normal to the bottom face is the unit vector pointing down
(0,-1,0) etc.
this draws a cube ready for shading
Hope it works
void DrawBox()
{
glPushMatrix();
glTranslatef(position.x,position.y,position.z);
glBegin(GL_POLYGON);
glNormal3f(0.0f, 1.0f, 0.0f); //top face Normal
glVertex3f(0.5f, 0.5f, 0.5f); // top face
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, 1.0f); // N front face
glVertex3f(0.5f, 0.5f, 0.5f); // front face
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(1.0f, 0.0f, 0.0f); // N right face
glVertex3f(0.5f, 0.5f, 0.5f); // right face
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(-1.0f, 0.0f, 0.0f); // N left face
glVertex3f(-0.5f, 0.5f, 0.5f); // left face
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, -1.0f, 0.0f); // N bottom face
glVertex3f(0.5f, 0.5f, 0.5f); // bottom face
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, -1.0f); // N back face
glVertex3f(0.5f, 0.5f, -0.5f); // back face
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f); glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
glPopMatrix();
}
To calculate the normal get the cross product of
any 2 of the 4 vectors.
I have included code for a cube with the surface
normals stated explicitly.
This works for shading etc.
The normal to the top face is the unit vector pointing up
(0,1,0)
The normal to the bottom face is the unit vector pointing down
(0,-1,0) etc.
this draws a cube ready for shading
Hope it works
void DrawBox()
{
glPushMatrix();
glTranslatef(position.x,position.y,position.z);
glBegin(GL_POLYGON);
glNormal3f(0.0f, 1.0f, 0.0f); //top face Normal
glVertex3f(0.5f, 0.5f, 0.5f); // top face
glVertex3f(0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, 0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, 1.0f); // N front face
glVertex3f(0.5f, 0.5f, 0.5f); // front face
glVertex3f(-0.5f, 0.5f, 0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(1.0f, 0.0f, 0.0f); // N right face
glVertex3f(0.5f, 0.5f, 0.5f); // right face
glVertex3f(0.5f, -0.5f, 0.5f);
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(0.5f, 0.5f, -0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(-1.0f, 0.0f, 0.0f); // N left face
glVertex3f(-0.5f, 0.5f, 0.5f); // left face
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, -1.0f, 0.0f); // N bottom face
glVertex3f(0.5f, 0.5f, 0.5f); // bottom face
glVertex3f(0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, 0.5f);
glEnd();
glBegin(GL_POLYGON);
glNormal3f(0.0f, 0.0f, -1.0f); // N back face
glVertex3f(0.5f, 0.5f, -0.5f); // back face
glVertex3f(-0.5f, 0.5f, -0.5f);
glVertex3f(-0.5f, -0.5f, -0.5f); glVertex3f(0.5f, -0.5f, -0.5f);
glEnd();
glPopMatrix();
}






