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:
glLoadIdentity();
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
Quote this message in a reply
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
Quote this message in a reply
Post Reply 

Possibly Related Threads...
Thread: Author Replies: Views: Last Post
  Cube auto-rotate sakrist 2 3,067 May 5, 2009 03:31 AM
Last Post: Ingemar
  How does one rotate a scanned image in openGL? WhatMeWorry 16 8,681 Feb 2, 2005 09:25 PM
Last Post: arekkusu
  Focus on SDL Nick 13 5,808 Jul 22, 2004 07:30 PM
Last Post: Nick
  Best way to rotate an object Jake 12 4,455 Jul 30, 2003 01:09 PM
Last Post: Jake
  Move and Rotate camera SummerLand 2 3,316 Nov 25, 2002 10:53 PM
Last Post: Feanor