DirectX 11 D3DXMatrixTranslation 继续运行吗?

发布于 2024-12-27 18:55:21 字数 1395 浏览 1 评论 0原文

我想将移动对象绑定到按下按钮。当我按下按钮时,该对象很快消失,并且看起来好像第一个翻译始终在运行。然后,当我松开按钮时,它很快就会消失并最终回到没有触摸按钮的地方。当我按下/释放按钮时,在两者之间“弹跳”。

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 还很陌生,并且已经仔细观察过。我正在这里拔我的头发试图弄清楚发生了什么事。

I want to bind moving an object to a button press. When I press the button, the object vanishes quickly and appears as if the first Translation was always running. Then when I let go of the button, it quickly vanishes and ends up where it would've been without touching the button. 'Bouncing' between the two when I press/release the button.

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();

I'm still really new to DX11 and I've had a good look around. I'm pulling my hair out here trying to work out whats going on.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

绝影如岚 2025-01-03 18:55:21

这就是你的代码的作用。如果按下按钮,您将设置一个世界矩阵,如果没有,则设置另一个世界矩阵。您需要做的是将世界矩阵乘以新生成的平移矩阵。请注意,这种乘法每秒会发生约 60 次,因此每次只需移动很小的距离。

您的代码应该是这样的

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 的类。

That's what your code does. If a button is pressed you set one world matrix, if not - another. What you need to do is multiply the world matrix by a newly generated translation matrix. Notice that this multiplication will happen ~60 times every second, so you need to move only a very tiny distance with each one.

Your code should be like this

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

You may need to do

m_Direct3D->SetWorldMatrix(worldMatrix);

Or something similar. I don't think I'm familiar with the classes you're using for m_Camera and m_Direct3D.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文