1

This is what I want:

enter image description here

What am I doing wrong with the following code. The output of the translation for the orbit rotation never occurs, it just ends up rotating all on the original axis.

void Renderer::UpdateAsteroid( Placement^ asteroidRotation, Placement^ sceneOrientation )
{
    XMMATRIX selfRotation;

    // Rotate the asteroid
    selfRotation = XMMatrixRotationX( asteroidRotation->GetRotX() );
    selfRotation = XMMatrixMultiply( selfRotation, XMMatrixRotationY( asteroidRotation->GetRotY() ) );  
    selfRotation = XMMatrixMultiply( selfRotation, XMMatrixRotationZ( asteroidRotation->GetRotZ() ) );

    XMMATRIX translation;

    // Move the asteroid to new location
    translation = XMMatrixTranslation( sceneOrientation->GetPosX(), sceneOrientation->GetPosY(), sceneOrientation->GetPosZ() );

    XMMATRIX orbitRotation;

    // Rotate from moved origin
    orbitRotation = XMMatrixRotationZ( sceneOrientation->GetRotZ() );

    XMMATRIX outputMatrix = selfRotation * translation * orbitRotation;

    // Store
    XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose( outputMatrix ) );
}

but it does not seem to work.. it just ends up rotating on the same point.

Jimmyt1988
  • 20,466
  • 41
  • 133
  • 233

1 Answers1

0

Matrix multiplication is not commutative, i.e. changing operands order changes result. Typically you will want to calculate all of your matrces and then multiply together. Try this order first:

result = scale * selfRotation * translation * orbitRotation

If it's not what you want, just move matrices around to find right order.

Note, XMMath also have XMMatrixRotationRollPitchYaw() function to get rotation matrices in one call.

Ivan Aksamentov - Drop
  • 12,860
  • 3
  • 34
  • 61