los triangle
This commit is contained in:
@@ -1,9 +1,15 @@
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
// Filename: applicationclass.cpp
|
||||
////////////////////////////////////////////////////////////////////////////////
|
||||
#include "applicationclass.h"
|
||||
|
||||
|
||||
ApplicationClass::ApplicationClass()
|
||||
{
|
||||
m_Direct3D = 0;
|
||||
m_Camera = 0;
|
||||
m_Model = 0;
|
||||
m_ColorShader = 0;
|
||||
}
|
||||
|
||||
|
||||
@@ -31,12 +37,62 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||
MessageBox(hwnd, L"Could not initialize Direct3D", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create the camera object.
|
||||
m_Camera = new CameraClass;
|
||||
|
||||
// Set the initial position of the camera.
|
||||
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
|
||||
|
||||
// Create and initialize the model object.
|
||||
m_Model = new ModelClass;
|
||||
|
||||
result = m_Model->Initialize(m_Direct3D->GetDevice());
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
// Create and initialize the color shader object.
|
||||
m_ColorShader = new ColorShaderClass;
|
||||
|
||||
result = m_ColorShader->Initialize(m_Direct3D->GetDevice(), hwnd);
|
||||
if (!result)
|
||||
{
|
||||
MessageBox(hwnd, L"Could not initialize the color shader object.", L"Error", MB_OK);
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
void ApplicationClass::Shutdown()
|
||||
{
|
||||
// Release the color shader object.
|
||||
if (m_ColorShader)
|
||||
{
|
||||
m_ColorShader->Shutdown();
|
||||
delete m_ColorShader;
|
||||
m_ColorShader = 0;
|
||||
}
|
||||
|
||||
// Release the model object.
|
||||
if (m_Model)
|
||||
{
|
||||
m_Model->Shutdown();
|
||||
delete m_Model;
|
||||
m_Model = 0;
|
||||
}
|
||||
|
||||
// Release the camera object.
|
||||
if (m_Camera)
|
||||
{
|
||||
delete m_Camera;
|
||||
m_Camera = 0;
|
||||
}
|
||||
|
||||
// Release the Direct3D object.
|
||||
if (m_Direct3D)
|
||||
{
|
||||
@@ -60,17 +116,40 @@ bool ApplicationClass::Frame()
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
bool ApplicationClass::Render()
|
||||
{
|
||||
// Clear the buffers to begin the scene.
|
||||
m_Direct3D->BeginScene(255.0f, 255.0f, 0.0f, 1.0f);
|
||||
XMMATRIX worldMatrix, viewMatrix, projectionMatrix;
|
||||
bool result;
|
||||
|
||||
|
||||
// Clear the buffers to begin the scene.
|
||||
m_Direct3D->BeginScene(0.0f, 0.0f, 0.0f, 1.0f);
|
||||
|
||||
// Generate the view matrix based on the camera's position.
|
||||
m_Camera->Render();
|
||||
|
||||
// Get the world, view, and projection matrices from the camera and d3d objects.
|
||||
m_Direct3D->GetWorldMatrix(worldMatrix);
|
||||
m_Camera->GetViewMatrix(viewMatrix);
|
||||
m_Direct3D->GetProjectionMatrix(projectionMatrix);
|
||||
|
||||
// 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 color shader.
|
||||
result = m_ColorShader->Render(m_Direct3D->GetDeviceContext(), m_Model->GetIndexCount(), worldMatrix, viewMatrix, projectionMatrix);
|
||||
if (!result)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
|
||||
// Present the rendered scene to the screen.
|
||||
m_Direct3D->EndScene();
|
||||
|
||||
return true;
|
||||
}
|
||||
Reference in New Issue
Block a user