-
Notifications
You must be signed in to change notification settings - Fork 1
/
SceneObject.js
157 lines (129 loc) · 2.89 KB
/
SceneObject.js
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
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
const INV_RAD = 180 / Math.PI;
export class SceneObject {
set dirty(value) {
this._dirty = value;
}
set rotationDirty(value) {
this._rotationDirty = value;
if (value) {
this._dirty = true;
}
}
get x() {
return this._translateVec[0];
}
set x(value) {
if (this._translateVec[0] !== value) {
this._translateVec[0] = value;
this._dirty = true;
}
}
get y() {
return this._translateVec[1];
}
set y(value) {
if (this._translateVec[1] !== value) {
this._translateVec[1] = value;
this._dirty = true;
}
}
get z() {
return this._translateVec[2];
}
set z(value) {
if (this._translateVec[2] !== value) {
this._translateVec[2] = value;
this._dirty = true;
}
}
get translate() {
return this._translateVec;
}
get scaleX() {
return this._scaleVec[0];
}
set scaleX(value) {
if (this._scaleVec[0] !== value) {
this._scaleVec[0] = value;
this._dirty = true;
}
}
get scaleY() {
return this._scaleVec[1];
}
set scaleY(value) {
if (this._scaleVec[1] !== value) {
this._scaleVec[1] = value;
this._dirty = true;
}
}
get scaleZ() {
return this._scaleVec[2];
}
set scaleZ(value) {
if (this._scaleVec[2] !== value) {
this._scaleVec[2] = value;
this._dirty = true;
}
}
get scale() {
return this._scaleVec;
}
get rotationX() {
return this._rotationX;
}
set rotationX(value) {
if (this._rotationX !== value) {
this._rotationX = value;
this._rotationDirty = true;
this._dirty = true;
}
}
get rotationY() {
return this._rotationY;
}
set rotationY(value) {
if (this._rotationY !== value) {
this._rotationY = value;
this._rotationDirty = true;
this._dirty = true;
}
}
get rotationZ() {
return this._rotationZ;
}
set rotationZ(value) {
if (this._rotationZ !== value) {
this._rotationZ = value;
this._rotationDirty = true;
this._dirty = true;
}
}
get quaternion() {
return this._quat;
}
constructor() {
this._mMatrix = mat4.identity(mat4.create());
this._translateVec = vec3.create();
this._scaleVec = vec3.create();
this._quat = quat.create();
this._dirty = true;
this._rotationDirty = true;
vec3.set(this._translateVec, 0.0, 0.0, 0.0);
vec3.set(this._scaleVec, 1.0, 1.0, 1.0);
this._rotationX = 0.0;
this._rotationY = 0.0;
this._rotationZ = 0.0;
}
getModelMatrix() {
if (this._dirty) {
this._dirty = false;
if (this._rotationDirty) {
this._rotationDirty = false;
quat.fromEuler(this._quat, this._rotationX * INV_RAD, this._rotationY * INV_RAD, this._rotationZ * INV_RAD);
}
mat4.fromRotationTranslationScale(this._mMatrix, this._quat, this._translateVec, this._scaleVec);
}
return this._mMatrix;
}
}