• Advertisement

#### Archived

This topic is now archived and is closed to further replies.

# How do you calculate normals for a cube?

This topic is 6027 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

## Recommended Posts

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

#### Share this post

##### Share on other sites
Advertisement
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

#### Share this post

##### Share on other sites
Those tutorials have nothing to do with per vertex normal calculations. Lesson 8 has nothing to do with normals and lesson 7 only discusses face normals briefly.

#### Share this post

##### Share on other sites
a unit normal = vector / vector''s size . magnitude/size =
sqrt(x2 + y2 + z2). read up on cross product''s too. hope that helped.

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
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

#### Share this post

##### Share on other sites
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();

}

#### Share this post

##### Share on other sites
Ok, thanks for all of your help =)

#### Share this post

##### Share on other sites
Guys... I don''t think Corillian was talking about face normals.

#### Share this post

##### Share on other sites

• Advertisement