Avancement Limière

This commit is contained in:
Harpie94
2024-03-25 18:03:06 +01:00
parent af2231210c
commit da18ae6547
12 changed files with 678 additions and 50 deletions

View File

@@ -6,6 +6,8 @@ ApplicationClass::ApplicationClass()
m_Camera = 0;
m_Model = 0;
m_TextureShader = 0;
m_LightShader = 0;
m_Light = 0;
}
@@ -72,12 +74,43 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
return false;
}
// Create and initialize the light shader object.
m_LightShader = new LightShaderClass;
result = m_LightShader->Initialize(m_Direct3D->GetDevice(), hwnd);
if (!result)
{
MessageBox(hwnd, L"Could not initialize the light shader object.", L"Error", MB_OK);
return false;
}
// Create and initialize the light object.
m_Light = new LightClass;
m_Light->SetDiffuseColor(1.0f, 1.0f, 1.0f, 1.0f);
m_Light->SetDirection(0.0f, 0.0f, 1.0f);
return true;
}
void ApplicationClass::Shutdown()
{
// Release the light object.
if (m_Light)
{
delete m_Light;
m_Light = 0;
}
// Release the light shader object.
if (m_LightShader)
{
m_LightShader->Shutdown();
delete m_LightShader;
m_LightShader = 0;
}
// Release the texture shader object.
if (m_TextureShader)
{
@@ -115,11 +148,19 @@ void ApplicationClass::Shutdown()
bool ApplicationClass::Frame()
{
static float rotation = 0.0f;
bool result;
// Update the rotation variable each frame.
rotation -= 0.0174532925f * 0.1f;
if (rotation < 0.0f)
{
rotation += 360.0f;
}
// Render the graphics scene.
result = Render();
result = Render(rotation);
if (!result)
{
return false;
@@ -129,7 +170,8 @@ bool ApplicationClass::Frame()
}
bool ApplicationClass::Render()
bool ApplicationClass::Render(float rotation)
{
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
bool result;
@@ -146,8 +188,15 @@ bool ApplicationClass::Render()
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.
m_Model->Render(m_Direct3D->GetDeviceContext());
// Render the model using the texture shader.
result = m_TextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture());
if (!result)
@@ -155,6 +204,14 @@ bool ApplicationClass::Render()
return false;
}
// 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();