Draw Matrix or Grid in 3D

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

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-

I want to draw a grid in 3D. Can the example make that?

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.

Can you give me an example?

Nemesis code will work fine. You could set the z values to zero and then translate and rotate the grid into place.

Old GLman

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

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)(i10), 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&lt;numCols+1; i++)
	{
		glVertex3f((float)(i*10), 0, 0);
		glVertex3f((float)(i*10), numCols*10, 0);

	}
glEnd();
glEndList();

glNewList(3, GL_COMPILE); //Board
glBegin(GL_QUADS);
glVertex3f(0, 0, 10);
glVertex3f(numRows10, 0, 0);
glVertex3f(numRows
10, numCols10, 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).]

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-

I already have this and it works, but know I want that the table have the aspect, like for example, a box.