Local rotation about fixed axis (Picture included)

Started by
8 comments, last by Supernat02 19 years, 7 months ago
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
<-Sweenie->
Advertisement
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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."


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.






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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

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.

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."


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. :)

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

"Ars longa, vita brevis, occasio praeceps, experimentum periculosum, iudicium difficile"

"Life is short, [the] craft long, opportunity fleeting, experiment treacherous, judgement difficult."

Great.
I will try that.

Thanks!
<-Sweenie->
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
Chris ByersMicrosoft DirectX MVP - 2005

This topic is closed to new replies.

Advertisement