-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathIrisSprite.cpp
More file actions
187 lines (155 loc) · 4.22 KB
/
IrisSprite.cpp
File metadata and controls
187 lines (155 loc) · 4.22 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
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
#include "IrisSprite.h"
#include <cmath>
using namespace Gdiplus;
const double PI = 3.14159;
IrisSprite::IrisSprite(IDirect3DDevice9 *Device){
this->Device = Device;
this->angle = 0.0f;
this->blendType = 0;
this->bushDepth = 0;
this->bushOpacity = 255;
this->mirror = false;
this->opacity = 255;
this->ox = 0.0f;
this->oy = 0.0f;
this->visible = true;
this->waveAmp = 0.0f;
this->waveLength = 0.0f;
this->wavePhase = 0.0f;
this->waveSpeed = 0.0f;
this->x = 0.0f;
this->y = 0.0f;
this->z = 0.0f;
this->zoomX = 1.0f;
this->zoomY = 1.0f;
this->viewport = ModuleIrisGraphics::getGViewport(); // 將不受viewport的控制,需要手工釋放.
this->viewport->addSprite(this);
this->viewport->sortViewports();
}
IrisSprite::IrisSprite(IDirect3DDevice9 *device, IrisViewport *viewport){
this->Device = device;
this->angle = 0.0f;
this->blendType = 0;
this->bushDepth = 0;
this->bushOpacity = 255;
this->mirror = false;
this->opacity = 255;
this->ox = 0.0f;
this->oy = 0.0f;
this->visible = true;
this->waveAmp = 0.0f;
this->waveLength = 0.0f;
this->wavePhase = 0.0f;
this->waveSpeed = 0.0f;
this->x = 0.0f;
this->y = 0.0f;
this->z = 0.0f;
this->zoomX = 1.0f;
this->zoomY = 1.0f;
this->viewport = viewport;
this->viewport->addSprite(this);
this->viewport->sortViewports();
}
void IrisSprite::Dispose(){
this->bitmap->Dispose();
delete this->bitmap;
this->bitmap = NULL;
this->viewport->deleteSprite(this);
this->viewport = NULL;
this->Device = NULL;
}
bool IrisSprite::Disposed(){
if(this->Device == NULL)
return true;
return false;
}
void IrisSprite::AutoDispose(){
this->bitmap->Dispose();
delete this->bitmap;
this->bitmap = NULL;
this->viewport = NULL;
this->Device = NULL;
}
void IrisSprite::Flash(IrisColor *color, int duration){
}
void IrisSprite::Update(){
if(this->visible)
return;
//this->Draw();
}
void IrisSprite::Draw(){
if(this->bitmap == NULL)
return;
if(this->visible == false)
return;
this->bitmap->Draw(255, this->viewport, this->x, this->y);
/*
D3DXMATRIX proj;
Device->SetViewport(&(this->viewport->GetD3DViewport()));
D3DXMatrixOrthoOffCenterLH(&proj, this->viewport->GetX(), this->viewport->GetWidth(), this->viewport->GetHeight(), this->viewport->GetY(), 0.0f, 9999.0f);
Device->SetTransform(D3DTS_PROJECTION, &proj);
*/
//-------------Material && Texture Setting-------------
//this->bitmap->SetOpacity(opacity / 255.0);
//this->Device->SetMaterial(&(this->bitmap->mtrl));
Device->SetTexture(0, this->bitmap->GetTexture());
//-------------Matrix Math-------------
D3DXMATRIX W;
D3DXMatrixIdentity(&W);
Device->SetTransform(D3DTS_WORLD, &W);
Device->SetFVF(Iris2DVertex::FVF);
D3DXMATRIX translationMatrix;
D3DXMATRIX rotationMatrix;
D3DXMATRIX scalingMatrix;
D3DXMATRIX resultMatrix;
D3DXMatrixIdentity(&translationMatrix);
D3DXMatrixIdentity(&rotationMatrix);
D3DXMatrixIdentity(&scalingMatrix);
if(this->angle != 0.0f)
D3DXMatrixRotationZ(&rotationMatrix, this->angle);
D3DXMatrixTranslation(&translationMatrix, this->x, this->y, 0.0f);
if(this->zoomX != 1.0f || this->zoomY != 1.0f)
D3DXMatrixScaling(&scalingMatrix, this->zoomX, this->zoomY, 1.0f);
resultMatrix = rotationMatrix * translationMatrix * scalingMatrix;
Device->SetTransform(D3DTS_WORLD, &resultMatrix);
Device->SetStreamSource(0, this->bitmap->GetVb(), 0, sizeof(Iris2DVertex));
Device->DrawPrimitive(D3DPT_TRIANGLELIST, 0, 2);
}
int IrisSprite::GetWidth(){
if(this->bitmap == NULL)
return 0;
else
return this->bitmap->width;
}
int IrisSprite::GetHeight(){
if(this->bitmap == NULL)
return 0;
else
return this->bitmap->height;
}
void IrisSprite::SetViewport(IrisViewport *tviewport){
this->viewport->deleteSprite(this);
this->viewport = tviewport;
this->viewport->addSprite(this);
}
void IrisSprite::AutoSetViewport(IrisViewport *tviewport){
this->viewport = tviewport;
this->viewport->addSprite(this);
}
IrisViewport* IrisSprite::GetViewport(IrisViewport *tviewport){
return this->viewport;
}
void IrisSprite::SetOpacity(int tOpacity){
this->opacity = tOpacity;
this->bitmap->SetOpacity(this->opacity);
}
int IrisSprite::GetOpacity(){
return this->opacity;
}
IrisSprite::~IrisSprite(void)
{
if(!this->Disposed())
this->Dispose();
if(!this->bitmap->Disposed())
this->bitmap->Dispose();
}