Merge branch 'main' into Imgui
This commit is contained in:
commit
05e5959cb1
@ -22,6 +22,7 @@ ApplicationClass::~ApplicationClass()
|
|||||||
|
|
||||||
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
||||||
{
|
{
|
||||||
|
char modelFilename[128];
|
||||||
char textureFilename[128];
|
char textureFilename[128];
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
@ -51,12 +52,16 @@ bool ApplicationClass::Initialize(int screenWidth, int screenHeight, HWND hwnd)
|
|||||||
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
|
m_Camera->SetPosition(0.0f, 0.0f, -5.0f);
|
||||||
m_Camera->SetRotation(0.0f, 0.0f, 10.0f);
|
m_Camera->SetRotation(0.0f, 0.0f, 10.0f);
|
||||||
|
|
||||||
// Create and initialize the model object.
|
// Set the file name of the model.
|
||||||
m_Model = new ModelClass;
|
strcpy_s(modelFilename, "cube.txt");
|
||||||
|
|
||||||
// Set the name of the texture file that we will be loading.
|
// Set the name of the texture file that we will be loading.
|
||||||
strcpy_s(textureFilename, "stone01.tga");
|
strcpy_s(textureFilename, "stone01.tga");
|
||||||
|
|
||||||
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), textureFilename);
|
// Create and initialize the model object.
|
||||||
|
m_Model = new ModelClass;
|
||||||
|
|
||||||
|
result = m_Model->Initialize(m_Direct3D->GetDevice(), m_Direct3D->GetDeviceContext(), modelFilename, textureFilename);
|
||||||
if (!result)
|
if (!result)
|
||||||
{
|
{
|
||||||
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
|
MessageBox(hwnd, L"Could not initialize the model object.", L"Error", MB_OK);
|
||||||
|
40
enginecustom/cube.txt
Normal file
40
enginecustom/cube.txt
Normal file
@ -0,0 +1,40 @@
|
|||||||
|
Vertex Count: 36
|
||||||
|
|
||||||
|
Data:
|
||||||
|
|
||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0 0.0 0.0 0.0 1.0 0.0
|
||||||
|
1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0
|
||||||
|
-1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0
|
||||||
|
-1.0 1.0 -1.0 0.0 1.0 0.0 1.0 0.0
|
||||||
|
1.0 1.0 1.0 1.0 0.0 0.0 1.0 0.0
|
||||||
|
1.0 1.0 -1.0 1.0 1.0 0.0 1.0 0.0
|
||||||
|
-1.0 -1.0 -1.0 0.0 0.0 0.0 -1.0 0.0
|
||||||
|
1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0
|
||||||
|
-1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0
|
||||||
|
-1.0 -1.0 1.0 0.0 1.0 0.0 -1.0 0.0
|
||||||
|
1.0 -1.0 -1.0 1.0 0.0 0.0 -1.0 0.0
|
||||||
|
1.0 -1.0 1.0 1.0 1.0 0.0 -1.0 0.0
|
@ -87,6 +87,9 @@
|
|||||||
<ItemGroup>
|
<ItemGroup>
|
||||||
<Image Include="stone01.tga" />
|
<Image Include="stone01.tga" />
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="cube.txt" />
|
||||||
|
</ItemGroup>
|
||||||
<PropertyGroup Label="Globals">
|
<PropertyGroup Label="Globals">
|
||||||
<VCProjectVersion>17.0</VCProjectVersion>
|
<VCProjectVersion>17.0</VCProjectVersion>
|
||||||
<Keyword>Win32Proj</Keyword>
|
<Keyword>Win32Proj</Keyword>
|
||||||
|
@ -137,4 +137,9 @@
|
|||||||
<Filter>assets</Filter>
|
<Filter>assets</Filter>
|
||||||
</Image>
|
</Image>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
|
<ItemGroup>
|
||||||
|
<Text Include="cube.txt">
|
||||||
|
<Filter>assets</Filter>
|
||||||
|
</Text>
|
||||||
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
@ -6,6 +6,7 @@ ModelClass::ModelClass()
|
|||||||
m_vertexBuffer = 0;
|
m_vertexBuffer = 0;
|
||||||
m_indexBuffer = 0;
|
m_indexBuffer = 0;
|
||||||
m_Texture = 0;
|
m_Texture = 0;
|
||||||
|
m_model = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@ -18,10 +19,16 @@ ModelClass::~ModelClass()
|
|||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* textureFilename)
|
bool ModelClass::Initialize(ID3D11Device* device, ID3D11DeviceContext* deviceContext, char* modelFilename, char* textureFilename)
|
||||||
{
|
{
|
||||||
bool result;
|
bool result;
|
||||||
|
|
||||||
|
// Load in the model data.
|
||||||
|
result = LoadModel(modelFilename);
|
||||||
|
if (!result)
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
// Initialize the vertex and index buffers.
|
// Initialize the vertex and index buffers.
|
||||||
result = InitializeBuffers(device);
|
result = InitializeBuffers(device);
|
||||||
@ -48,6 +55,9 @@ void ModelClass::Shutdown()
|
|||||||
// Shutdown the vertex and index buffers.
|
// Shutdown the vertex and index buffers.
|
||||||
ShutdownBuffers();
|
ShutdownBuffers();
|
||||||
|
|
||||||
|
// Release the model data.
|
||||||
|
ReleaseModel();
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -81,35 +91,46 @@ bool ModelClass::InitializeBuffers(ID3D11Device* device)
|
|||||||
HRESULT result;
|
HRESULT result;
|
||||||
|
|
||||||
|
|
||||||
// Set the number of vertices in the vertex array.
|
|
||||||
m_vertexCount = 6;
|
|
||||||
|
|
||||||
// Set the number of indices in the index array.
|
|
||||||
m_indexCount = 6;
|
|
||||||
|
|
||||||
// Create the vertex array.
|
// Create the vertex array.
|
||||||
vertices = new VertexType[m_vertexCount];
|
vertices = new VertexType[m_vertexCount];
|
||||||
|
|
||||||
// Create the index array.
|
// Create the index array.
|
||||||
indices = new unsigned long[m_indexCount];
|
indices = new unsigned long[m_indexCount];
|
||||||
|
|
||||||
// Load the vertex array with data.
|
// Load the vertex array and index array with data.
|
||||||
vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); // Bottom left.
|
for (int i = 0; i < m_vertexCount; i++)
|
||||||
vertices[0].texture = XMFLOAT2(0.0f, 1.0f);
|
{
|
||||||
vertices[0].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
vertices[i].position = XMFLOAT3(m_model[i].x, m_model[i].y, m_model[i].z);
|
||||||
|
vertices[i].texture = XMFLOAT2(m_model[i].tu, m_model[i].tv);
|
||||||
|
vertices[i].normal = XMFLOAT3(m_model[i].nx, m_model[i].ny, m_model[i].nz);
|
||||||
|
|
||||||
vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f); // Top middle.
|
indices[i] = i;
|
||||||
vertices[1].texture = XMFLOAT2(0.5f, 0.0f);
|
}
|
||||||
vertices[1].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
|
||||||
|
|
||||||
vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f); // Bottom right.
|
|
||||||
vertices[2].texture = XMFLOAT2(1.0f, 1.0f);
|
|
||||||
vertices[2].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
|
||||||
|
|
||||||
// Load the index array with data.
|
//// Create the vertex array.
|
||||||
indices[0] = 0; // Bottom left.
|
//vertices = new VertexType[m_vertexCount];
|
||||||
indices[1] = 1; // Top middle.
|
|
||||||
indices[2] = 2; // Bottom right.
|
//// Create the index array.
|
||||||
|
//indices = new unsigned long[m_indexCount];
|
||||||
|
|
||||||
|
//// Load the vertex array with data.
|
||||||
|
//vertices[0].position = XMFLOAT3(-1.0f, -1.0f, 0.0f); // Bottom left.
|
||||||
|
//vertices[0].texture = XMFLOAT2(0.0f, 1.0f);
|
||||||
|
//vertices[0].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
//vertices[1].position = XMFLOAT3(0.0f, 1.0f, 0.0f); // Top middle.
|
||||||
|
//vertices[1].texture = XMFLOAT2(0.5f, 0.0f);
|
||||||
|
//vertices[1].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
//vertices[2].position = XMFLOAT3(1.0f, -1.0f, 0.0f); // Bottom right.
|
||||||
|
//vertices[2].texture = XMFLOAT2(1.0f, 1.0f);
|
||||||
|
//vertices[2].normal = XMFLOAT3(0.0f, 0.0f, -1.0f);
|
||||||
|
|
||||||
|
//// Load the index array with data.
|
||||||
|
//indices[0] = 0; // Bottom left.
|
||||||
|
//indices[1] = 1; // Top middle.
|
||||||
|
//indices[2] = 2; // Bottom right.
|
||||||
|
|
||||||
// Set up the description of the static vertex buffer.
|
// Set up the description of the static vertex buffer.
|
||||||
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
vertexBufferDesc.Usage = D3D11_USAGE_DEFAULT;
|
||||||
@ -231,5 +252,71 @@ void ModelClass::ReleaseTexture()
|
|||||||
m_Texture = 0;
|
m_Texture = 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool ModelClass::LoadModel(char* filename)
|
||||||
|
{
|
||||||
|
ifstream fin;
|
||||||
|
char input;
|
||||||
|
int i;
|
||||||
|
|
||||||
|
|
||||||
|
// Open the model file.
|
||||||
|
fin.open(filename);
|
||||||
|
|
||||||
|
// If it could not open the file then exit.
|
||||||
|
if (fin.fail())
|
||||||
|
{
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read up to the value of vertex count.
|
||||||
|
fin.get(input);
|
||||||
|
while (input != ':')
|
||||||
|
{
|
||||||
|
fin.get(input);
|
||||||
|
}
|
||||||
|
|
||||||
|
// Read in the vertex count.
|
||||||
|
fin >> m_vertexCount;
|
||||||
|
|
||||||
|
// Set the number of indices to be the same as the vertex count.
|
||||||
|
m_indexCount = m_vertexCount;
|
||||||
|
|
||||||
|
// Create the model using the vertex count that was read in.
|
||||||
|
m_model = new ModelType[m_vertexCount];
|
||||||
|
|
||||||
|
// Read up to the beginning of the data.
|
||||||
|
fin.get(input);
|
||||||
|
while (input != ':')
|
||||||
|
{
|
||||||
|
fin.get(input);
|
||||||
|
}
|
||||||
|
fin.get(input);
|
||||||
|
fin.get(input);
|
||||||
|
|
||||||
|
// Read in the vertex data.
|
||||||
|
for (i = 0; i < m_vertexCount; i++)
|
||||||
|
{
|
||||||
|
fin >> m_model[i].x >> m_model[i].y >> m_model[i].z;
|
||||||
|
fin >> m_model[i].tu >> m_model[i].tv;
|
||||||
|
fin >> m_model[i].nx >> m_model[i].ny >> m_model[i].nz;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Close the model file.
|
||||||
|
fin.close();
|
||||||
|
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelClass::ReleaseModel()
|
||||||
|
{
|
||||||
|
if (m_model)
|
||||||
|
{
|
||||||
|
delete[] m_model;
|
||||||
|
m_model = 0;
|
||||||
|
}
|
||||||
|
|
||||||
return;
|
return;
|
||||||
}
|
}
|
@ -7,7 +7,9 @@
|
|||||||
//////////////
|
//////////////
|
||||||
#include <d3d11.h>
|
#include <d3d11.h>
|
||||||
#include <directxmath.h>
|
#include <directxmath.h>
|
||||||
|
#include <fstream>
|
||||||
using namespace DirectX;
|
using namespace DirectX;
|
||||||
|
using namespace std;
|
||||||
|
|
||||||
///////////////////////
|
///////////////////////
|
||||||
// MY CLASS INCLUDES //
|
// MY CLASS INCLUDES //
|
||||||
@ -29,12 +31,20 @@ private:
|
|||||||
XMFLOAT3 normal;
|
XMFLOAT3 normal;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
struct ModelType
|
||||||
|
{
|
||||||
|
float x, y, z;
|
||||||
|
float tu, tv;
|
||||||
|
float nx, ny, nz;
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
public:
|
public:
|
||||||
ModelClass();
|
ModelClass();
|
||||||
ModelClass(const ModelClass&);
|
ModelClass(const ModelClass&);
|
||||||
~ModelClass();
|
~ModelClass();
|
||||||
|
|
||||||
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*);
|
bool Initialize(ID3D11Device*, ID3D11DeviceContext*, char*, char*);
|
||||||
void Shutdown();
|
void Shutdown();
|
||||||
void Render(ID3D11DeviceContext*);
|
void Render(ID3D11DeviceContext*);
|
||||||
|
|
||||||
@ -49,10 +59,15 @@ private:
|
|||||||
bool LoadTexture(ID3D11Device*, ID3D11DeviceContext*, char*);
|
bool LoadTexture(ID3D11Device*, ID3D11DeviceContext*, char*);
|
||||||
void ReleaseTexture();
|
void ReleaseTexture();
|
||||||
|
|
||||||
|
bool LoadModel(char*);
|
||||||
|
void ReleaseModel();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
ID3D11Buffer* m_vertexBuffer, * m_indexBuffer;
|
||||||
int m_vertexCount, m_indexCount;
|
int m_vertexCount, m_indexCount;
|
||||||
TextureClass* m_Texture;
|
TextureClass* m_Texture;
|
||||||
|
|
||||||
|
ModelType* m_model;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
Loading…
x
Reference in New Issue
Block a user