-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShape.cpp
More file actions
89 lines (72 loc) · 1.84 KB
/
Shape.cpp
File metadata and controls
89 lines (72 loc) · 1.84 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
#include "Shape.hpp"
#include <stdio.h>
Shape::Shape() {
MC.mat[0][0] = 1.0; MC.mat[0][1] = 0.0; MC.mat[0][2] = 0.0; MC.mat[0][3] = 0.0;
MC.mat[1][0] = 0.0; MC.mat[1][1] = 1.0; MC.mat[1][2] = 0.0; MC.mat[1][3] = 0.0;
MC.mat[2][0] = 0.0; MC.mat[2][1] = 0.0; MC.mat[2][2] = 1.0; MC.mat[2][3] = 0.0;
MC.mat[3][0] = 0.0; MC.mat[3][1] = 0.0; MC.mat[3][2] = 0.0; MC.mat[3][3] = 1.0;
s = 1;
}
Shape::~Shape() { };
Matrix Shape::getMC() {
return MC;
};
void Shape::translate(GLfloat tx, GLfloat ty, GLfloat tz) {
MC.translate(tx, ty, tz);
}
void Shape::rotate(GLfloat rx, GLfloat ry, GLfloat rz, GLfloat angle) {
MC.rotate(rx, ry, rz, angle);
}
void Shape::rotate_mc(GLfloat rx, GLfloat ry, GLfloat rz, GLfloat angle) {
GLfloat x,y,z;
x=MC.mat[0][3];
y=MC.mat[1][3];
z=MC.mat[2][3];
MC.rotate(rx,ry,rz,angle);
MC.mat[0][3]=x;
MC.mat[1][3]=y;
MC.mat[2][3]=z;
MC.normalize();
}
void Shape::rotate_origin(GLfloat rx, GLfloat ry, GLfloat rz, GLfloat angle) {
Matrix* m = new Matrix();
m->rotate(rx, ry, rz, angle);
GLfloat v[4];
v[0] = MC.mat[0][3];
v[1] = MC.mat[1][3];
v[2] = MC.mat[2][3];
v[3] = MC.mat[3][3];
m->multiply_vector(v);
MC.mat[0][3] = v[0];
MC.mat[1][3] = v[1];
MC.mat[2][3] = v[2];
MC.mat[3][3] = v[3];
MC.normalize();
delete m;
}
void Shape::scale_change(GLfloat x) {
s += x;
}
/**
* Shape::ctm_multiply() multiply this matrix to openGL current matrix
*/
void Shape::ctm_multiply() {
GLfloat M[16];
M[0] = MC.mat[0][0];
M[1] = MC.mat[1][0];
M[2] = MC.mat[2][0];
M[3] = 0;
M[4] = MC.mat[0][1];
M[5] = MC.mat[1][1];
M[6] = MC.mat[2][1];
M[7] = 0;
M[8] = MC.mat[0][2];
M[9] = MC.mat[1][2];
M[10] = MC.mat[2][2];
M[11] = 0;
M[12] = MC.mat[0][3];
M[13] = MC.mat[1][3];
M[14] = MC.mat[2][3];
M[15] = 1;
glMultMatrixf(M);
}