This commit is contained in:
CatChow0 2024-03-25 16:11:46 +01:00
commit 7ad8ed3483

View File

@ -48,7 +48,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
}
// Set the initial position of the camera.
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
m_Camera->SetPosition(0.0f, 0.0f, -10.0f);
m_Camera->SetRotation(0.0f, 0.0f, 10.0f);
// Set the file name of the model.
@ -155,7 +155,7 @@ bool ApplicationClass::Frame()
bool ApplicationClass::Render(float rotation)
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
XMMATRIX worldMatrix, viewMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
bool result;
@ -169,19 +169,37 @@ bool ApplicationClass::Render(float rotation)
m_Direct3D->GetWorldMatrix(worldMatrix);
m_Camera->GetViewMatrix(viewMatrix);
m_Direct3D->GetProjectionMatrix(projectionMatrix);
// Rotate the world matrix by the rotation value so that the triangle will spin.
worldMatrix = XMMatrixRotationY(rotation);
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
// Render the first cube
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f);
rotateMatrix = XMMatrixRotationX(rotation);
translateMatrix = XMMatrixTranslation(-2.0f, 0.0f, 0.0f);
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
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;
}
// Render the second cube
scaleMatrix = XMMatrixScaling(1.5f, 1.5f, 1.5f);
rotateMatrix = XMMatrixRotationY(rotation);
translateMatrix = XMMatrixTranslation(2.0f, 0.0f, 0.0f);
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
m_Model->Render(m_Direct3D->GetDeviceContext());
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();
@ -201,4 +219,4 @@ int ApplicationClass::GetScreenWidth() const
int ApplicationClass::GetScreenHeight() const
{
return GetSystemMetrics(SM_CYSCREEN);
}
}