|
@@ -784,7 +784,35 @@
|
|
|
}
|
|
|
return this;
|
|
|
}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * Rotates the mesh around the axis vector for the passed angle (amount) expressed in radians, in world space.
|
|
|
+ * Note that the property `rotationQuaternion` is then automatically updated and the property `rotation` is set to (0,0,0) and no longer used.
|
|
|
+ * The passed axis is also normalized.
|
|
|
+ * Returns the AbstractMesh.
|
|
|
+ * Method is based on http://www.euclideanspace.com/maths/geometry/affine/aroundPoint/index.htm
|
|
|
+ */
|
|
|
+ public rotateAround(point: Vector3, axis: Vector3, amount: number): AbstractMesh {
|
|
|
+ axis.normalize();
|
|
|
+ if (!this.rotationQuaternion) {
|
|
|
+ this.rotationQuaternion = Quaternion.RotationYawPitchRoll(this.rotation.y, this.rotation.x, this.rotation.z);
|
|
|
+ this.rotation.copyFromFloats(0, 0, 0);
|
|
|
+ }
|
|
|
+ point.subtractToRef(this.position, Tmp.Vector3[0]);
|
|
|
+ Matrix.TranslationToRef(Tmp.Vector3[0].x, Tmp.Vector3[0].y, Tmp.Vector3[0].z, Tmp.Matrix[0]);
|
|
|
+ Tmp.Matrix[0].invertToRef(Tmp.Matrix[2]);
|
|
|
+ Matrix.RotationAxisToRef(axis, amount, Tmp.Matrix[1]);
|
|
|
+ Tmp.Matrix[2].multiplyToRef(Tmp.Matrix[1], Tmp.Matrix[2]);
|
|
|
+ Tmp.Matrix[2].multiplyToRef(Tmp.Matrix[0], Tmp.Matrix[2]);
|
|
|
+
|
|
|
+ Tmp.Matrix[2].decompose(Tmp.Vector3[0], Tmp.Quaternion[0], Tmp.Vector3[1]);
|
|
|
+
|
|
|
+ this.position.addInPlace(Tmp.Vector3[1]);
|
|
|
+ this.rotationQuaternion.multiplyInPlace(Tmp.Quaternion[0]);
|
|
|
|
|
|
+ return this;
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* Translates the mesh along the axis vector for the passed distance in the given space.
|
|
|
* space (default LOCAL) can be either BABYLON.Space.LOCAL, either BABYLON.Space.WORLD.
|