## rotate to focus on objects

szgezu
Unregistered

Post: #1
Hi All,
With the great help of you I have managed to select objects in the 3d enviroment. I would like to rotate the whole thing into a position where the selected object is rotated to the nearest position to the viewer (would be in the middle of the screen). The problem is that the idea I used seems to be not working. Better say it works, but do not serves the expected values. Somebody may help me to find the bug in the idea?

Thanks a lot!

--------------------------------
This is the code where I try to calculate the needed rotations: (X,Y,Z are the coordinates of the object I would like to rotate to get into "focus")
atan2 gives back tha arc tangent of y/x; the multiplication with 57,... is the conversion from radian to degrees. The additions in the begining is not sure that correct of course.
\$room_rotY=270-57.295779579*atan2(\$Z,\$X);
\$room_rotX=180-57.295779579*atan2(\$Y,\$Z);
\$room_rotZ=57.295779579*atan2(\$X,\$Y);

this would be the code where make the rotation:
glTranslated(0, 0, -200); #to move the screen a little bit farer to see everything

glRotated(\$room_rotY, 0, 1, 0);
glRotated(\$room_rotX, 1, 0, 0);
glRotated(\$room_rotZ, 0, 0, 1);

glCallList(\$objects); #to draw the objects on the window
Apprentice
Posts: 17
Joined: 2006.02
Post: #2
ThemsAllTook has a good tutorial on rotations in 3D space:
http://www.sacredsoftware.net/tutorials/...ions.xhtml