Skip to main content
GameDev.net gamedev.net
🔒 Locked

Cube

Started by NighTiger Oct 27, 2005 at 4:24 PM 3 replies 700+ views
Original Post
NighTiger
NighTiger
Hi guys, I would like to make a little valley. I did think to make a big cube and put my camera into it. But how can I store my cube data and in the future other vertex data? tnx
taby
taby
You can store coordinates and whatnot in a static or dynamically sized array of floats, and then pass them into the OpenGL API functions instead of literal values like in the source examples below.

First, you should find a way to be able to draw a cube in your mind or on paper using lines. Don't proceed until you can do this.

You can start by tracing it out using OpenGL line primitives into cartesian space.

glBegin(GL_LINES);glColor3f(1.0, 1.0, 1.0); // draw white line:glVertex3f(-0.5, -0.5, 0.5); // from left, bottom, front cornerglVertex3f(-0.5, 0.5, 0.5); // to left, top, front corner// draw 11 more linesglEnd();



Another way is to trace that out into cartesian space using OpenGL quad primitives. Keep in mind that vertex placement should be in counter-clockwise order to define the front face. I also assume that you want your cube's quad front facing in toward the centre of the cube.

glBegin(GL_QUADS);// draw -x side planeglColor3f(1.0, 1.0, 1.0); // draw white quad:glVertex3f(-0.5, -0.5, -0.5); // from left, bottom, back cornerglVertex3f(-0.5, 0.5, -0.5); // from left, top, back cornerglVertex3f(-0.5, -0.5, 0.5); // from left, bottom, front cornerglVertex3f(-0.5, 0.5, 0.5); // from left, top, front corner// draw 5 more quad facesglEnd();



A vertex class could be as simple as:

class vertex4f{public:	// colour variables	float r, g, b, a;	// texture coordinate variables	float u, v;	// position variables	float x, y, z;};// ... // allocate memory for an array of 50000 elements through the use of a pointersize_t vertex_array_size = 50000;vertex4f *vertex_array = new vertex4f[vertex_array_size];// set red intensity member variable of the 1st vertex4f element in the arrayvertex_array[0].r = 1.0f;// deallocate memory used by arraydelete [] vertex_array;


[Edited by - taby on October 27, 2005 4:28:32 PM]
taby
taby
Sky map I bet.
NighTiger
NighTiger
I don't find anything about skymap in dx9...
anyhelp?
tnx

Topic Locked

This topic has been locked by a moderator. New replies are not allowed.

Sign in to reply to this topic.