# Local rotation about fixed axis (Picture included)

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

## 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.  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 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 on other sites

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 on other sites
Hmm, the post above was from me.The session must have timedout or something.

##### 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 on other sites
PS: why can't you do the rotation about the blue-axis before you've built the transformation matrix?
Then you wouldn't have to mess around with the rest of this stuff.

##### 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 on other sites
S'ok glad to help if i can [smile]

By the way i worked it out then confirmed it with a colleague here, getting the inverse should work perfectly.

Andy

Great.
I will try that.

Thanks!

##### 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

1. 1
Rutin
41
2. 2
3. 3
4. 4
5. 5

• 16
• 18
• 12
• 14
• 9
• ### Forum Statistics

• Total Topics
633360
• Total Posts
3011524
• ### Who's Online (See full list)

There are no registered users currently online

×