• Create Account

Need scary sound effects or creepy audio loops for your next horror-themed game? Check out Highscore Vol.3 - The Horror Edition in our marketplace. 50 sounds and 10 loops for only \$9.99!

# Rotation Matrix

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

3 replies to this topic

### #1thekiwimaddog  Members   -  Reputation: 154

Like
1Likes
Like

Posted 03 September 2013 - 11:44 AM

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!

David

Edited by thekiwimaddog, 03 September 2013 - 11:45 AM.

### #2Jason Z  Crossbones+   -  Reputation: 3278

Like
0Likes
Like

Posted 03 September 2013 - 07:10 PM

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.

Jason Zink :: DirectX MVP

Direct3D 11 engine on CodePlex: Hieroglyph 3

Games: Lunar Rift

### #3Burnt_Fyr  Members   -  Reputation: 785

Like
0Likes
Like

Posted 03 September 2013 - 07:16 PM

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.

### #4mdias  Members   -  Reputation: 699

Like
0Likes
Like

Posted 03 September 2013 - 08:03 PM

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.

Old topic!
Guest, the last post of this topic is over 60 days old and at this point you may not reply in this topic. If you wish to continue this conversation start a new topic.

PARTNERS