Random Quotes

You see those who had loved, been loved and in love-likewise: there's SOMEONE out there for EVERYBODY.

Countries

23.6%Philippines Philippines
14.7%United States United States
10.8%Australia Australia
3.5%Germany Germany
3.3%Malaysia Malaysia

Who's Online

We have 2 guests online

Drawing a Cube

Attention: open in a new window. PDFPrintE-mail

Have you ever heard the Cartesian coordinate system? I bet you know it if you took trigonometry class.

Basically, you have x and y axis there, right? And it looks like this.



In 3D world, we now have a new axis, the z axis. It is the depth of a 3D object. Try looking at the picture below and I'm pretty sure you'll get what I mean.



So, drawing a cube will require you to have an 8 vertices.

 
// { X, Y, Z }
float vertices[8][3] = { { 1.0f, 1.0f, 0.0f },    //Vertex 0
                         { 0.0f, 1.0f, 0.0f },    //Vertex 1
                         { 0.0f, 0.0f, 0.0f },    //Vertex 2
                         { 1.0f, 0.0f, 0.0f },    //Vertex 3
                         { 1.0f, 0.0f, 1.0f },    //Vertex 4
                         { 1.0f, 1.0f, 1.0f },    //Vertex 5
                         { 0.0f, 1.0f, 1.0f },    //Vertex 6
                         { 0.0f, 0.0f, 1.0f }};   //Vertex 7 

Then to draw it.

 
//Note: The order of the vertices is very important especially if you're going to use texture mapping. 
Front Face         
Draw(vertices[0], vertices[1], vertices[2], vertices[3]);

Back Face
Draw(vertices[4], vertices[7], vertices[6], vertices[5]);

Right Face
Draw(vertices[0], vertices[3], vertices[4], vertices[5]);

Left Face
Draw(vertices[1],vertices[6],vertices[7], vertices[2]);

Top Face
Draw(vertices[0], vertices[5], vertices[6], vertices[1]);

Bottom Face
Draw(vertices[7], vertices[4], vertices[3], vertices[2]);
 

So that's it! If you have any problems, just post a comment here or try to email me. Good luck.

Comments (0)
Write comment
Your Contact Details:
Comment:
[b] [i] [u] [url] [quote] [code] [img]   
:angry::0:confused::cheer:B):evil::silly::dry::lol::kiss::D:pinch:
:(:shock::X:side::):P:unsure::woohoo::huh::whistle:;):s
:!::?::idea::arrow:
Security
Please input the anti-spam code that you can read in the image.

Login