Re: Rotating Mesh around X,Y,Z



using quaternions is the typical approach to avoiding the gimbal lock
phenomenon that shows when using Euler angles.

a google search should be helpful.

"Jaret Brower" <browerjs@xxxxxxxxxxxxx> wrote in message
news:531F5343-E81F-47BB-BFC8-92BEC17F84C5@xxxxxxxxxxxxxxxx
>I think I need to rephrase slightly. What I want to do is rotate a mesh
> around all 3 axis at the same time. For example I first move my mesh
> 45deg
> around X, now I want to move it 20deg around Y (while keeping the X
> rotation), and then rotate around the Z 30deg, keeping the previous X and
> Y
> rotations.
>
> Depending on how i do my movements it some times works properly doing:
>
> device.Transform.World = RotateX(xangle)*RotateY(yangle)*RotateZ(zangle);
> or
> device.Transform.World = RotateYawPitchRoll(yangle,xangle,zangle);
>
> but I believe gimble lock is occurring when i do either of this methods,
> because eventually, when i rotate around the Z, it's actually rotating
> around
> the Y. Any more thoughts?
>
> "Rhett Gong [MSFT]" wrote:
>
>> We have a tutorial code in DX SDK which illustrate how to rotate a mesh
>> around Y axis. And you can find it under "Microsoft DirectX 9.0 SDK
>> (April
>> 2005)\Samples\Managed\Direct3D\Tutorials\Tutorial6" if you installed
>> DX9.0
>> sdk april 2005.
>> To make a test, you can change line 111 to:
>> device.Transform.World = Matrix.RotationX(Environment.TickCount/1000.0f);
>> or
>> device.Transform.World = Matrix.RotationZ(Environment.TickCount/1000.0f);
>> to make the mesh rotated around x or z axis.
>>
>> Basically, we use 3 matrix to rotate the mesh around x,y or z axis. For
>> more details on the transform matrix, you can reference following doc:
>> http://msdn.microsoft.com/archive/default.asp?url=/archive/en-us/directx9_c_
>> Summer_04/directx/graphics/programmingguide/FixedFunction/Transforms/matrice
>> s/rotation.asp
>>
>> I noticed you are using (1,0,0,XAngle) for the Quaternion rotation.
>> Describe (1,0,0,XAngle) as a matrix, it is:
>> | 1 0 0 0 |
>> | 0 -1 -2XAngle 0 |
>> | 0 2XAngle -1 0 |
>> | 0 0 0 1 |
>> That why you get the mesh looked bigger and bigger. When given a rotation
>> axis, you need to transform it to a quaternion with following formula:
>> q.x = sin(theta/2) * axis.x
>> q.y = sin(theta/2) * axis.y
>> q.z = sin(theta/2) * axis.z
>> q.w = cos(theta/2)
>>
>> Please let me know if my answer helps you resolve the problem. If there
>> is
>> anything more I can assist you, please feel free to let me know.
>>
>> Thanks,
>> Rhett Gong [MSFT]
>> Microsoft Online Partner Support
>> Get Secure! - www.microsoft.com/security
>> http://support.microsoft.com/default.aspx?scid=/servicedesks/msdn/nospam.asp
>> &SD=msdn
>>
>> This posting is provided "AS IS" with no warranties and confers no
>> rights.
>>
>>


.



Relevant Pages

  • Re: newbie: rotating meshes
    ... The problems I noticed, were if you for example rolled the ship, then tried ... not the rolled x axis, which says to me that the math for matrix ... concatenation doesnt rotate the values of the matrix correctly is some ... which meant the y roation rotated the models x axis whereas the z rotation ...
    (microsoft.public.win32.programmer.directx.graphics)
  • RE: Rotating Mesh around X,Y,Z
    ... For example I first move my mesh 45deg ... rotation), and then rotate around the Z 30deg, keeping the previous X and Y ... > to make the mesh rotated around x or z axis. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Object rotation
    ... > need to translate back to the origin first, then rotate, then translate to ... For example rotations are ALWAYS around an axis so if you ... then moves on the new x axis after the Z rotation. ...
    (microsoft.public.win32.programmer.directx.managed)
  • Rotating Mesh around X,Y,Z
    ... Basically what I'm trying to do is display a mesh and rotate it around the ... X, Y, and Z axis. ... To do my rotation i catch mouse movement with a button down, ...
    (microsoft.public.win32.programmer.directx.managed)
  • Re: Accelerometer + Tilt compensation
    ... motion in one direction will affect the other (due to rotation). ... so I can't just "rotate y axis to y ... Use the equations given above to solve for the angle ...
    (sci.electronics.design)

Loading