Rotation around two axis
hi
what would the best way to go about rotating an object around two origins, ie rotating in the y-axis around the centre of the object and rotating in the x-axis around one corner of the object, for example. The only way i can see to do it is by
Matrix.CreateTranslation(offset1) *
CreateRotationY(rotY) *
Matrix.CreateTranslation(-offset1) *
Matrix.CreateTranslation(offset2) *
CreateRotationX(rotX) *
Matrix.CreateTranslation(-offset2)
which seems awfully clumsy so i was just wondering if there was a more optimized way of doing it that any of you know?
the other problem is that say i want to rotate in the y-axis around the center but when i press a certain button i want it to rotate in the same axis but this time around the corner... ive tried by just changing the value of 'offset' when i press the button but the model jumps so the point of rotation is always in the same world space. any ideas on how to prevent this?
oh and by the way im using c# and xna but the question is quite general so just some pseudo-code in any language would be much appreciated.
thanks.
In principal, that is exactly the way to go. It isn't clumsy but a normal composition of transformation matrices.
For the general case there is only a small optimization possible:
Matrix.CreateTranslation(-offset1) * Matrix.CreateTranslation(offset2) == Matrix.CreateTranslation(offset2-offset1)
For the general case there is only a small optimization possible:
Matrix.CreateTranslation(-offset1) * Matrix.CreateTranslation(offset2) == Matrix.CreateTranslation(offset2-offset1)
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement