|
@@ -152,10 +152,8 @@ export class Transform
|
152
|
152
|
*/
|
153
|
153
|
get right(): Vector3
|
154
|
154
|
{
|
155
|
|
- if(this._right === Vector3.ZERO) {
|
156
|
|
- this._right = new Vector3(1, 0, 0)
|
157
|
|
- ._applyRotationQuaternion(this.orientation);
|
158
|
|
- }
|
|
155
|
+ if(this._right === Vector3.ZERO)
|
|
156
|
+ this._right = this._scaleAndRotate(new Vector3(1, 0, 0))._normalize();
|
159
|
157
|
|
160
|
158
|
return this._right;
|
161
|
159
|
}
|
|
@@ -165,10 +163,8 @@ export class Transform
|
165
|
163
|
*/
|
166
|
164
|
get up(): Vector3
|
167
|
165
|
{
|
168
|
|
- if(this._up === Vector3.ZERO) {
|
169
|
|
- this._up = new Vector3(0, 1, 0)
|
170
|
|
- ._applyRotationQuaternion(this.orientation);
|
171
|
|
- }
|
|
166
|
+ if(this._up === Vector3.ZERO)
|
|
167
|
+ this._up = this._scaleAndRotate(new Vector3(0, 1, 0))._normalize();
|
172
|
168
|
|
173
|
169
|
return this._up;
|
174
|
170
|
}
|
|
@@ -181,14 +177,32 @@ export class Transform
|
181
|
177
|
if(this._forward === Vector3.ZERO) {
|
182
|
178
|
// in a right-handed system, the unit forward vector is (0, 0, -1)
|
183
|
179
|
// in a left-handed system, it is (0, 0, 1)
|
184
|
|
- this._forward = new Vector3(0, 0, -1)
|
185
|
|
- ._applyRotationQuaternion(this.orientation);
|
|
180
|
+ this._forward = this._scaleAndRotate(new Vector3(0, 0, -1))._normalize();
|
186
|
181
|
}
|
187
|
182
|
|
188
|
183
|
return this._forward;
|
189
|
184
|
}
|
190
|
185
|
|
191
|
186
|
/**
|
|
187
|
+ * Use this transform to scale and rotate a vector
|
|
188
|
+ * The translation component of the transform is ignored
|
|
189
|
+ * @param v a vector
|
|
190
|
+ * @returns input vector v
|
|
191
|
+ */
|
|
192
|
+ private _scaleAndRotate(v: Vector3): Vector3
|
|
193
|
+ {
|
|
194
|
+ const m = this._matrix.read();
|
|
195
|
+ const h = Math.abs(m[15]) < EPSILON ? Number.NaN : 1 / m[15]; // usually h = 1
|
|
196
|
+ const vx = v.x, vy = v.y, vz = v.z;
|
|
197
|
+
|
|
198
|
+ const x = m[0] * vx + m[4] * vy + m[8] * vz;
|
|
199
|
+ const y = m[1] * vx + m[5] * vy + m[9] * vz;
|
|
200
|
+ const z = m[2] * vx + m[6] * vy + m[10] * vz;
|
|
201
|
+
|
|
202
|
+ return v._set(x * h, y * h, z * h);
|
|
203
|
+ }
|
|
204
|
+
|
|
205
|
+ /**
|
192
|
206
|
* Decompose this transform
|
193
|
207
|
*/
|
194
|
208
|
private _decompose(): void
|