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
|
#define OGL2D_IMPLEMENT
#include "je_gl.h"
#include "je_color.h"
using namespace JinEngine::Math;
namespace JinEngine
{
namespace Graphics
{
OpenGL gl;
OpenGL::OpenGL()
: ogl2d::OpenGL()
{
mModelViewMatrices.push_back(Matrix());
solve();
}
void OpenGL::setColor(Channel r, Channel g, Channel b, Channel a)
{
setColor(Color(r, g, b, a));
}
void OpenGL::setColor(Color c)
{
mCurrentColor = c;
glColor4f(c.r / 255.f, c.g / 255.f, c.b / 255.f, c.a / 255.f);
}
Color OpenGL::getColor()
{
return mCurrentColor;
}
void OpenGL::clearMatrix()
{
mModelViewMatrices.clear();
mModelViewMatrices.push_back(Matrix());
mModelViewMatrix.setIdentity();
}
void OpenGL::push()
{
mModelViewMatrices.push_back(Matrix());
}
void OpenGL::pop()
{
if (mModelViewMatrices.size() == 1)
return;
mModelViewMatrices.pop_back();
solve();
}
void OpenGL::solve()
{
mModelViewMatrix.setIdentity();
for (Matrix& m : mModelViewMatrices)
mModelViewMatrix *= m;
}
void OpenGL::translate(float x, float y)
{
if (mModelViewMatrices.size() == 1)
return;
Matrix& m = mModelViewMatrices.back();
m.translate(x, y);
mModelViewMatrix.translate(x, y);
}
void OpenGL::scale(float sx, float sy)
{
if (mModelViewMatrices.size() == 1)
return;
Matrix& m = mModelViewMatrices.back();
m.scale(sx, sy);
mModelViewMatrix.scale(sx, sy);
}
void OpenGL::rotate(float r)
{
if (mModelViewMatrices.size() == 1)
return;
Matrix& m = mModelViewMatrices.back();
m.rotate(r);
mModelViewMatrix.rotate(r);
}
Matrix OpenGL::getModelViewMatrix(float x, float y, float sx, float sy, float r, float ox, float oy)
{
Matrix m;
m.setTransformation(x, y, sx, sy, r, ox, oy);
return mModelViewMatrix*m;
}
Matrix OpenGL::getModelViewMatrix()
{
return mModelViewMatrix;
}
const Matrix& OpenGL::getProjectionMatrix()
{
return mProjectionMatrix;
}
void OpenGL::setProjectionMatrix(float l, float r, float b, float t, float n, float f)
{
mProjectionMatrix.setOrtho(l, r, b, t, n, f);
}
} // namespace Graphics
} // namespace JinEngine
|