View Full Version : object translation
06-07-2005, 10:03 PM
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. :)
06-07-2005, 10:07 PM
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
06-08-2005, 02:55 PM
This doesn't seem to work for the perspective view... :\
06-08-2005, 03:28 PM
find the center of your object and
glTranslatef( - center_object.x, -center_object.y, -center_object.z)
06-08-2005, 04:44 PM
Originally posted by ThunderSoul:
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.
06-08-2005, 07:04 PM
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.
06-08-2005, 07:23 PM
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
06-08-2005, 09:39 PM
Thank you very much for your replies... It helped me with my work. :)
Powered by vBulletin® Version 4.2.3 Copyright © 2017 vBulletin Solutions, Inc. All rights reserved.