Sign in to follow this  

Quick question regarding positioning.

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

If you intended to correct an error in the post then please contact us.

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)
  {
    glBegin(GL_QUADS);
      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 this post


Link to post
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 this post


Link to post
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.

Share this post


Link to post
Share on other sites

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

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this