سؤال

I have drawn a cube onto the screen and I want to both rotate and translate the scene:

// Translation
XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose( XMMatrixTranslation( placement->GetPosX(), placement->GetPosY(), placement->GetPosZ() ) ) );

// Rotation
XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationX( placement->GetRotX() ) ) );
XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationY( placement->GetRotY() ) ) );
XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose(XMMatrixRotationZ( placement->GetRotZ() ) ) );

the problem is, only the translation is working... Do I have to set something somehow before doing the rotations too.

  • I have used the default Windows 8 Phone Direct3D C++ Project in Visual Studio 2012 Windows Phone.
  • I have passed in a few more variables and thanks to intellisense, found out there was a matrixtransaltion function
  • I added my positioning to this matrix and also hooked up the rotation to some custom variables too
  • The cube will move (translate) but I am guessing I need to save this movement somehow and THEN do the rotation.

Anything I can add to this to help solve the issue?

هل كانت مفيدة؟

المحلول

You are overwriting the contents of m_constantBufferData.model every time. You need to call XMMatrixMultiply on the four matrices to combine the transformations into a single matrix, then store the final result. For example:

// Rotation
XMMATRIX m = XMMatrixRotationX( placement->GetRotX() );
m = XMMatrixMultiply(m, XMMatrixRotationY( placement->GetRotY() );
m = XMMatrixMultiply(m, XMMatrixRotationZ( placement->GetRotZ() );

// Translation
m = XMMatrixMultiply(m, XMMatrixTranslation( placement->GetPosX(), placement->GetPosY(), placement->GetPosZ() ) );

XMStoreFloat4x4( &m_constantBufferData.model, XMMatrixTranspose(m) );
مرخصة بموجب: CC-BY-SA مع الإسناد
لا تنتمي إلى StackOverflow
scroll top