Rotation Matrix

Started by
2 comments, last by mdias 10 years, 7 months ago

Hi everyone!

I've been using this code for years when setting up my world matrix for my meshes:


D3DXMatrixRotationX( &matRotX, Coords.Rotate.x );
D3DXMatrixRotationY( &matRotY, Coords.Rotate.y ); 
D3DXMatrixRotationZ( &matRotZ, Coords.Rotate.z ); 

D3DXMatrixScaling( &matScale, Coords.Scaling.x, Coords.Scaling.y, Coords.Scaling.z );
 
D3DXMatrixTranslation( &matTrans ,Coords.Position.x, Coords.Position.y, Coords.Position.z );
 
matWorld = ( matScale * matRotX * matRotY * matRotZ ) * matTrans;

d3dDevice->SetTransform( D3DTS_WORLD, &matWorld );

However, my graphics guy has asked if he can have a system where if he rotates on an axis then it's sure to always rotate the same way regardless of other rotations applied.

For example:

If you have a Bike Wheel rotating on the Z Axis then it should still rotate correctly even if I rotate it on the Y Axis too. Currently using the above code it end up rotating the wrong way. I figured this is because of the order they are multiplied together. X then Y and then Z. But I don't just want to force the order the are multiplied for this specific case. How would I make it so that the Z Axis no matter what other rotations are applied will always make it spin the way you'd expect a wheel to spin?

Also, does anyone know if there is a technical term for what I am asking?

I would be grateful for any advice!

Thanks in advance for your time!

David

Advertisement

Can you show an image of what the problem is? It sounds to me like you need to make the wheel have its own local axes (i.e. a node in the scene graph) so that it can be applied independently of what is going on with the bicycle it is attached to. By having separate nodes apply the rotations for their respective objects, then you can strictly control the order of the operations being applied.

You likely want to move away from the idea of creating a transform each time, to storing that transform and applying future transforms to that.

Basically when you want to turn the tire, you get the tire's current transform matrix, grab a vector from it that describes the axis that you want to rotate around, and make an incremental rotation matrix from this axis. then multiply this into your current transform. Look into D3DXMatrixRotationAxisAngle() or what ever it was called in d3dx.

You could have an enum that specifies the order in which the components should be multiplied.

If that doesn't solve the problem (if you want to keep the order and only after that want to rotate along a specific axis) you can still implement an interface that allows the user to specify a "delta matrix" which would be a custom matrix that is applied on top of your generated matrix, however this could be bad for memory and performance.

Maybe you could also try to make a virtual protected internalUpdateMatrix() method that your friend could override for his special case objects.

This topic is closed to new replies.

Advertisement