Jump to content
  • Advertisement
Sign in to follow this  
39ster

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.

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
Advertisement
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
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 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
Sign in to follow this  

  • Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

We are the game development community.

Whether you are an indie, hobbyist, AAA developer, or just trying to learn, GameDev.net is the place for you to learn, share, and connect with the games industry. Learn more About Us or sign up!

Sign me up!