-
Notifications
You must be signed in to change notification settings - Fork 0
/
Object.h
128 lines (92 loc) · 3.73 KB
/
Object.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
//------------------------------------------------------- ----------------------
// File: Object.h
//-----------------------------------------------------------------------------
#pragma once
#include "Mesh.h"
#include "Camera.h"
#define DIR_FORWARD 0x01
#define DIR_BACKWARD 0x02
#define DIR_LEFT 0x04
#define DIR_RIGHT 0x08
#define DIR_UP 0x10
#define DIR_DOWN 0x20
class CShader;
class CBoundingBoxShader;
struct CB_GAMEOBJECT_INFO
{
XMFLOAT4X4 m_xmf4x4World;
};
class CMaterial
{
public:
CMaterial();
virtual ~CMaterial();
private:
int m_nReferences = 0;
public:
char m_pstrName[256] = { '\0' };
void AddRef() { m_nReferences++; }
void Release() { if (--m_nReferences <= 0) delete this; }
XMFLOAT4 m_xmf4AlbedoColor = XMFLOAT4(0.4f, 0.2f, 0.2f, 0.0f);
XMFLOAT4 m_xmf4EmissionColor = XMFLOAT4(0.0f, 0.0f, 0.5f, 0.0f);
XMFLOAT4 m_xmf4SpecularColor = XMFLOAT4(0.0f, 0.0f, 0.3f, 0.0f);
int m_nMaterial = 1; //Material Index, CScene::m_pReflections[]
void SetAlbedoColor(XMFLOAT4 xmf4Color) { m_xmf4AlbedoColor = xmf4Color; }
void SetEmissionColor(XMFLOAT4 xmf4Color) { m_xmf4EmissionColor = xmf4Color; }
void SetMaterial(int nMaterial) { m_nMaterial = nMaterial; }
void UpdateShaderVariables(ID3D12GraphicsCommandList *pd3dCommandList);
void ReleaseShaderVariables();
void ReleaseUploadBuffers();
void LoadMaterialFromFile(ID3D12Device* pd3dDevice, ID3D12GraphicsCommandList* pd3dCommandList, FILE* pFile);
};
////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//
class CGameObject
{
public:
CGameObject() { }
CGameObject(ID3D12Device* pd3dDevice, ID3D12GraphicsCommandList* pd3dCommandList, UINT nMaterials=1);
virtual ~CGameObject();
public:
char m_pstrName[256] = { '\0' };
XMFLOAT4X4 m_xmf4x4World;
CMesh *m_pMesh = NULL;
BoundingOrientedBox m_xmBoundingBox = BoundingOrientedBox(XMFLOAT3(0.0f, 0.0f, 0.0f), XMFLOAT3(0.1f, 0.1f, 0.1f), XMFLOAT4(0.0f, 0.0f, 0.0f, 1.0f));
CBoundingBoxMesh* m_pBoundingBoxMesh = NULL;
CShader *m_pShader = NULL;
UINT m_nMaterials = 0;
CMaterial **m_ppMaterials = NULL;
protected:
ID3D12Resource *m_pd3dcbGameObject = NULL;
public:
CB_GAMEOBJECT_INFO *m_pcbMappedGameObject = NULL;
public:
void SetMesh(CMesh* pMesh);
void SetBoundingBoxMesh(CBoundingBoxMesh *pMesh);
void SetShader(CShader *pShader);
void SetAlbedoColor(UINT nIndex, XMFLOAT4 xmf4Color);
void SetEmissionColor(UINT nIndex, XMFLOAT4 xmf4Color);
void SetMaterial(UINT nIndex, CMaterial *pMaterial);
void SetMaterial(UINT nIndex, UINT nMaterial);
virtual void CreateShaderVariables(ID3D12Device *pd3dDevice, ID3D12GraphicsCommandList *pd3dCommandList);
virtual void ReleaseShaderVariables();
virtual void UpdateShaderVariables(ID3D12GraphicsCommandList *pd3dCommandList);
void UpdateBoundingBox();
void RenderBoundingBox(ID3D12GraphicsCommandList* pd3dCommandList, CCamera* pCamera);
virtual void Animate(float fTimeElapsed);
virtual void OnPrepareRender() { }
virtual void Render(ID3D12GraphicsCommandList *pd3dCommandList, CCamera *pCamera=NULL);
virtual void ReleaseUploadBuffers();
XMFLOAT3 GetPosition();
XMFLOAT3 GetLook();
XMFLOAT3 GetUp();
XMFLOAT3 GetRight();
void SetPosition(float x, float y, float z);
void SetPosition(XMFLOAT3 xmf3Position);
void MoveStrafe(float fDistance = 1.0f);
void MoveUp(float fDistance = 1.0f);
void MoveForward(float fDistance = 1.0f);
void Rotate(float fPitch = 10.0f, float fYaw = 10.0f, float fRoll = 10.0f);
void Rotate(XMFLOAT3 *pxmf3Axis, float fAngle);
void LoadGameObjectFromFile(ID3D12Device *pd3dDevice, ID3D12GraphicsCommandList *pd3dCommandList, char *pstrFileName);
};