Results 1 to 8 of 8

Thread: object translation

  1. #1
    Junior Member Newbie
    Join Date
    May 2005
    Posts
    22

    object translation

    Hi...
    in addition to some of the problems I mentioned before, some have just come up to this bottom line: centering an object at the origin. What are some techniques I could use to attain that goal? I appreciate your effort.
    Thanks,
    -TS...

  2. #2
    Senior Member Regular Contributor
    Join Date
    Mar 2005
    Posts
    115

    Re: object translation

    You can find the position of your object then translate it to the negative of the position you found.

    example: object.x=5, object.y=1, object.z=0;
    glTranslatef(-object.x, -object.y, -object.z);

    this will place the object at 0,0,0

  3. #3
    Junior Member Newbie
    Join Date
    May 2005
    Posts
    22

    Re: object translation

    Thank you...
    This doesn't seem to work for the perspective view... :\

  4. #4
    Senior Member Regular Contributor
    Join Date
    Sep 2002
    Location
    Dresden, Sachsen, Germany
    Posts
    203

    Re: object translation

    find the center of your object and

    glTranslatef( - center_object.x, -center_object.y, -center_object.z)

  5. #5
    Senior Member Frequent Contributor ehsan2004's Avatar
    Join Date
    Jun 2004
    Location
    Iran
    Posts
    645

    Re: object translation

    Originally posted by ThunderSoul:
    [qb]Thank you...
    This doesn't seem to work for the perspective view... :\
    The modelview matrix is independent of the projection matrix. When you do a translation, the coordinate system goes to the new position regardless of the current projection definitions.Then the projection matrix is applied to clip the objects.Maybe you are clipping the center of your coordinate system.
    -Ehsan-

  6. #6
    Senior Member Frequent Contributor ehsan2004's Avatar
    Join Date
    Jun 2004
    Location
    Iran
    Posts
    645

    Re: object translation

    I should complete my previous post.In perspective mode, we should adjust the znear plane to the value that is greater than 0. As the camera position has been inserted in the point(0,0,0), so we clip this point in the perspective mode. So if you move your object to the point (0,0,0), part of it cannot be seen.
    -Ehsan-

  7. #7
    Senior Member Frequent Contributor ehsan2004's Avatar
    Join Date
    Jun 2004
    Location
    Iran
    Posts
    645

    Re: object translation

    Another issue is about the meaning of the *center*. 1.default center or 2.the center of the current cordinate system? Obviouslym when you transform the current coordinate system, objects that are drawn after this transformation, use from the new coordinate system.Assum that what does happen when you use from the glVertex*(center_x,center_y,center_z) to draw that object. In this case if we use from the this formula: glTranslatef(-center_x,-center_y,-center_z) we are moving the object to the center of the *transformed* coordinate system. So the rule that i said in the previous reply about the clipping isn't correct. But if you mean the *DEFAULT* (0,0,0)positon, the previous rule about the clipping is correct.
    Actually if you want to move the object to the *default* center of the world coordinate system, you should consider all the transformations--Remember that the scaling transformation changes the units
    -Ehsan-

  8. #8
    Junior Member Newbie
    Join Date
    May 2005
    Posts
    22

    Re: object translation

    Thank you very much for your replies... It helped me with my work.
    Thank you,
    -TS...

Similar Threads

  1. 3D Object translation and resize
    By Vincent22 in forum OpenGL: Basic Coding
    Replies: 0
    Last Post: 04-26-2012, 02:44 PM
  2. picking 2D object (with rotation, translation)
    By codetale in forum OpenGL: General
    Replies: 1
    Last Post: 08-13-2010, 06:17 AM
  3. object translation and rotation around local coordinates
    By moogoo in forum OpenGL: Basic Coding
    Replies: 3
    Last Post: 04-11-2004, 02:27 PM
  4. Doing your own translation
    By howie in forum OpenGL: Basic Coding
    Replies: 4
    Last Post: 01-12-2004, 01:29 PM
  5. Determing translation parameters for object
    By imported_korin in forum OpenGL: Basic Coding
    Replies: 1
    Last Post: 08-09-2000, 01:45 AM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Proudly hosted by Digital Ocean