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
188
189
190
191
192
193
194
195
196
197
198
|
#include "Engine.h"
void CAnimation::CreateSinglePictureAnimation(char* texturepath, int picturewidth, int picturecount, int pictureduration, bool independence, bool autoscale)
{
HRESULT r;
D3DXIMAGE_INFO ImgInfo;
r = D3DXGetImageInfoFromFile(texturepath, &ImgInfo);
if(FAILED(r)) EngineLog.Log("Error in function D3DXGetImageInfoFromFile()", LOG_ERROR);
width = picturewidth;
height = ImgInfo.Height;
count = picturecount-1;
duration = pictureduration;
lastchange = 0;
position = 0;
first = NULL;
last = NULL;
independency = independence;
autoscaling = autoscale;
multipicture = false;
running = false;
scalefactor = 1.0f;
rotationangle = 0;
r = D3DXCreateTextureFromFileEx( CDirect3D::lpD3DDevice,
texturepath,
ImgInfo.Width,
ImgInfo.Height,
1, 0,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0, 0, 0,
&texture);
if(FAILED(r)) EngineLog.Log("Error in function D3DXCreateTextureFromFileEx()", LOG_ERROR);
}
void CAnimation::CreateMultiPictureAnimation(int pictureduration, bool independence, bool autoscale)
{
width = 0;
height = 0;
count = 0;
duration = pictureduration;
lastchange = 0;
position = 0;
first = NULL;
last = NULL;
independency = independence;
autoscaling = autoscale;
multipicture = true;
running = false;
scalefactor = 1.0f;
rotationangle = 0;
}
void CAnimation::AddPicture(char* texturepath)
{
if(multipicture == true)
{
HRESULT r;
D3DXIMAGE_INFO ImgInfo;
r = D3DXGetImageInfoFromFile(texturepath, &ImgInfo);
if(FAILED(r)) EngineLog.Log("Error in function D3DXGetImageInfoFromFile()", LOG_ERROR);
count++;
sTexture* newtexture = new sTexture;
if(first == NULL) { first = newtexture; last = newtexture; }
last->next = newtexture;
newtexture->next = NULL;
r = D3DXCreateTextureFromFileEx( CDirect3D::lpD3DDevice,
texturepath,
ImgInfo.Width,
ImgInfo.Height,
1, 0,
D3DFMT_UNKNOWN,
D3DPOOL_MANAGED,
D3DX_FILTER_NONE,
D3DX_FILTER_NONE,
0, 0, 0,
&newtexture->texture);
if(FAILED(r)) EngineLog.Log("Error in function D3DXCreateTextureFromFileEx()", LOG_ERROR);
}
else EngineLog.Log("You tried to add a new texture to a SinglePictureAnimation", LOG_WARNING);
}
void CAnimation::Show(int coordx, int coordy)
{
HRESULT r;
float x = static_cast<float>(coordx);
float y = static_cast<float>(coordy);
if(independency == true)
{
x = ResolutionWidth/OriginalResolutionWidth * x;
y = ResolutionHeight/OriginalResolutionHeight * y;
}
float asfactorwidth = 1.0f;
float asfactorheight = 1.0f;
if(autoscaling == true)
{
asfactorwidth = ResolutionWidth/OriginalResolutionWidth;
asfactorheight = ResolutionHeight/OriginalResolutionHeight;
}
D3DXVECTOR2 ScalingVector(asfactorwidth*scalefactor, asfactorheight*scalefactor);
D3DXVECTOR2 CenterVector(static_cast<float>(width/2+x), static_cast<float>(height/2+y));
float rotation = rotationangle*D3DX_PI/180;
D3DXMATRIX matrix;
D3DXMatrixTransformation2D( &matrix,
&CenterVector,
0.0f,
&ScalingVector,
&CenterVector,
rotation,
NULL);
CDirect3D::lpSprite->SetTransform(&matrix);
D3DXVECTOR3 PositionVector(x, y, 0.0f);
D3DCOLOR ModulateColor = 0xFFFFFFFF;
int time = timeGetTime();
if(time - lastchange >= duration && running == true)
{
(position == count) ? position = 0 : position++;
lastchange = time;
}
RECT rect;
rect.left = position*width;
rect.top = 0;
rect.right = (position+1)*width-1;
rect.bottom = height;
r = CDirect3D::lpSprite->Begin(D3DXSPRITE_ALPHABLEND);
if(FAILED(r)) EngineLog.Log("Error in function lpSprite::Begin()", LOG_ERROR);
r = CDirect3D::lpSprite->Draw( texture,
&rect,
NULL,
&PositionVector,
ModulateColor);
if(FAILED(r)) EngineLog.Log("Error in function lpSprite::Draw()", LOG_ERROR);
r = CDirect3D::lpSprite->End();
if(FAILED(r)) EngineLog.Log("Error in function lpSprite::End()", LOG_ERROR);
D3DXMATRIX emptymatrix;
r = CDirect3D::lpSprite->SetTransform(D3DXMatrixIdentity(&emptymatrix));
if(FAILED(r)) EngineLog.Log("Error in function lpSprite::SetTransform()", LOG_ERROR);
}
void CAnimation::Scale(float factor)
{
scalefactor *= factor;
}
void CAnimation::SetScale(float factor)
{
scalefactor = factor;
}
void CAnimation::Rotate(int angle)
{
rotationangle += angle;
}
void CAnimation::SetRotation(int angle)
{
rotationangle = angle;
}
void CAnimation::Start()
{
running = true;
}
void CAnimation::Stop()
{
running = false;
}
void CAnimation::Reset()
{
position = 0;
}
|