Scaling + Rotation + Translation
This commit is contained in:
parent
86e06aea02
commit
3ee96cf6ec
@ -51,8 +51,8 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Set the initial position of the camera.
|
// 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);
|
m_Camera->SetRotation(0.0f, 0.0f, 0.0f);
|
||||||
|
|
||||||
// Set the file name of the model.
|
// Set the file name of the model.
|
||||||
strcpy_s(modelFilename, "sphere.obj");
|
strcpy_s(modelFilename, "sphere.obj");
|
||||||
@ -138,6 +138,9 @@ void ApplicationClass::Shutdown()
|
|||||||
bool ApplicationClass::Frame()
|
bool ApplicationClass::Frame()
|
||||||
{
|
{
|
||||||
static float rotation = 0.0f;
|
static float rotation = 0.0f;
|
||||||
|
static float x = 2.f;
|
||||||
|
static float y = 0.f;
|
||||||
|
static float z = 0.f;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
@ -148,8 +151,17 @@ bool ApplicationClass::Frame()
|
|||||||
rotation += 360.0f;
|
rotation += 360.0f;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Update the x position variable each frame.
|
||||||
|
x -= 0.0174532925f * 0.54672f;
|
||||||
|
|
||||||
|
y -= 0.0174532925f * 0.8972f;
|
||||||
|
|
||||||
|
// Update the z position variable each frame.
|
||||||
|
z -= 0.0174532925f * 0.8972f;
|
||||||
|
|
||||||
|
|
||||||
// Render the graphics scene.
|
// Render the graphics scene.
|
||||||
result = Render(rotation);
|
result = Render(rotation, x, y, z);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
@ -159,9 +171,9 @@ bool ApplicationClass::Frame()
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
bool ApplicationClass::Render(float rotation)
|
bool ApplicationClass::Render(float rotation, float x, float y, float z)
|
||||||
{
|
{
|
||||||
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
|
XMMATRIX worldMatrix, viewMatrix, projectionMatrix, rotateMatrix, translateMatrix, scaleMatrix, srMatrix;
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
|
||||||
@ -175,8 +187,14 @@ bool ApplicationClass::Render(float rotation)
|
|||||||
m_Direct3D->GetWorldMatrix(worldMatrix);
|
m_Direct3D->GetWorldMatrix(worldMatrix);
|
||||||
m_Camera->GetViewMatrix(viewMatrix);
|
m_Camera->GetViewMatrix(viewMatrix);
|
||||||
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
||||||
// Rotate the world matrix by the rotation value so that the triangle will spin.
|
|
||||||
worldMatrix = XMMatrixRotationY(rotation);
|
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(rotateMatrix, translateMatrix);
|
||||||
|
|
||||||
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
|
// Put the model vertex and index buffers on the graphics pipeline to prepare them for drawing.
|
||||||
m_Model->Render(m_Direct3D->GetDeviceContext());
|
m_Model->Render(m_Direct3D->GetDeviceContext());
|
||||||
@ -188,6 +206,26 @@ bool ApplicationClass::Render(float rotation)
|
|||||||
{
|
{
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
scaleMatrix = XMMatrixScaling(2.0f, 2.0f, 2.0f); // 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(),
|
||||||
|
m_Light->GetDirection(), m_Light->GetDiffuseColor());
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Present the rendered scene to the screen.
|
// Present the rendered scene to the screen.
|
||||||
m_Direct3D->EndScene();
|
m_Direct3D->EndScene();
|
||||||
|
|
||||||
|
@ -35,7 +35,7 @@ public:
|
|||||||
bool Frame();
|
bool Frame();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
bool Render(float);
|
bool Render(float, float, float, float);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
D3DClass* m_Direct3D;
|
D3DClass* m_Direct3D;
|
||||||
|
Loading…
x
Reference in New Issue
Block a user