7

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

Ata
  • 253
  • 1
  • 5
  • 13
  • 3
    With a screenshot like this you leave me no choice but to upvote the question :) – Wouter van Nifterick Jun 22 '11 at 16:24
  • `@Wouter van Nifterick` sorry, I don't understand you, what do you mean? – Ata Jun 22 '11 at 16:36
  • What is GLScene? Normally I'd say simply do glRotatef(angle, rot_axis.x, rot_axis.y, rot_axis.z), or some equivalent transformation. – datenwolf Jun 22 '11 at 16:42
  • Your question is not clear. You don't rotate about a direction. You rotate about a point, in a particular direction. And you haven't specified what conventions you use for Euler angles, although perhaps that's implicit in GLScene. – David Heffernan Jun 22 '11 at 18:10
  • Yes, You are right, I modified picture. please check it. – Ata Jun 22 '11 at 18:47

3 Answers3

7

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.

Mikola
  • 8,569
  • 1
  • 31
  • 41
  • @ Mikola, I checked your suggested website. I think the below code is what you mean: `heading = atan2(y * sin(angle)- x * z * (1 - cos(angle)) , 1 - (y2 + z2 ) * (1 - cos(angle)))` --- `attitude = asin(x * y * (1 - cos(angle)) + z * sin(angle))`--- `bank = atan2(x * sin(angle)-y * z * (1 - cos(angle)) , 1 - (x2 + z2) * (1 - cos(angle)))` – Ata Jun 22 '11 at 19:04
  • 1
    @Ata: There is an explanation on the website. The full derivation is somewhat involved, but fairly straightforward if you know your trig. What this code will do is take an axis angle represented by (x, y, z, angle) and convert it to Euler angles, http://www.euclideanspace.com/maths/geometry/rotations/euler/index.htm – Mikola Jun 22 '11 at 19:24
  • 1
    @Mikola, 1. what are x,y and z? what should I attribute to these variables? 2. is "angle" that angle which I want to rotate around the global orientation? – Ata Jun 22 '11 at 20:03
  • 1
    Think of them as the `components' of your axis of rotation along the yaw, pitch and turn directions. The angle is the amount that you rotate about that axis. All of this is discussed on that second website I linked to, or you can also read more on wikipedia: http://en.wikipedia.org/wiki/Rotation_representation_(mathematics) – Mikola Jun 22 '11 at 23:16
3

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

Harriv
  • 5,877
  • 6
  • 40
  • 73
1

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.

dthorpe
  • 33,791
  • 3
  • 72
  • 118
  • As far as I know, we should use some conversion between local orientation and global orientation. Yes, you are right. but I want to know how I can use mathematical algorithm in order to rotate object around global orientation. I think I should use Euler angles. but how... – Ata Jun 22 '11 at 18:57