开发者

Global Rotation

开发者 https://www.devze.com 2023-03-14 13:49 出处:网络
in GLScene we have three parameters (开发者_JAVA百科RollAngle, PitchAngle and TurnAngle) for rotation around local orientation. in the image below, how can I rotate cube around global orientation (ora

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

Global Rotation


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.


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


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.

0

精彩评论

暂无评论...
验证码 换一张
取 消

关注公众号