Plane render ok

This commit is contained in:
CatChow0 2024-03-29 17:31:18 +01:00
parent 2c493bc979
commit b73f86ff45
3 changed files with 62 additions and 60 deletions

View File

@ -173,7 +173,7 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
} }
// Set the file name of the model. // Set the file name of the model.
strcpy_s(modelFilename, "cube.txt"); strcpy_s(modelFilename, "plane.txt");
// Set the file name of the textures. // Set the file name of the textures.
strcpy_s(textureFilename1, "stone01.tga"); strcpy_s(textureFilename1, "stone01.tga");
@ -344,6 +344,22 @@ void ApplicationClass::Shutdown()
m_Model = 0; m_Model = 0;
} }
// Liberez la memoire pour chaque cube
for (auto cube : m_cubes)
{
cube->Shutdown();
delete cube;
}
m_cubes.clear();
// Liberez la memoire pour chaque cube du terrain
for (auto cube : m_terrainChunk)
{
cube->Shutdown();
delete cube;
}
m_terrainChunk.clear();
// Release the multitexture shader object. // Release the multitexture shader object.
if (m_MultiTextureShader) if (m_MultiTextureShader)
{ {
@ -365,40 +381,23 @@ void ApplicationClass::Shutdown()
delete m_TextureShader; delete m_TextureShader;
m_TextureShader = 0; m_TextureShader = 0;
} }
// Liberez la memoire pour chaque cube
for (auto cube : m_cubes)
{
cube->Shutdown();
delete cube;
}
m_cubes.clear();
// Liberez la memoire pour chaque cube du terrain
for (auto cube : m_terrainChunk)
{
cube->Shutdown();
delete cube;
}
m_terrainChunk.clear();
// Release the camera object. // Release the camera object.
if (m_Camera) if (m_Camera)
{ {
delete m_Camera; delete m_Camera;
m_Camera = 0; m_Camera = 0;
} }
// Release the D3D object. // Release the D3D object.
if (m_Direct3D) if (m_Direct3D)
{ {
m_Direct3D->Shutdown(); m_Direct3D->Shutdown();
delete m_Direct3D; delete m_Direct3D;
m_Direct3D = 0; m_Direct3D = 0;
} }
return; return;
} }
} }
@ -560,13 +559,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix.
rotateMatrix = XMMatrixRotationY(rotation); // Build the rotation matrix.
translateMatrix = XMMatrixTranslation(x, y, z); // Build the translation matrix.
// Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
// Render the model using the multitexture shader. // Render the model using the multitexture shader.
m_Model->Render(m_Direct3D->GetDeviceContext()); m_Model->Render(m_Direct3D->GetDeviceContext());
@ -588,17 +581,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
// Create the light position array from the four light positions. // Create the light position array from the four light positions.
lightPosition[i] = m_Lights[i].GetPosition(); lightPosition[i] = m_Lights[i].GetPosition();
} }
// 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(0),
diffuseColor, lightPosition);
if (!result)
{
return false;
}
for (auto cube : m_cubes) for (auto cube : m_cubes)
{ {
@ -618,8 +601,8 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix); srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix); worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), cube->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, cube->GetTexture(0), result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition); diffuseColor, lightPosition);
if (!result) if (!result)
{ {
return false; return false;
@ -647,8 +630,29 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
} }
// Render the model using the multitexture shader. // Render the model using the multitexture shader.
result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, //result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
m_Model->GetTexture(0), m_Model->GetTexture(1)); // m_Model->GetTexture(0), m_Model->GetTexture(1));
if (!result)
{
return false;
}
scaleMatrix = XMMatrixScaling(0.5f, 0.5f, 0.5f); // Build the scaling matrix.
rotateMatrix = XMMatrixRotationY(rotation); // Build the rotation matrix.
translateMatrix = XMMatrixTranslation(x, y, z); // Build the translation matrix.
// Multiply the scale, rotation, and translation matrices together to create the final world transformation matrix.
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
// 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(0),
diffuseColor, lightPosition);
if (!result) if (!result)
{ {
return false; return false;
@ -695,8 +699,7 @@ void ApplicationClass::GenerateTerrain()
Object* newTerrain = new Object(); Object* newTerrain = new Object();
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2); newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2);
newTerrain->SetTranslateMatrix(XMMatrixTranslation(0.0f, -1.0f, 0.0f)); newTerrain->SetTranslateMatrix(XMMatrixTranslation(0.0f, 0.0f, 0.0f));
newTerrain->SetRotateMatrix(XMMatrixRotationY(180.0f));
m_cubes.push_back(newTerrain); m_cubes.push_back(newTerrain);

View File

@ -273,10 +273,10 @@
<Text Include="cube.txt"> <Text Include="cube.txt">
<Filter>Assets</Filter> <Filter>Assets</Filter>
</Text> </Text>
<Text Include="plane.txt"> <Text Include="sphere.txt">
<Filter>Assets</Filter> <Filter>Assets</Filter>
</Text> </Text>
<Text Include="sphere.txt"> <Text Include="plane.txt">
<Filter>Assets</Filter> <Filter>Assets</Filter>
</Text> </Text>
</ItemGroup> </ItemGroup>

View File

@ -3,9 +3,8 @@ Pos=60,60
Size=400,400 Size=400,400
[Window][Khaotic Engine] [Window][Khaotic Engine]
Pos=2,63 Pos=14,56
Size=694,183 Size=694,183
Collapsed=1
[Window][Objects] [Window][Objects]
Pos=10,29 Pos=10,29
@ -13,7 +12,7 @@ Size=492,353
Collapsed=1 Collapsed=1
[Window][Terrain] [Window][Terrain]
Pos=913,27 Pos=892,20
Size=418,94 Size=418,94
Collapsed=1 Collapsed=1