Sign in to follow this  

Local rotation about fixed axis (Picture included)

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi. I'm going crazy about a rotationproblem I have. Use the picture below as reference. First I build a rotationmatrix which rotates around Y. If I multiply my current Transformmatrix with the RotMatrix I should get these results. NewTransform = CurrentTransformMatrix * RotMatrix Should produce a rotation about the world center(Red axis in picture) NewTransform = RotMatrix * CurrentTransformMatrix Should produce a rotation about the object center(Green axis in picture) Now, how would I perform a rotation about the Blue Axis?(See picture) I'm using D3DX Matrices. [Edit] Could I possibly translate the cube to the worldcenter, perform a rotation around the world center and then translate it back? If this is correct, maybe someone could provide a little codesnippet? Cause I'm not quite sure how to do that. //Sweenie

Share this post


Link to post
Share on other sites
Not gonna help that much with the code because you'll be able to figure it out v.easy once you start...and it's good practice! [grin]

what you're looking for is to:
R1 = rotate box around blue axis
T1 = translate box to distance from red axis
R2 = rotate box around red axis

R1 produces you're boxes local rotation(s), T1 positions it ready for R2 to make it orbit around the red axis...is that what you want?

if it is you can create those matrices using the D3DXMatrix functions quite easily and multiply them together in that order (in OpenGL it'd be reverse order i believe) and you should have what you're looking for...

...i think, im at work and i just hammered this out but it should be correct [smile]

Andy

Share this post


Link to post
Share on other sites
Guest Anonymous Poster

Um, Consider the picture.

The green axis shows the cubes current Y-Axis after I have turned the cube 45 degrees on it's local X-axis.
The cube has also translated a couple of units on the worlds Z-axis.

All I have now is the cube's Tranformation Matrix, no angle/rotation variables or x,y,z position variables.

Now I want to turn the cube 30 degrees around the blue axis(which is the absolute Y-axis in the world) using only it's current Transformationmatrix as reference.






Share this post


Link to post
Share on other sites
So you need to construct a matrix which translates to the origin, rotates, and translates back (which you've already considered)... but without any of the information you used to put it there...

I think (<--fear this statement) you could get the current matrices inverse to get the cube back to the origin then multiply it by the rotation matrix and again by the original transformation matrix.

but that doesnt sounds very elegant does it? I'm sure there must be a better way.

You sound like you know at least as well as i do what you're on about but this page is quite helpful if you need to be able to find the inverse of the transformation matrix you've got. Vector and Matrix Primer.

Good luck dude [grin]

Andy

Share this post


Link to post
Share on other sites

I'm not doing the transformations in one go.
For example the Z-translation is done when pressing the Up & Down arrows.
The local x-rotation is done when pressing some other keys.
And the global y-rotation (around objects origin) is done when pressing yet some more keys.

I think the solution might be to transform the rotationvector from world space into the objects local space.
Then turn the object locally using the transformed vectors.

Worth a try at least.

Anyway, thanks for discussing this with me Andy. :)

Share this post


Link to post
Share on other sites
Another solution would be to keep track of the angles instead of the transformations. Then complete them all in one shot. One rotation that you aren't showing is the one one around the red axis in your picture when the object is at rest at position (0,0,0). It's the rotation that causes problems when you want to rotate the model around the blue axis. I'll call it RotModelZ. RotModelY is the one around the blue bar that you have drawn. RotWorldY is the one around the Red bar that you have drawn.

// Calculate your transforms here in one place using the angles and position you have been keeping track of.
// Then multiply them.
NewTransform = RotModelY*RotModelZ*Translation*RotWorldY.

First you rotate around the Y axis with an unmodified model. Then you take that model and rotate around the Z axis of the model, turning it into some odd orientation. Now you translate it out to its new position and finally rotate it around the world axis. I hope this works, I haven't tried it. Feel free to let me know if I screwed something up.

Good luck,
Chris

Share this post


Link to post
Share on other sites

This topic is 4838 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this