Browse Source

Optimalize sprite.raycast

06wj 7 years ago
parent
commit
2b21dd6023
1 changed files with 8 additions and 3 deletions
  1. 8 3
      src/objects/Sprite.js

+ 8 - 3
src/objects/Sprite.js

@@ -45,9 +45,14 @@ Sprite.prototype = Object.assign( Object.create( Object3D.prototype ), {
 			alignedPosition.set( ( 0.5 - this.center.x ) * worldScale.x, ( 0.5 - this.center.y ) * worldScale.y );
 
 			var rotation = this.material.rotation;
-			rotatedPosition.x = ( Math.cos( rotation ) * alignedPosition.x ) - ( Math.sin( rotation ) * alignedPosition.y );
-			rotatedPosition.y = ( Math.sin( rotation ) * alignedPosition.x ) + ( Math.cos( rotation ) * alignedPosition.y );
-
+			if ( rotation !== 0 ) {
+				var cos = Math.cos( rotation ), sin = Math.sin( rotation );
+				rotatedPosition.x = ( cos * alignedPosition.x ) - ( sin * alignedPosition.y );
+				rotatedPosition.y = ( sin * alignedPosition.x ) + ( cos * alignedPosition.y );
+			} else {
+				rotatedPosition.copy( alignedPosition );
+			}
+			
 			worldPosition.setFromMatrixPosition( this.modelViewMatrix );
 			worldPosition.x += rotatedPosition.x;
 			worldPosition.y += rotatedPosition.y;