Przeglądaj źródła

add rotateOnWorldAxis method to Object3D

MichaelHazani 7 lat temu
rodzic
commit
65ea3db93a
2 zmienionych plików z 29 dodań i 0 usunięć
  1. 9 0
      docs/api/core/Object3D.html
  2. 20 0
      src/core/Object3D.js

+ 9 - 0
docs/api/core/Object3D.html

@@ -320,6 +320,15 @@
 		Rotate an object along an axis in object space. The axis is assumed to be normalized.
 		Rotate an object along an axis in object space. The axis is assumed to be normalized.
 		</div>
 		</div>
 
 
+		<h3>[method:Object3D rotateOnWorldAxis]( [page:Vector3 axis], [page:Float angle] )</h3>
+		<div>
+		axis -- A normalized vector in world space. <br />
+		angle -- The angle in radians.<br /><br />
+
+		Rotate an object along an axis in world space. The axis is assumed to be normalized.
+		Method Assumes no rotated parent.
+		</div>
+
 		<h3>[method:null rotateX]( [page:Float rad] )</h3>
 		<h3>[method:null rotateX]( [page:Float rad] )</h3>
 		<div>
 		<div>
 		rad - the angle to rotate in radians.<br /><br />
 		rad - the angle to rotate in radians.<br /><br />

+ 20 - 0
src/core/Object3D.js

@@ -170,6 +170,26 @@ Object.assign( Object3D.prototype, EventDispatcher.prototype, {
 
 
 	}(),
 	}(),
 
 
+	rotateOnWorldAxis: function () {
+		
+		// rotate object on axis in world space
+		// axis is assumed to be normalized
+		// method assumes no rotated parent
+
+		var q1 = new Quaternion();
+		
+		return function rotateOnWorldAxis(axis, angle) {
+		
+			q1.setFromAxisAngle(axis, angle);
+		
+			this.quaternion.premultiply(q1);
+		
+			return this;
+		
+		};
+		
+	}(),
+
 	rotateX: function () {
 	rotateX: function () {
 
 
 		var v1 = new Vector3( 1, 0, 0 );
 		var v1 = new Vector3( 1, 0, 0 );