/
cube.cpp
98 lines (80 loc) · 1.7 KB
/
cube.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
89
90
91
92
93
94
95
96
97
98
#include <stdlib.h>
#include <iostream>
#include "cube.h"
#include "matrix.h"
#include "point.h"
#include "quaternion.h"
Cube::Cube() {
mat = new Matrix();
data = (Point*) malloc(8*sizeof(Vector3));
for(int i=0; i<8; i++) data[i] = Point();
}
void Cube::apply(Matrix* m) {
for(int i=0; i<8; i++) data[i] *= m;
}
void Cube::reset() {
data[0].set(1,1,1);
data[1].set(1,1,-1);
data[2].set(1,-1,1);
data[3].set(1,-1,-1);
data[4].set(-1,1,1);
data[5].set(-1,1,-1);
data[6].set(-1,-1,1);
data[7].set(-1,-1,-1);
}
void Cube::translateX(float x) {
mat->translateX(x);
Cube::apply(mat);
}
void Cube::translateY(float y) {
mat->translateY(y);
Cube::apply(mat);
}
void Cube::translateZ(float z) {
mat->translateZ(z);
Cube::apply(mat);
}
void Cube::rotateH(float h) {
mat->rotateH(h);
Cube::apply(mat);
}
void Cube::rotateP(float p) {
mat->rotateP(p);
Cube::apply(mat);
}
void Cube::rotateR(float r) {
mat->rotateR(r);
Cube::apply(mat);
}
void Cube::scale(float s) {
mat->scale(s);
Cube::apply(mat);
}
void Cube::translateXYZ(float x, float y, float z) {
mat->translateXYZ(x, y, z);
Cube::apply(mat);
}
void Cube::translateXYZ(Vector3 v) {
Cube::translateXYZ(v.x, v.y, v.z);
}
void Cube::rotateHPR(float h, float p, float r) {
Cube::rotateH(h);
Cube::rotateH(p);
Cube::rotateH(r);
//mat->rotateHPR(h, p, r);
//Cube::apply(mat);
}
void Cube::transformXYZHPRS(float x, float y, float z,
float h, float p, float r, float s) {
Cube::translateXYZ(x,y,z);
Cube::rotateHPR(h,p,r);
Cube::scale(s);
//mat->transformXYZHPRS(x,y,z,h,p,r,s);
//Cube::apply(mat);
}
void Cube::print() {
for(int i=0; i<8; i++) data[i].print();
}
void Cube::printMat() {
mat->print();
}