2012-01-16 14 views
1

オブジェクトをボタン・プレスに移動してバインドしたいと思います。ボタンを押すと、オブジェクトはすぐに消滅し、最初の翻訳が常に実行されているかのように見えます。それから、ボタンを手放すと、すぐに消えて、ボタンに触れずにどこにいたでしょう。私がボタンを押したり離したりするとき、2人の間で「バウンス」します。DirectX 11 D3DXMatrixTranslationは引き続き実行されますか?

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つのワールドマトリックスを設定します(存在しない場合)。あなたがする必要があるのは、新しく生成された翻訳マトリックスで世界の行列を掛けることです。この乗算は毎秒約60回発生することに注意してください。したがって、各乗算で非常に小さい距離だけ移動する必要があります。

あなたのコードは、あなたが

m_Direct3D->SetWorldMatrix(worldMatrix); 

または類似何かをする必要があるかもしれません。この

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

ようにする必要があります。私はあなたがm_Cameraとm_Direct3Dで使っているクラスに精通しているとは思わない。

+0

私はまだこのすべてにとても新しいです。 –

+1

"各[フレーム]で非常に小さい距離だけ移動する"というかなり重要な部分は、フレーム時間を使用して距離を変更しています( 'unitsPerSecond * frameDelta')。これはあなたの動きを安定し、フレームレートから独立させます。 – ssube

+0

本当に便利です。ありがとうございました –

関連する問題