-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathimage.cpp
More file actions
244 lines (203 loc) · 10.1 KB
/
image.cpp
File metadata and controls
244 lines (203 loc) · 10.1 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
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
#include "stdafx.h"
#include "image.h"
/********************************************************************************
## image ##
@@ ID2D1Bitmap* bitmap : ImageManager에서 생성된 비트맵
@@ TagLoadImageInfo loadinfo : 이미지 정보(키값,파일 경로)
프레임이미지가 아닌 이미지 클래스 생성
*********************************************************************************/
image::image(ID2D1Bitmap * const bitmap, const TagLoadedImageInfo & loadinfo)
:mBitmap(bitmap), mLoadInfo(loadinfo), mScale(1.f), mAlpha(1.f), mAngle(0.f), mMaxFrameX(1), mMaxFrameY(1)
{
this->mSize.x = (float)this->mBitmap->GetPixelSize().width;
this->mSize.y = (float)this->mBitmap->GetPixelSize().height;
FrameRect rc;
rc.x = 0;
rc.y = 0;
rc.width = mSize.x;
rc.height = mSize.y;
this->mFrameInfo.push_back(rc);
this->ResetRenderOption();
}
/********************************************************************************
## image ##
@@ ID2D1Bitmap* bitmap : ImageManager에서 생성된 비트맵
@@ TagLoadImageInfo loadinfo : 이미지 정보(키값,파일 경로)
@@ int maxFrameX : 가로 프레임 수
@@ int maxFrameY : 세로 프레임 수
프레임 이미지 클래스 생성
*********************************************************************************/
image::image(ID2D1Bitmap *const bitmap, const TagLoadedImageInfo & loadinfo, const int maxFrameX, const int maxFrameY)
:mBitmap(bitmap), mLoadInfo(loadinfo), mMaxFrameX(maxFrameX), mMaxFrameY(maxFrameY), mScale(1.f), mAlpha(1.f), mAngle(0.f)
{
this->mSize.x = (float)mBitmap->GetPixelSize().width;
this->mSize.y = (float)mBitmap->GetPixelSize().height;
float frameX = mSize.x / (float)this->mMaxFrameX;
float frameY = mSize.y / (float)this->mMaxFrameY;
FrameRect rc;
for (int j = 0; j < maxFrameY; ++j)
{
for (int i = 0; i < maxFrameX; ++i)
{
rc.x = (float)i * (frameX);
rc.y = (float)j * (frameY);
rc.width = frameX;
rc.height = frameY;
this->mFrameInfo.push_back(rc);
}
}
this->ResetRenderOption();
}
/********************************************************************************
## ~image ##
비트맵 해제
*********************************************************************************/
image::~image()
{
NEW_SAFE_RELEASE(mBitmap);
}
/********************************************************************************
## PerfeactRender ##
*********************************************************************************/
void image::render(const Vector2& position)
{
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale , mScale , D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, size.y / 2.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x, position.y);//(position.x - size.x / 2.f, position.y - size.y / 2.f ); // 중점 ??
D2D1_RECT_F dxArea = D2D1::RectF(0.f, 0.f, mSize.x, mSize.y);
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha);
ResetRenderOption();
}
void image::render(const Vector2 & position, float scale)
{
mScale = scale;
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, size.y / 2.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x, position.y);//(position.x - size.x / 2.f, position.y - size.y / 2.f ); // 중점 ??
D2D1_RECT_F dxArea = D2D1::RectF(0.f, 0.f, mSize.x, mSize.y);
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha);
ResetRenderOption();
}
void image::topRender(const Vector2 & position)
{
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, 0.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x, position.y);//(position.x - size.x / 2.f, position.y - size.y / 2.f ); // 중점 ??
D2D1_RECT_F dxArea = D2D1::RectF(0.f, 0.f, mSize.x, mSize.y);
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha);
ResetRenderOption();
}
void image::aniRender(const Vector2& position, animation* ani, float scale)
{
Vector2 tempFrameSize;
tempFrameSize.x = ani->getFrameWidth();
tempFrameSize.y = ani->getFrameHeight();
Vector2 size = tempFrameSize * scale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(scale, scale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, size.y / 2.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation((position.x - size.x / 2.f), (position.y - size.y / 2.f));//(position.x - size.x / 2.f, position.y - size.y / 2.f ); // 중점 ??
D2D1_RECT_F dxArea = D2D1::RectF(0.0f, 0.0f, mSize.x, mSize.y);
D2D1_RECT_F dxSrc = D2D1::RectF((float)ani->getFramePos().x, (float)ani->getFramePos().y,
(float)(ani->getFramePos().x + tempFrameSize.x),
(float)(ani->getFramePos().y + tempFrameSize.y));
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha, D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &dxSrc);
ResetRenderOption();
}
/********************************************************************************
## PerfeactFrameRender ##
*********************************************************************************/
void image::frameRender(const Vector2& position, const int frameX, const int frameY)
{
//현재 프레임인덱스
int frame = frameY * mMaxFrameX + frameX;
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, size.y / 2.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation((position.x - size.x / 2.f), (position.y - size.y / 2.f));
//그릴 영역 세팅
D2D1_RECT_F dxArea = D2D1::RectF(0.0f, 0.0f, mSize.x, mSize.y);
D2D1_RECT_F dxSrc = D2D1::RectF((float)mFrameInfo[frame].x, (float)mFrameInfo[frame].y,
(float)(mFrameInfo[frame].x + mFrameInfo[frame].width),
(float)(mFrameInfo[frame].y + mFrameInfo[frame].height));
//최종행렬 세팅
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
//렌더링 요청
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha,
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &dxSrc);
this->ResetRenderOption();
}
void image::frameTopRender(const Vector2 & position, const int frameX, const int frameY)
{
//Vector2 size = mSize * mScale;
//D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
//D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, 0.f));
//D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x, position.y);//(position.x - size.x / 2.f, position.y - size.y / 2.f ); // 중점 ??
//D2D1_RECT_F dxArea = D2D1::RectF(0.f, 0.f, mSize.x, mSize.y);
//D2DRenderer::GetInstance()->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
//D2DRenderer::GetInstance()->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha);
//ResetRenderOption();
//현재 프레임인덱스
int frame = frameY * mMaxFrameX + frameX;
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, 0.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x - size.x / 2.f, position.y - size.y / 2.f);
//그릴 영역 세팅
D2D1_RECT_F dxArea = D2D1::RectF(0.0f, 0.0f, mSize.x, mSize.y);
D2D1_RECT_F dxSrc = D2D1::RectF((float)mFrameInfo[frame].x, (float)mFrameInfo[frame].y,
(float)(mFrameInfo[frame].x + mFrameInfo[frame].width),
(float)(mFrameInfo[frame].y + mFrameInfo[frame].height));
//최종행렬 세팅
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
//렌더링 요청
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha,
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &dxSrc);
this->ResetRenderOption();
}
void image::frameRender(const Vector2 & position, const int frameX, const int frameY, float scale)
{//현재 프레임인덱스
int frame = frameY * mMaxFrameX + frameX;
mScale = scale;
Vector2 size = mSize * mScale;
D2D1::Matrix3x2F scaleMatrix = D2D1::Matrix3x2F::Scale(mScale, mScale, D2D1::Point2F(0, 0));
D2D1::Matrix3x2F rotateMatrix = D2D1::Matrix3x2F::Rotation(mAngle, D2D1::Point2F(size.x / 2.f, size.y / 2.f));
D2D1::Matrix3x2F translateMatrix = D2D1::Matrix3x2F::Translation(position.x - size.x / 2.f, position.y - size.y / 2.f);
//그릴 영역 세팅
D2D1_RECT_F dxArea = D2D1::RectF(0.0f, 0.0f, mSize.x, mSize.y);
D2D1_RECT_F dxSrc = D2D1::RectF((float)mFrameInfo[frame].x, (float)mFrameInfo[frame].y,
(float)(mFrameInfo[frame].x + mFrameInfo[frame].width),
(float)(mFrameInfo[frame].y + mFrameInfo[frame].height));
//최종행렬 세팅
D2DRENDERER->GetRenderTarget()->SetTransform(scaleMatrix * rotateMatrix * translateMatrix);
//렌더링 요청
D2DRENDERER->GetRenderTarget()->DrawBitmap(mBitmap, dxArea, mAlpha,
D2D1_BITMAP_INTERPOLATION_MODE_NEAREST_NEIGHBOR, &dxSrc);
this->ResetRenderOption();
}
/********************************************************************************
## ResetRenderOption ##
이미지 클래스 렌더 관련 옵션들 전부 초기화
*********************************************************************************/
void image::ResetRenderOption()
{
this->mAlpha = 1.0f;
this->mScale = 1.0f;
this->mAngle = 0.f;
if (mFrameInfo.size() <= 1)
{
this->mSize.x = (float)mBitmap->GetPixelSize().width;
this->mSize.y = (float)mBitmap->GetPixelSize().height;
}
else
{
this->mSize.x = mFrameInfo[0].width;
this->mSize.y = mFrameInfo[0].height;
}
}