Take the 2-minute tour ×
Game Development Stack Exchange is a question and answer site for professional and independent game developers. It's 100% free, no registration required.

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.)

share|improve this question
    
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. :) –  Aliasmk Nov 18 '12 at 12:37
1  
Are you familiar with matrix-math and -multiplication? That is what is going on behind the scenes when you call glTranslate/glRotate etc. –  Maik Semder Nov 18 '12 at 13:14

3 Answers 3

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!

share|improve this answer
    
haha.. that's why you had to show some code for us to make sense. glad your problem is solved. –  Jake Nov 19 '12 at 1:28

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);
share|improve this answer
    
Thanks for the explanation :) –  Aliasmk Nov 18 '12 at 21:59

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.

share|improve this answer
    
Thank you for your reply, I was able to solve my problem. :) –  Aliasmk Nov 18 '12 at 21:56

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.