Merge branch 'main' into ImGui-V2

This commit is contained in:
2024-04-08 15:37:13 +02:00
2 changed files with 133 additions and 101 deletions

View File

@@ -741,6 +741,103 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
m_Direct3D->GetProjectionMatrix(projectionMatrix);
m_Direct3D->GetOrthoMatrix(orthoMatrix);
// Get the light properties.
for (i = 0; i < m_numLights; i++)
{
// Create the diffuse color array from the four light colors.
diffuseColor[i] = m_Lights[i]->GetDiffuseColor();
// Create the light position array from the four light positions.
lightPosition[i] = m_Lights[i]->GetPosition();
}
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);
for (auto cube : m_cubes)
{
scaleMatrix = cube->GetScaleMatrix();
if (cube->m_demoSpinning)
rotateMatrix = XMMatrixRotationY(rotation);
else
{
rotateMatrix = cube->GetRotateMatrix();
}
translateMatrix = cube->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
cube->Render(m_Direct3D->GetDeviceContext());
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 object : m_object)
{
scaleMatrix = object->GetScaleMatrix();
if (object->m_demoSpinning)
rotateMatrix = XMMatrixRotationY(rotation);
else
{
rotateMatrix = object->GetRotateMatrix();
}
translateMatrix = object->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
object->Render(m_Direct3D->GetDeviceContext());
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
if (!result)
{
return false;
}
}
// Render terrain
for (auto chunk : m_terrainChunk)
{
scaleMatrix = chunk->GetScaleMatrix();
rotateMatrix = chunk->GetRotateMatrix();
translateMatrix = chunk->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
chunk->Render(m_Direct3D->GetDeviceContext());
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), chunk->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, chunk->GetTexture(1),
diffuseColor, lightPosition);
if (!result)
{
return false;
}
}
// Setup matrices - Top display plane.
worldMatrix = XMMatrixTranslation(0.0f, 1.5f, 0.0f);
@@ -777,16 +874,6 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
return false;
}
// Get the light properties.
for (i = 0; i < m_numLights; i++)
{
// Create the diffuse color array from the four light colors.
diffuseColor[i] = m_Lights[i]->GetDiffuseColor();
// Create the light position array from the four light positions.
lightPosition[i] = m_Lights[i]->GetPosition();
}
// Construct the frustum.
m_Frustum->ConstructFrustum(viewMatrix, projectionMatrix, SCREEN_DEPTH);
@@ -919,92 +1006,7 @@ bool ApplicationClass::Render(float rotation, float x, float y, float z)
lightPosition[i] = m_Lights[i]->GetPosition();
}
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);
for (auto cube : m_cubes)
{
scaleMatrix = cube->GetScaleMatrix();
if (cube->m_demoSpinning)
rotateMatrix = XMMatrixRotationY(rotation);
else
{
rotateMatrix = cube->GetRotateMatrix();
}
translateMatrix = cube->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
cube->Render(m_Direct3D->GetDeviceContext());
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 object : m_object)
{
scaleMatrix = object->GetScaleMatrix();
if (object->m_demoSpinning)
rotateMatrix = XMMatrixRotationY(rotation);
else
{
rotateMatrix = object->GetRotateMatrix();
}
translateMatrix = object->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
object->Render(m_Direct3D->GetDeviceContext());
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
if (!result)
{
return false;
}
}
// Render terrain
for (auto chunk : m_terrainChunk)
{
scaleMatrix = chunk->GetScaleMatrix();
rotateMatrix = chunk->GetRotateMatrix();
translateMatrix = chunk->GetTranslateMatrix();
srMatrix = XMMatrixMultiply(scaleMatrix, rotateMatrix);
worldMatrix = XMMatrixMultiply(srMatrix, translateMatrix);
chunk->Render(m_Direct3D->GetDeviceContext());
result = m_LightShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix, m_Model->GetTexture(0),
diffuseColor, lightPosition);
if (!result)
{
return false;
}
}
// Render the model using the multitexture shader.
//result = m_MultiTextureShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix,
@@ -1076,6 +1078,16 @@ void ApplicationClass::GenerateTerrain()
char textureFilename[128];
char textureFilename2[128];
char textureFilename3[128];
XMMATRIX scaleMatrix;
int scaleX, scaleY, scaleZ;
scaleX = 10.0f;
scaleY = 1.0f;
scaleZ = 10.0f;
scaleMatrix = XMMatrixScaling(scaleX, scaleY, scaleZ);
// Set the file name of the model.
strcpy_s(modelFilename, "plane.txt");
strcpy_s(textureFilename, "stone01.tga");
@@ -1083,14 +1095,16 @@ void ApplicationClass::GenerateTerrain()
strcpy_s(textureFilename3, "alpha01.tga");
// for loop to generate terrain chunks for a 10x10 grid
for (int i = -5; i < 5; i++)
for (int i = 0; i < 10; i++)
{
for (int j = -5; j < 5; j++)
for (int j = 0; j < 10; j++)
{
Object* newTerrain = new Object();
newTerrain->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename, textureFilename2, textureFilename3);
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i*10, -5.0f, j*10));
newTerrain->SetScaleMatrix(scaleMatrix);
newTerrain->SetTranslateMatrix(XMMatrixTranslation(i / 2 * (scaleX * 2), -5.0f, j * (scaleZ * 2)));
m_terrainChunk.push_back(newTerrain);