KisaragiLibrary
 
読み取り中…
検索中…
一致する文字列を見つけられません
Transform.hpp
[詳解]
1#pragma once
2
3#include "Const.h"
4#include "Accessor.hpp"
6#include <cmath>
8#include "Matrix2D.hpp"
9
10namespace Kisaragi_Lib
11{
12 /// <summary>
13 /// matrix3x3座標系のラッパークラス
14 /// </summary>
16 {
17 protected:
18
19 //座標の実体
21
22 /// <summary>
23 /// matrixのポジションを扱うラッパークラス
24 /// </summary>
26 {
27 private:
29
30 class PosX
31 {
32 private:
34 public:
35 PosX(Matrix2D* _p) :pMat(_p) {}
36
37 operator double() const
38 {
39 return pMat->Position().x;
40 }
41 };
42
43 class PosY
44 {
45 private:
47 public:
48 PosY(Matrix2D* _p) :pMat(_p) {}
49
50 operator double() const
51 {
52 return pMat->Position().y;
53 }
54 };
55
56
57 public:
59
60 operator Point2D<double>() const
61 {
62 return pMat->Position();
63 }
64
66 {
67 return pMat->Position() + _p;
68 }
69
71 {
72 //回転の影響を受けた移動をする.
73 //*pMat *= Matrix2D::CreateMoveMatrix(_p.x, _p.y);
74
75 //軸に平行な移動をする.
76 pMat->AxisAlignedTranslation(_p.x, _p.y);
77
78 return *this; //operator呼び出し-
79 }
80
82 {
83 return pMat->Position() - _p;
84 }
85
87 {
88 //回転の影響を受けた移動をする.
89 //*pMat *= Matrix2D::CreateMoveMatrix(_p.x, _p.y);
90
91 //軸に平行な移動をする.
92 pMat->AxisAlignedTranslation(-_p.x, -_p.y);
93
94 return *this; //operator呼び出し
95 }
96
98 {
99
100 pMat->SetAxisAlignedTranslation(_p.x, _p.y);
101 return *this; //operator呼び出し
102 }
103
105 {
106 return Point2D<double>(x,y);
107 }
108
111 };
112
113 /// <summary>
114 /// matrixのRotaを扱うラッパークラス.
115 /// </summary>
117 {
118 private:
120
121 class Radian
122 {
123 private:
125 public:
126 Radian(Matrix2D* _p) :pMat(_p) {}
127
128 operator double() const
129 {
130 return pMat->Rotation();
131 }
132 };
133
134 public:
136
137 //0~360で返す.
138 operator double() const
139 {
140 return Math::RadianToDegree(pMat->Rotation());
141 }
142
143 double operator =(double _degree)
144 {
145 *pMat *= pMat->CreateInverseRotaMatrix();
146
147 if (_degree > 360)
148 {
149 _degree = std::fmod(_degree, 360);
150 }
151
152 if (_degree < 0)
153 {
154 _degree = std::fmod(_degree, 360);
155 }
156
158
159 return *this;
160 }
161
162 double operator +=(double _degree)
163 {
164 if (_degree > 360)
165 {
166 _degree = std::fmod(_degree, 360);
167 }
168
169 if (_degree < 0)
170 {
171 _degree = std::fmod(_degree, 360);
172 }
173
175
176 return *this;
177 }
178
179 double operator -=(double _degree)
180 {
181 if (_degree > 360)
182 {
183 _degree = std::fmod(_degree, 360);
184 }
185
186 if (_degree < 0)
187 {
188 _degree = std::fmod(_degree, 360);
189 }
190
192
193 return *this;
194 }
195
197
198
199 };
200
201 /// <summary>
202 /// matrixの拡大率を扱うラッパークラス.
203 /// </summary>
205 {
206 private:
208
209 class ScaleX
210 {
211 private:
213 public:
214 ScaleX(Matrix2D* _p) :pMat(_p) {}
215
216 operator double() const
217 {
218 return pMat->Scale().x;
219 }
220 };
221
222 class ScaleY
223 {
224 private:
226 public:
227 ScaleY(Matrix2D* _p) :pMat(_p) {}
228
229 operator double() const
230 {
231 return pMat->Scale().y;
232 }
233 };
234
235 public:
236 Scale2D(Matrix2D* _p) :pMat(_p) {}
237
238 operator Point2D<double>() const
239 {
240 return pMat->Scale();
241 }
242
244 {
246 return *this; //operator呼び出し
247 }
248
250 {
251 *pMat *= Matrix2D::CreateScaleMatrix(-_p.x, -_p.y);
252 return *this; //operator呼び出し
253 }
254
256 {
257 //移動打消し.
258 *pMat *= pMat->CreateInverseScaleMatrix();
259 //移動
261 return *this; //operator呼び出し
262 }
263
266 };
267
268 //親座標
270
271 //デフォルトの親座標
272 static Transform2D world; //世界座標
273
274 public:
278
279 bool isWorld = false;
280
282 {
283 pearent = &world;
284 }
285
286 Transform2D(bool _isWorld) : isWorld(_isWorld)
287 {
288
289 }
290
291 void SetPearent(Transform2D* _pearent)
292 {
293 pearent = _pearent;
294 }
295
296 //matirxとして扱うときの変換
297 operator Matrix2D()
298 {
299 if (isWorld)
300 {
301 return mat;
302 }
303
304 return ((Matrix2D)*pearent * mat);
305 }
306
308 {
309 mat *= _mat;
310 return mat;
311 }
312
313#pragma region 要素アクセス子
315 {
316 return mat;
317 }
318#pragma endregion
319 };
320}
独自のMathを提供します
図形の形状を表すためのクラスを提供するヘッダ
static double DegreeToRadian(const double &_degree)
角度をラジアン値に変換する.
Definition KisaragiMath.hpp:57
static double RadianToDegree(const double &_radian)
ラジアン値を角度に変換する.
Definition KisaragiMath.hpp:47
Definition Matrix2D.hpp:24
Matrix2D CreateRotaMatrix()
Definition Matrix2D.hpp:226
Matrix2D CreateScaleMatrix()
Definition Matrix2D.hpp:274
Matrix2D * pMat
Definition Transform.hpp:33
PosX(Matrix2D *_p)
Definition Transform.hpp:35
PosY(Matrix2D *_p)
Definition Transform.hpp:48
Matrix2D * pMat
Definition Transform.hpp:46
matrixのポジションを扱うラッパークラス
Definition Transform.hpp:26
Point2D< double > operator-(Point2D< double > _p)
Definition Transform.hpp:81
PosX x
Definition Transform.hpp:109
Point2D< double > operator=(Point2D< double > _p)
Definition Transform.hpp:97
Matrix2D * pMat
Definition Transform.hpp:28
PosY y
Definition Transform.hpp:110
Point2D< double > operator+(Point2D< double > _p)
Definition Transform.hpp:65
Position2D(Matrix2D *_p)
Definition Transform.hpp:58
Point2D< double > operator-=(Point2D< double > _p)
Definition Transform.hpp:86
Point2D< double > operator+=(Point2D< double > _p)
Definition Transform.hpp:70
Radian(Matrix2D *_p)
Definition Transform.hpp:126
Matrix2D * pMat
Definition Transform.hpp:124
matrixのRotaを扱うラッパークラス.
Definition Transform.hpp:117
Matrix2D * pMat
Definition Transform.hpp:119
double operator-=(double _degree)
Definition Transform.hpp:179
Rotation2D(Matrix2D *_p)
Definition Transform.hpp:135
double operator=(double _degree)
Definition Transform.hpp:143
double operator+=(double _degree)
Definition Transform.hpp:162
Radian radian
Definition Transform.hpp:196
Definition Transform.hpp:210
Matrix2D * pMat
Definition Transform.hpp:212
ScaleX(Matrix2D *_p)
Definition Transform.hpp:214
Definition Transform.hpp:223
ScaleY(Matrix2D *_p)
Definition Transform.hpp:227
Matrix2D * pMat
Definition Transform.hpp:225
matrixの拡大率を扱うラッパークラス.
Definition Transform.hpp:205
Point2D< double > operator+=(Point2D< double > _p)
Definition Transform.hpp:243
Point2D< double > operator=(Point2D< double > _p)
Definition Transform.hpp:255
Matrix2D * pMat
Definition Transform.hpp:207
Point2D< double > operator-=(Point2D< double > _p)
Definition Transform.hpp:249
ScaleY y
Definition Transform.hpp:265
ScaleX x
Definition Transform.hpp:264
Scale2D(Matrix2D *_p)
Definition Transform.hpp:236
static Transform2D world
Definition Transform.hpp:272
Matrix2D mat
Definition Transform.hpp:20
void SetPearent(Transform2D *_pearent)
Definition Transform.hpp:291
Position2D position
Definition Transform.hpp:275
const Matrix2D & operator*=(Matrix2D _mat)
Definition Transform.hpp:307
Rotation2D rotation
Definition Transform.hpp:276
Transform2D * pearent
Definition Transform.hpp:269
const Matrix2D & operator->()
Definition Transform.hpp:314
bool isWorld
Definition Transform.hpp:279
Transform2D()
Definition Transform.hpp:281
Scale2D scale
Definition Transform.hpp:277
Transform2D(bool _isWorld)
Definition Transform.hpp:286
Definition Accessor.hpp:110
@ IDENTITY_MATRIX
Definition Matrix2D.hpp:19
点を表すプリミティブ型
Definition Primitive.hpp:29
T y
Definition Primitive.hpp:30
T x
Definition Primitive.hpp:30