簡體   English   中英

在DirectX 11.2 C ++中圍繞所有3個(X,Y,Z)軸旋轉模型

[英]Rotating a model around all 3 (X, Y, Z) axis in DirectX 11.2 C++

我有下一個問題。 我試圖同時圍繞所有3軸旋轉3D模型。 意思是我想通過按鍵盤上的按鈕繞X軸,然后繞Y軸,然后再繞X旋轉模型,等等。 問題是當我像這樣使用XMMatrixRotationX,XMMatrixRotationY或XMMatrixRotationZ時:

    void Rotate(float radians_x, float radians_y, float radians_z)
    {
        DirectX::XMStoreFloat4x4(&_transfer.world, DirectX::XMMatrixTranspose(DirectX::XMMatrixRotationZ(radians_z)));
        DirectX::XMStoreFloat4x4(&_transfer.world, DirectX::XMMatrixTranspose(DirectX::XMMatrixRotationY(radians_y)));
        DirectX::XMStoreFloat4x4(&_transfer.world, DirectX::XMMatrixTranspose(DirectX::XMMatrixRotationX(radians_x)));
    }

只有最后的輪換完成了。 我希望能夠將對象繞每個軸旋轉特定角度(實際上是弧度),如代碼中所示。 我發現XMMatrixRotationAxis方法可以做到這一點,但是它只使用一個角度參數,我想為每個軸使用不同的角度參數。 誰能幫我解決這個問題?

另外,我不知道將什么作為第一個參數發送給XMMatrixRotationAxis,它只是說一個軸向量。 我不明白如何訪問這些代碼,我在代碼發布中使用的方法不需要發送任何軸。 如果這是正確的解決方案,我不明白為什么這是必要的,或者怎么做。

任何幫助將非常感激。

我在這里找到了答案:

http://books.google.hr/books?id=7ZkLAAAAQBAJ&pg=PA251&lpg=PA251&dq=XMMatrixRotationQuaternion&source=bl&ots=xveQhsj-x_&sig=Ny6IdK1JNFBF99LyC_HY8b-y4tI&hl=hr&sa=X&ei=dtkQVOmmA8aXatfugZgL&ved=0CHEQ6AEwCA#v=onepage&q=XMMatrixRotationQuaternion&f=false

我必須使用XMMatrixRotationRollPitchYaw。 現在,代碼看起來如下:

    void Rotate(float radians_x, float radians_y, float radians_z)
    {
        DirectX::XMStoreFloat4x4(&_transfer.world, DirectX::XMMatrixTranspose(DirectX::XMMatrixRotationRollPitchYaw(radians_x, radians_y, radians_z)));
    }

奇跡般有效 :)

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM