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
|
#include "transform.h"
namespace JinEngine
{
namespace Math
{
Transform::Transform()
: mScale(1, 1)
, mPosition(0, 0)
, mOrigin(0, 0)
, mRotation(0)
{
}
Transform::Transform(float x, float y, float sx, float sy, float r, float ox, float oy)
{
set(x, y, sx, sy, r, ox, oy);
}
void Transform::set(float x, float y, float sx, float sy, float r, float ox, float oy)
{
setPosition(x, y);
setScale(sx, sy);
setRotation(r);
setOrigin(ox, oy);
}
void Transform::setScale(float sx, float sy)
{
mScale.set(sx, sy);
}
Vector2<float> Transform::getScale() const
{
return mScale;
}
void Transform::scale(float sx, float sy)
{
mScale.x() *= sx;
mScale.y() *= sy;
}
void Transform::setPosition(const Vector2<float>& p)
{
setPosition(p.x(), p.y());
}
void Transform::setPosition(float x, float y)
{
mPosition.set(x, y);
}
Vector2<float> Transform::getPosition() const
{
return mPosition;
}
void Transform::move(float x, float y)
{
mPosition.x() += x;
mPosition.y() += y;
}
void Transform::move(const Vector2<float>& v)
{
move(v.x(), v.y());
}
void Transform::setOrigin(float x, float y)
{
mOrigin.set(x, y);
}
Vector2<float> Transform::getOrigin() const
{
return mOrigin;
}
void Transform::setRotation(float r)
{
mRotation = r;
}
float Transform::getRotation() const
{
return mRotation;
}
void Transform::rotate(float r)
{
mRotation += r;
}
Matrix Transform::getMatrix() const
{
Matrix m;
m.setTransformation(mPosition.x(), mPosition.y(), mRotation, mScale.x(), mScale.y(), mOrigin.x(), mOrigin.y());
return m;
}
}
}
|