PDA

View Full Version : how these cube vertices are defined??



darshan
05-21-2010, 07:04 AM
hi this array is [6][4][4] array... it represents 6 faces of the cube and 4 vertices of each face.any one who can tell me how these vertices in the array are defined ex:{-1.0,-1.0,-1.0,1.0} this represents a vertex which is called in glVertex4fv(&cube_vertexes[0][0][0]); how these values in the "ex" are defined??

static float cube_vertexes[6][4][4] =
{
{
{-1.0, -1.0, -1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0}},

{
{1.0, 1.0, 1.0, 1.0},
{1.0, -1.0, 1.0, 1.0},
{1.0, -1.0, -1.0, 1.0},
{1.0, 1.0, -1.0, 1.0}},

{
{-1.0, -1.0, -1.0, 1.0},
{1.0, -1.0, -1.0, 1.0},
{1.0, -1.0, 1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0}},

{
{1.0, 1.0, 1.0, 1.0},
{1.0, 1.0, -1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0}},

{
{-1.0, -1.0, -1.0, 1.0},
{-1.0, 1.0, -1.0, 1.0},
{1.0, 1.0, -1.0, 1.0},
{1.0, -1.0, -1.0, 1.0}},

{
{1.0, 1.0, 1.0, 1.0},
{-1.0, 1.0, 1.0, 1.0},
{-1.0, -1.0, 1.0, 1.0},
{1.0, -1.0, 1.0, 1.0}}
};

Jan
05-21-2010, 07:32 AM
Don't crosspost.

darshan
05-21-2010, 12:11 PM
sorry for the crosspost

mhagain
05-21-2010, 12:17 PM
You're really better off posting these questions in the Beginners forum too, you know.

darshan
05-21-2010, 10:04 PM
what do you mean by posting in the beginners forum??again it ll lead to a cross post

mhagain
05-22-2010, 08:02 AM
I mean instead of posting to advanced in the first place. For this one done is done, but in future you should consider that a questions like this one might get you more meaningful answers in the beginners forum.

ZbuffeR
05-22-2010, 11:30 AM
ex:{-1.0,-1.0,-1.0,1.0}
it is the values for each of the 4 coordinates, in this order : x,y,z,w
See glVertex4?? details here :
http://www.opengl.org/sdk/docs/man/xhtml/glVertex.xml

Now you may ask, x,y,z makes sense for a 3D cube, but what about w ? Why 4 dimensions ?
Short answer : it is not needed for a cube ! By default w is 1.0 for glVertex3??, like all your values by the way.
Long answer : it is useful to represent things "at infinity" by setting w to 0.0 like for horizon, sun, stars, etc. For more math details, read about homogenous coordinates (http://en.wikipedia.org/wiki/Homogeneous_coordinates#Use_in_computer_graphics) and perspective projection (http://en.wikipedia.org/wiki/Transformation_matrix#Perspective_projection).