3D Cube

Started by
6 comments, last by NineYearCycle 15 years, 9 months ago
Hi, I am trying to define a 3D cube. Is this correct? glVertex3f(-1,1,0); glVertex3f(1,1,0); glVertex3f(1,-1,0); glVertex3f(-1,-1,0); glVertex3f(0,0,-1); glVertex3f(0,0,1); Thanks
Advertisement
A 3D Cube has 8 Vertices last time I checked.
------------Anything prior to 9am should be illegal.
How the vertices will be interpreted depends on what you pass to glBegin(), but either way your code will not define a cube. See here for more info.
Quote:Original post by mbanghart
Hi,

I am trying to define a 3D cube. Is this correct?

glVertex3f(-1,1,0);
glVertex3f(1,1,0);
glVertex3f(1,-1,0);
glVertex3f(-1,-1,0);
glVertex3f(0,0,-1);
glVertex3f(0,0,1);

Thanks


Where are the glBegin and glEnd calls?
Sig: http://glhlib.sourceforge.net
an open source GLU replacement library. Much more modern than GLU.
float matrix[16], inverse_matrix[16];
glhLoadIdentityf2(matrix);
glhTranslatef2(matrix, 0.0, 0.0, 5.0);
glhRotateAboutXf2(matrix, angleInRadians);
glhScalef2(matrix, 1.0, 1.0, -1.0);
glhQuickInvertMatrixf2(matrix, inverse_matrix);
glUniformMatrix4fv(uniformLocation1, 1, FALSE, matrix);
glUniformMatrix4fv(uniformLocation2, 1, FALSE, inverse_matrix);
GL_Polygon
First off don't use GL_POLYGON ever, and you need glBegin() and glEnd() when you draw polygons in immediate mode.

glBegin(GL_QUADS);glColor3f(0.0f,1.0f,0.0f);glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Top)glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Top)glVertex3f(-1.0f, 1.0f, 1.0f);			// Bottom Left Of The Quad (Top)glVertex3f( 1.0f, 1.0f, 1.0f);			// Bottom Right Of The Quad (Top)glColor3f(1.0f,0.5f,0.0f);			// Set The Color To OrangeglVertex3f( 1.0f,-1.0f, 1.0f);			// Top Right Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f, 1.0f);			// Top Left Of The Quad (Bottom)glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Bottom)glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Bottom)glColor3f(1.0f,0.0f,0.0f);			// Set The Color To RedglVertex3f( 1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Front)glVertex3f(-1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Front)glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Front)glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Front)glColor3f(1.0f,1.0f,0.0f);			// Set The Color To YellowglVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Back)glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Back)glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Back)glVertex3f( 1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Back)glColor3f(0.0f,0.0f,1.0f);			// Set The Color To BlueglVertex3f(-1.0f, 1.0f, 1.0f);			// Top Right Of The Quad (Left)glVertex3f(-1.0f, 1.0f,-1.0f);			// Top Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f,-1.0f);			// Bottom Left Of The Quad (Left)glVertex3f(-1.0f,-1.0f, 1.0f);			// Bottom Right Of The Quad (Left)glColor3f(1.0f,0.0f,1.0f);			// Set The Color To VioletglVertex3f( 1.0f, 1.0f,-1.0f);			// Top Right Of The Quad (Right)glVertex3f( 1.0f, 1.0f, 1.0f);			// Top Left Of The Quad (Right)		glVertex3f( 1.0f,-1.0f, 1.0f);			// Bottom Left Of The Quad (Right)glVertex3f( 1.0f,-1.0f,-1.0f);			// Bottom Right Of The Quad (Right)glEnd();						// Done Drawing The Quad


there look through that, and check out the beautiful colored cube.
Thanks. But this is for a school project and I have to use polygons. The cube is being displayed 2D (and I have to use 6 vertices) and my input data is 3D.
Quote:Original post by mbanghart
Thanks. But this is for a school project and I have to use polygons. The cube is being displayed 2D (and I have to use 6 vertices) and my input data is 3D.


Triangles and Quads are Polygons. Polygon just means a "many-sides" ;)

Secondly it's impossible to have a "cube" in 3D with only 6 vertices. Think about it, or better yet pick up a box and count the number of corners, there are 8. Any less than 8 and you cannot have a cube.

It is possible to represent something that looks like a cube using 6 projected vertices (since 2 will always be culled as they will be back-facing) but I don't think thats what your homework means.

Andy

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

This topic is closed to new replies.

Advertisement