-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathGeo.cpp
More file actions
164 lines (107 loc) · 4.85 KB
/
Copy pathGeo.cpp
File metadata and controls
164 lines (107 loc) · 4.85 KB
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
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
#include "Geo.h"
void SphereGeo::Create(int horzSeg, int vertSeg, float radius){
float begin = 0;
float end = XM_2PI;
float begin2 = 0;
float end2 = XM_PI;
float end3 = XM_PI;
int numVerts = (horzSeg + 1)*(vertSeg + 1);
XMFLOAT3* pos = new XMFLOAT3[numVerts];
XMFLOAT3* normal = new XMFLOAT3[numVerts];
XMFLOAT2* txcoord = new XMFLOAT2[numVerts];
VertexPNU* verts;
verts = new VertexPNU[numVerts];
for (int i = 0; i < vertSeg; i++) {
}
}
/// Cube Geometry
CubeGeo::CubeGeo(){
m_rIds.m_topoID = D3D11_PRIMITIVE_TOPOLOGY_TRIANGLELIST;
m_pos = { 0.0f, 0.0f, 0.0f };
}
void CubeGeo::AssignResources(int texID, int vsID, int psID) {
m_rIds.m_textureID = texID;
m_rIds.m_vsID = vsID;
m_rIds.m_psID = psID;
}
void CubeGeo::Create(float width, float height, float depth) {
VertexPNU verts[] = {
{ XMFLOAT3(-width, -height, -depth), XMFLOAT3(0, 0, -1), XMFLOAT2(0, 1) },
{ XMFLOAT3(width, -height, -depth), XMFLOAT3(0, 0, -1), XMFLOAT2(1, 1) },
{ XMFLOAT3(-width, height, -depth), XMFLOAT3(0, 0, -1), XMFLOAT2(0, 0) },
{ XMFLOAT3(width, height, -depth), XMFLOAT3(0, 0, -1), XMFLOAT2(1, 0) },
{ XMFLOAT3(-width, height, -depth), XMFLOAT3(0, 1, -0), XMFLOAT2(0, 0) },
{ XMFLOAT3(width, height, -depth), XMFLOAT3(0, 1, -0), XMFLOAT2(0, 1) },
{ XMFLOAT3(-width, height, depth), XMFLOAT3(0, 1, -0), XMFLOAT2(1, 0) },
{ XMFLOAT3(width, height, depth), XMFLOAT3(0, 1, -0), XMFLOAT2(1, 1) },
{ XMFLOAT3(-width, height, depth), XMFLOAT3(0, 0, 1), XMFLOAT2(1, 0) },
{ XMFLOAT3(width, height, depth), XMFLOAT3(0, 0, 1), XMFLOAT2(0, 0) },
{ XMFLOAT3(-width, -height, depth), XMFLOAT3(0, 0, 1), XMFLOAT2(1, 1) },
{ XMFLOAT3(width, -height, depth), XMFLOAT3(0, 0, 1), XMFLOAT2(0, 1) },
{ XMFLOAT3(-width, -height, depth), XMFLOAT3(0, -1, -0), XMFLOAT2(1, 0) },
{ XMFLOAT3(width, -height, depth), XMFLOAT3(0, -1, -0), XMFLOAT2(1, 1) },
{ XMFLOAT3(-width, -height, -depth), XMFLOAT3(0, -1, -0), XMFLOAT2(0, 0) },
{ XMFLOAT3(width, -height, -depth), XMFLOAT3(0, -1, -0), XMFLOAT2(0, 1) },
{ XMFLOAT3(width, -height, -depth), XMFLOAT3(1, 0, -0), XMFLOAT2(0, 1) },
{ XMFLOAT3(width, -height, depth), XMFLOAT3(1, 0, -0), XMFLOAT2(1, 1) },
{ XMFLOAT3(width, height, -depth), XMFLOAT3(1, 0, -0), XMFLOAT2(0, 0) },
{ XMFLOAT3(width, height, depth), XMFLOAT3(1, 0, -0), XMFLOAT2(1, 0) },
{ XMFLOAT3(-width, -height, depth), XMFLOAT3(-1, 0, -0), XMFLOAT2(0, 1) },
{ XMFLOAT3(-width, -height, -depth), XMFLOAT3(-1, 0, -0), XMFLOAT2(1, 1) },
{ XMFLOAT3(-width, height, depth), XMFLOAT3(-1, 0, -0), XMFLOAT2(0, 0) },
{ XMFLOAT3(-width, height, -depth), XMFLOAT3(-1, 0, -0), XMFLOAT2(1, 0) },
}; m_numOfVertices = ARRAYSIZE(verts);
unsigned short indices[] = {
2, 1, 0, 3, 1, 2, 6, 5, 4, 7, 5, 6, 10, 9, 8, 11, 9, 10, 14, 13, 12, 15, 13, 14, 18, 17, 16, 19, 17, 18, 22, 21, 20, 23, 21, 22,
}; m_numOfIndices = ARRAYSIZE(indices); //36
D3D11_SUBRESOURCE_DATA vertexBufferData = { 0 };
vertexBufferData.pSysMem = verts;
vertexBufferData.SysMemPitch = 0;
vertexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC vertexBufferDesc(sizeof(VertexPNU)*m_numOfVertices, D3D11_BIND_VERTEX_BUFFER);
D3D11_SUBRESOURCE_DATA indexBufferData = { 0 };
indexBufferData.pSysMem = indices;
indexBufferData.SysMemPitch = 0;
indexBufferData.SysMemSlicePitch = 0;
CD3D11_BUFFER_DESC indexBufferDesc(sizeof(unsigned short)*m_numOfIndices, D3D11_BIND_INDEX_BUFFER);
gDevice->CreateBuffer(&vertexBufferDesc, &vertexBufferData, &m_vertexBuffer);
gDevice->CreateBuffer(&indexBufferDesc, &indexBufferData, &m_indexBuffer);
}
void CubeGeo::Draw() {
SetResources();
XMMATRIX tmpWorldMatrix = XMMatrixTranslation(m_pos.x, m_pos.y, m_pos.z);
gContext->UpdateSubresource(gcbPerMesh.Get(), 0, 0, &tmpWorldMatrix, 0, 0);
gContext->DrawIndexed(m_numOfIndices, 0, 0);
}
void CubeGeo::SetResources() {
gDat.SetResources(m_rIds);
UINT stride = sizeof(VertexPNU); // make automatic
UINT offset = 0;
gContext->IASetVertexBuffers(0, 1, m_vertexBuffer.GetAddressOf(), &stride, &offset);
gContext->IASetIndexBuffer(m_indexBuffer.Get(), DXGI_FORMAT_R16_UINT, 0);
}
ScreenQuad::ScreenQuad(){
m_rIds.m_topoID = D3D10_PRIMITIVE_TOPOLOGY_TRIANGLESTRIP;
}
void ScreenQuad::Create(){
float zd = 0.0f;
VertexPU verts [] = {
{XMFLOAT3(-1.0f, 1.0f, 0.0f), XMFLOAT2(0.0f , 1.0f) },
{XMFLOAT3(1.0f, 1.0f, 0.0f), XMFLOAT2(1.0f, 1.0f) },
{XMFLOAT3(-1.0f, -1.0f, 0.0f), XMFLOAT2(0.0f , 0.0f) },
{XMFLOAT3(1.0f, -1.0f, 0.0f), XMFLOAT2(1.0f, 0.0f) },
};
int m_numElements = ARRAYSIZE(verts);
D3D11_BUFFER_DESC bd;
ZeroMemory(&bd, sizeof(bd));
D3D11_SUBRESOURCE_DATA InitData;
ZeroMemory(&InitData, sizeof(InitData));
bd.Usage = D3D11_USAGE_DEFAULT;
bd.ByteWidth = sizeof(VertexPU) * m_numElements;
bd.BindFlags = D3D11_BIND_VERTEX_BUFFER;
InitData.pSysMem = verts;
gDevice->CreateBuffer(&bd, &InitData, &m_vertexBuffer);
}
void ScreenQuad::Draw()
{
}