PDA

View Full Version : Draw Matrix or Grid in 3D

GLman
05-28-2002, 12:57 AM
That's it, how can I draw a grid in 3D? And draw that grid in way that does not occupy entire window.

Thanks
ruca
http://www.opengl.org/discussion_boards/ubb/wink.gif

nemesis
05-28-2002, 03:03 AM
hello!

I believe you can do something similar to:

glBegin(GL_LINES);

// Vertical lines
for (int w = 0; w < maxW; w = w + offset){
glVertex3f(x+w, y, z);
glVertex3f(x+w+offset, y, z);
}
// Horitzontal lines
for (int h = 0; h < maxH; h = h + offset){
glVertex3f(x, y+h, z);
glVertex3f(x, y+h+offset, z);
}

glEnd();

Hope it helps.
-nemesis-

GLman
05-28-2002, 03:09 AM
I want to draw a grid in 3D. Can the example make that?

GiMiC
05-28-2002, 04:20 AM
Just modify the above code so that you use the z axis as well. You'll probably need to nest the two for loops inside another one, that controls the z-axis.

GLman
05-28-2002, 05:41 AM
Can you give me an example?

Old GLman
05-28-2002, 10:37 AM
Nemesis code will work fine. You could set the z values to zero and then translate and rotate the grid into place.

Old GLman

GLman
06-04-2002, 01:04 AM
I don't understand very well what Old GLMan says. Can you explain me better?

I want to rotate and my table stays at same place but with other view.

Thanks

GLman
06-04-2002, 04:39 AM
glNewList(1, GL_COMPILE); //Board matrix (Horizontal Lines)
glBegin(GL_LINES);
glColor3f(1, 1, 1);
for (i=0; i<numRows+1; i++)
{
glVertex3f(0, (float)(i*10), 0);
glVertex3f(numRows*10, (float)(i*10), 0);
}
glEnd();
glEndList();

glNewList(2, GL_COMPILE); //Board matrix (Vertical Lines)
glBegin(GL_LINES);
glColor3f(1, 1, 1);
for (i=0; i<numCols+1; i++)
{
glVertex3f((float)(i*10), 0, 0);
glVertex3f((float)(i*10), numCols*10, 0);

}
glEnd();
glEndList();

glNewList(3, GL_COMPILE); //Board
glVertex3f(0, 0, 10);
glVertex3f(numRows*10, 0, 0);
glVertex3f(numRows*10, numCols*10, 0);
glVertex3f(0, numCols*10, 0);
glEnd();
glEndList();

How can I draw this in 3D???

[This message has been edited by GLman (edited 06-04-2002).]

[This message has been edited by GLman (edited 06-04-2002).]

nemesis
06-04-2002, 08:06 AM
This code will draw a grid in 3D but placed in z=0.
What Old GLman meant is:

glPushMatrix();
glTranslatef(x, y, z); // Where you want to place (translate) the grid
glRotatef(x_angle, 1, 0, 0); // If you want it to be rotated in X
glRotatef(y_angle, 0, 1, 0); // If you want it to be rotated in Y
glRotatef(z_angle, 0, 0, 1); // If you want it to be rotated in Z

// CODE HERE

glPopMatrix();

-nemesis-

GLman
06-04-2002, 08:21 AM
I already have this and it works, but know I want that the table have the aspect, like for example, a box.