Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Global Rotation

in GLScene we have three parameters (RollAngle, PitchAngle and TurnAngle) for rotation around local orientation. in the image below, how can I rotate cube around global orientation (orange axis)?

enter image description here

like image 775
Ata Avatar asked Jun 22 '11 16:06

Ata


3 Answers

You would need to convert the axis angle rotation to Euler angles. Here is a link explaining this process in some detail with code:
http://www.euclideanspace.com/maths/geometry/rotations/conversions/angleToEuler/index.htm

From the article:

yaw   = atan2(y * sin(angle)- x * z * (1 - cos(angle)) 
                , 1 - (y2 + z2 ) * (1 - cos(angle)))   

pitch = asin(x * y * (1 - cos(angle)) + z * sin(angle))   

roll  = atan2(x * sin(angle)-y * z * (1 - cos(angle)) 
             , 1 - (x2 + z2) * (1 - cos(angle)))

EDIT: Renamed the variables to be consistent with the pitch, yaw, roll naming convention.

like image 55
Mikola Avatar answered Sep 25 '22 19:09

Mikola


Maybe you could use "DummyCube" object as a parent. Then you can rotate first the cube inside dummy cube and then the DummyCube.

like image 37
Harriv Avatar answered Sep 25 '22 19:09

Harriv


This is a dirty cheat, but if the object is at the origin (0,0,0) and there is only one object in the scene, you could swing the camera (and light source) around the object instead of rotating the object.

like image 35
dthorpe Avatar answered Sep 22 '22 19:09

dthorpe