# Quick question regarding positioning.

This topic is 3971 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

Hey, im new to 3D and would just like to ask what is the "standard" or best method for positioning objects. Do you use glTranslate for every game object you want to draw or is it better or normal to use variable co-ordinates in the glVertex commands like glVertex3f(x + 1, y, z); This is how i do it
//lets just say i want to render a grid of cubes

for(int z = 0; z < 5; ++z)
{
for(int x = 0; x < 5; ++x)
{
glPushMatrix();
glTranslatei(x * 2, 0, z * 2);
drawCube();
glPopMatrix();
}
}

What i mean is, you could also do it like this:
//lets just say i want to render a grid of cubes

for(int y = 0; y < 5; ++y)
{
for(int x = 0; x < 5; ++x)
{
glVertex3f(x - 1.0f, y + 1.0f, 0.0f);
glVertex3f(x - 1.0f, y - 1.0f, 0.0f);
glVertex3f(x + 1.0f, y -1.0f, 0.0f);
glVertex3f(x +1.0f, y +1.0f, 0.0f);
glEnd();
}
}

[Edited by - 39ster on December 3, 2007 2:06:26 AM]

##### Share on other sites
If you really want to make something professional, you should use vertex buffers instead of rendering separate triangles. After you have a buffer ready, you can just use a world matrix to translate rotate and scale the content of the buffer.

##### Share on other sites
I'd likely say the first one. Because once you get anything sizeable rendering, you should be using VBO and the like instead of glVertex calls.

##### Share on other sites
First, the VBO thing is irrelevant, you probably don't even nkow what they are(?)

Second, you use translate and there are 2 reasons:

1, the gpu puts a vertex through a matrix, so if you send it a matrix with the translation in it, then you save in your glvertex call and extra add for each vertex.

2, you use translate because once you apply rotations, your code as of now, will break. Like if you have a 3d camera.

1. 1
2. 2
3. 3
Rutin
22
4. 4
5. 5

• 13
• 19
• 14
• 9
• 9
• ### Forum Statistics

• Total Topics
632935
• Total Posts
3009305
• ### Who's Online (See full list)

There are no registered users currently online

×