Переглянути джерело

Add rotation (optional) to THREE.EllipseCurve.

neko1235 10 роки тому
батько
коміт
26e3f30e38
1 змінених файлів з 16 додано та 5 видалено
  1. 16 5
      src/extras/curves/EllipseCurve.js

+ 16 - 5
src/extras/curves/EllipseCurve.js

@@ -2,7 +2,7 @@
  *	Ellipse curve
  **************************************************************/
 
-THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise ) {
+THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle, aClockwise, aRotation ) {
 
 	this.aX = aX;
 	this.aY = aY;
@@ -14,6 +14,8 @@ THREE.EllipseCurve = function ( aX, aY, xRadius, yRadius, aStartAngle, aEndAngle
 	this.aEndAngle = aEndAngle;
 
 	this.aClockwise = aClockwise;
+	
+	this.aRotation = aRotation || 0;
 
 };
 
@@ -39,11 +41,20 @@ THREE.EllipseCurve.prototype.getPoint = function ( t ) {
 
 	}
 	
-	var vector = new THREE.Vector2();
+	var x = this.aX + this.xRadius * Math.cos( angle );
+	var y = this.aY + this.yRadius * Math.sin( angle );
+
+	if ( this.aRotation ) {
+
+		var cos = Math.cos( this.aRotation );
+		var sin = Math.sin( this.aRotation );
 
-	vector.x = this.aX + this.xRadius * Math.cos( angle );
-	vector.y = this.aY + this.yRadius * Math.sin( angle );
+		// Rotate the point about the center of the ellipse.
+		x = ( x - this.aX ) * cos - ( y - this.aY ) * sin + this.aX;
+		y = ( x - this.aX ) * sin + ( y - this.aY ) * cos + this.aY;
+
+	}
 
-	return vector;
+	return new THREE.Vector2( x, y );
 
 };