1

オブジェクトの移動をボタンの押下にバインドしたい。ボタンを押すと、オブジェクトはすぐに消え、最初の Translation が常に実行されているかのように見えます。その後、ボタンを離すとすぐに消えて、ボタンに触れていなかったはずの場所に行き着きます。ボタンを押したり離したりすると、2 つの間で「バウンス」します。

D3DXMATRIX worldMatrix, viewMatrix, projectionMatrix;
bool result;


// Generate the view matrix based on the camera's position.
m_Camera->Render();

// Get the world, view, and projection matrices from the camera and d3d objects.
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);

// Move the world matrix by the rotation value so that the object will move.
if(m_Input->IsAPressed() == true) {
D3DXMatrixTranslation(&worldMatrix, 1.0f*rotation, 0.0f, 0.0f);
}
else {
    D3DXMatrixTranslation(&worldMatrix, 0.1f*rotation, 0.0f, 0.0f);
}

// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
m_Model->Render(m_Direct3D->GetDeviceContext());

// Render the model using the light shader.
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, 
                               m_Model->GetTexture(), m_Light->GetDirection(), m_Light->GetDiffuseColor());


if(!result)
{
    return false;
}

// Present the rendered scene to the screen.
m_Direct3D->EndScene();

私はまだ DX11 に本当に慣れていないので、よく見てきました。何が起こっているのかを理解しようとして、ここで髪を引っ張っています。

4

1 に答える 1

4

それがあなたのコードが行うことです。ボタンが押された場合は、1 つのワールド マトリックスを設定し、そうでない場合は別のワールド マトリックスを設定します。あなたがする必要があるのは、ワールドマトリックスに新しく生成された変換マトリックスを掛けることです。この乗算は 1 秒間に最大 60 回発生することに注意してください。したがって、1 回ごとに移動する必要がある距離はごくわずかです。

あなたのコードは次のようになります

if (m_Input->IsAPressed() == true) {
   D3DXMATRIX translation;
   D3DXMatrixTranslation(&translation, 0.05f, 0.0f, 0.0f);
   worldMatrix *= translation;
}

あなたがする必要があるかもしれません

m_Direct3D->SetWorldMatrix(worldMatrix);

または似たようなもの。m_Camera と m_Direct3D に使用しているクラスに慣れていないと思います。

于 2012-01-16T19:19:58.733 に答える