-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathModelController.cpp
126 lines (103 loc) · 2.75 KB
/
ModelController.cpp
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
//=====================================
//
//モデルコントローラ処理[ModelController.cpp]
//Author:GP12B332 21 立花雄太
//
//=====================================
#include "ModelController.h"
/**************************************
マクロ定義
***************************************/
/**************************************
構造体定義
***************************************/
/**************************************
グローバル変数
***************************************/
static LPD3DXMESH mesh[3];
static LPD3DXBUFFER bufMat[3];
static DWORD matNum[3];
static const char* modelName[3] =
{
"data/MODEL/cube00.x",
"data/MODEL/sphere00.x",
"data/MODEL/cube01.x",
};
static D3DXVECTOR3 position[3][50];
static D3DXVECTOR3 rotation[3] = {
D3DXVECTOR3(0.2f, 0.8f, 0.0f),
D3DXVECTOR3(0.0f, 0.8f, 0.0f),
D3DXVECTOR3(0.0f, 0.0f, 0.0f)
};
/**************************************
プロトタイプ宣言
***************************************/
/**************************************
初期化処理
***************************************/
void InitModelController(int num)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
for (int i = 0; i < 3; i++)
{
D3DXLoadMeshFromX(modelName[i], D3DXMESH_SYSTEMMEM, pDevice, NULL, &bufMat[i], NULL, &matNum[i], &mesh[i]);
}
const float offset = 100.0f;
for (int i = 0; i < 3; i++)
{
for (int j = 0; j < 50; j++)
{
position[i][j].x = (i - 1) * offset;
position[i][j].y = -30.0f;
position[i][j].z = j * offset;
}
}
}
/**************************************
終了処理
***************************************/
void UninitModelController(int num)
{
for (int i = 0; i < 3; i++)
{
SAFE_RELEASE(mesh[i]);
SAFE_RELEASE(bufMat[i]);
}
}
/**************************************
更新処理
***************************************/
void UpdateModelController(void)
{
}
/**************************************
描画処理
***************************************/
void DrawModelController(void)
{
LPDIRECT3DDEVICE9 pDevice = GetDevice();
D3DXMATRIX mtxWorld, mtxTranslate, mtxRot;
D3DXMATERIAL *pMaterial;
D3DMATERIAL9 matDef;
pDevice->GetMaterial(&matDef);
pDevice->SetTexture(0, NULL);
for (int i = 0; i < 3; i++)
{
for (int k = 0; k < 50; k++)
{
D3DXMatrixIdentity(&mtxWorld);
D3DXMatrixRotationYawPitchRoll(&mtxRot, rotation[i].y, rotation[i].x, rotation[i].z);
D3DXMatrixMultiply(&mtxWorld, &mtxWorld, &mtxRot);
D3DXMatrixTranslation(&mtxTranslate, position[i][k].x, position[i][k].y, position[i][k].z);
D3DXMatrixMultiply(&mtxWorld, &mtxWorld, &mtxTranslate);
pDevice->SetTransform(D3DTS_WORLD, &mtxWorld);
pMaterial = (D3DXMATERIAL*)bufMat[i]->GetBufferPointer();
for (UINT j = 0; j < matNum[i]; j++)
{
pDevice->SetMaterial(&pMaterial[j].MatD3D);
mesh[i]->DrawSubset(j);
}
}
}
pDevice->SetMaterial(&matDef);
}