Jump to content
  • Advertisement

Archived

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

Corillian

How do you calculate normals for a cube?

This topic is 6296 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


Link to post
Share on other sites
Advertisement
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


Link to 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


Link to 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


Link to post
Share on other sites
Guest Anonymous Poster
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


Link to post
Share on other sites

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!