-
Notifications
You must be signed in to change notification settings - Fork 3
/
util.cpp
88 lines (72 loc) · 1.72 KB
/
util.cpp
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
#ifdef _WIN32
#include <windows.h>
#endif
#include <GL/gl.h>
#include "util.h"
static void convert3to4(const Matrix3f& M, GLfloat *dest)
{
const float *e = M.getElements();
dest[ 0] = e[0]; dest[ 1] = e[1]; dest[ 2] = e[2]; dest[ 3] = 0;
dest[ 4] = e[3]; dest[ 5] = e[4]; dest[ 6] = e[5]; dest[ 7] = 0;
dest[ 8] = e[6]; dest[ 9] = e[7]; dest[10] = e[8]; dest[11] = 0;
dest[12] = 0; dest[13] = 0; dest[14] = 0; dest[15] = 1;
}
namespace vm
{
void loadMatrix(const Matrix3f& M3)
{
GLfloat M4[16];
convert3to4(M3, M4);
glLoadMatrixf(M4);
}
void loadMatrix(const Matrix4f& M)
{
glLoadMatrixf(M.getElements());
}
void multMatrix(const Matrix3f& M3)
{
GLfloat M4[16];
convert3to4(M3, M4);
glMultMatrixf(M4);
}
void multMatrix(const Matrix4f& M)
{
glMultMatrixf(M.getElements());
}
void pushMatrix(const Matrix3f& M3)
{
GLfloat M4[16];
convert3to4(M3, M4);
glPushMatrix();
glMultMatrixf(M4);
}
void pushMatrix(const Matrix4f& M)
{
glPushMatrix();
glMultMatrixf(M.getElements());
}
void normal(const Vector3f& v)
{
glNormal3fv(v.getElements());
}
void normal(const Vector4f& v)
{
glNormal3fv(v.getElements());
}
void vertex(const Vector2f& v)
{
glVertex2fv(v.getElements());
}
void vertex(const Vector3f& v)
{
glVertex3fv(v.getElements());
}
void vertex(const Vector4f& v)
{
glVertex4fv(v.getElements());
}
void vertex3(const Vector4f& v)
{
glVertex3fv(v.getElements());
}
}