1
\$\begingroup\$

So after almost two hours, I got the hang of using glTranslated() (with Java and LWJGL). If I am correct, applying glTranslated on an object moves that object with the x,y,z relative to the previously moved object. I believe the correct term for this is local vs global, global being the one I want. I was wondering if there was a way to translate an object to a specific XYZ position, or relative to the origin. Thanks!

(Code or other details can be supplied if it helps, just let me know. Also sorry if this is a noob comment, Im very new to OpenGL.)

\$\endgroup\$
2
  • \$\begingroup\$ If this question makes no sense, it could be that I am going at this completely wrong and I made a logic error somewhere... If that's the case, please let me know. :) \$\endgroup\$
    – MichaelK
    Nov 18, 2012 at 12:37
  • 1
    \$\begingroup\$ Are you familiar with matrix-math and -multiplication? That is what is going on behind the scenes when you call glTranslate/glRotate etc. \$\endgroup\$ Nov 18, 2012 at 13:14

3 Answers 3

1
\$\begingroup\$

Thanks for everyone's help. However, I found what I was looking for, and that was

GL11.glPushMatrix();
drawCube(x, y, z); //parameters for the glTranslated();
GL11.glPopMatrix();

Thanks again!

\$\endgroup\$
1
  • \$\begingroup\$ haha.. that's why you had to show some code for us to make sense. glad your problem is solved. \$\endgroup\$
    – Jake
    Nov 19, 2012 at 1:28
0
\$\begingroup\$

Since you brought up the concept of local and global coordinates, then you should also indicate where the origin is.

The steps to move the object to a specific XYZ relative to the origin of a specific space is as such:

  1. find out the object position in the target space coordinate or;
  2. find out the target position in the object space coordinate
  3. glTranslate() by the displacement vector in the same coordinate space as per Ken's method

In a professional set up, objects are usually in a hierarchical manner e.g. in an oct-tree; in scene graph; in skeletal animation etc, then you may need to use a recursive function to compute the object position from the object space up its parent space / nodes until you reach the target space where your origin is located.

\$\endgroup\$
1
  • \$\begingroup\$ Thank you for your reply, I was able to solve my problem. :) \$\endgroup\$
    – MichaelK
    Nov 18, 2012 at 21:56
0
\$\begingroup\$

To move an object from it current position to some other specific position you need to translate by a displacement vector. The displacement vector will be the difference between the desired position and current position.

glTranslatef(desired.x-current.x,desired.y-current.y, desired.z-current.z);
\$\endgroup\$
0

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .