Jump to content

  • Log In with Google      Sign In   
  • Create Account

How do you calculate normals for a cube?


Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

  • You cannot reply to this topic
8 replies to this topic

#1 Corillian   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 July 2001 - 02:26 PM

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

Sponsor:

#2 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

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

#3 Corillian   Members   -  Reputation: 122

Like
Likes
Like

Posted 19 July 2001 - 03:56 PM

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.

#4 masterg   Members   -  Reputation: 100

Like
Likes
Like

Posted 19 July 2001 - 04:16 PM

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

#5 mittens   Moderators   -  Reputation: 1315

Like
Likes
Like

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

#6 bobo   Members   -  Reputation: 122

Like
Likes
Like

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

#7 Anonymous Poster_Anonymous Poster_*   Guests   -  Reputation:

Likes

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();


}

#8 Corillian   Members   -  Reputation: 122

Like
Likes
Like

Posted 20 July 2001 - 09:36 AM

Ok, thanks for all of your help =)

#9 smitty1276   Members   -  Reputation: 560

Like
Likes
Like

Posted 20 July 2001 - 07:31 PM

Guys... I don''t think Corillian was talking about face normals.




Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.



PARTNERS