mirror of
https://github.com/tengge1/ShadowEditor.git
synced 2026-01-25 15:08:11 +00:00
99 lines
2.0 KiB
Go
99 lines
2.0 KiB
Go
// +build ignore
|
|
|
|
// Copyright 2017-2020 The ShadowEditor Authors. All rights reserved.
|
|
// Use of this source code is governed by a MIT-style
|
|
// license that can be found in the LICENSE file.
|
|
//
|
|
// For more information, please visit: https://github.com/tengge1/ShadowEditor
|
|
// You can also visit: https://gitee.com/tengge1/ShadowEditor
|
|
//
|
|
// This package is translated from three.js, visit `https://github.com/mrdoob/three.js`
|
|
// for more information.
|
|
|
|
package three
|
|
|
|
/**
|
|
* @author bhouston / http://clara.io
|
|
* @author WestLangley / http://github.com/WestLangley
|
|
*
|
|
* Ref: https://en.wikipedia.org/wiki/Spherical_coordinate_system
|
|
*
|
|
* The polar angle (phi) is measured from the positive y-axis. The positive y-axis is up.
|
|
* The azimuthal angle (theta) is measured from the positive z-axis.
|
|
*/
|
|
|
|
function Spherical( radius, phi, theta ) {
|
|
|
|
this.radius = ( radius !== undefined ) ? radius : 1.0;
|
|
this.phi = ( phi !== undefined ) ? phi : 0; // polar angle
|
|
this.theta = ( theta !== undefined ) ? theta : 0; // azimuthal angle
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
Object.assign( Spherical.prototype, {
|
|
|
|
set: function ( radius, phi, theta ) {
|
|
|
|
this.radius = radius;
|
|
this.phi = phi;
|
|
this.theta = theta;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
clone: function () {
|
|
|
|
return new this.constructor().copy( this );
|
|
|
|
},
|
|
|
|
copy: function ( other ) {
|
|
|
|
this.radius = other.radius;
|
|
this.phi = other.phi;
|
|
this.theta = other.theta;
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
// restrict phi to be betwee EPS and PI-EPS
|
|
makeSafe: function () {
|
|
|
|
var EPS = 0.000001;
|
|
this.phi = Math.max( EPS, Math.min( Math.PI - EPS, this.phi ) );
|
|
|
|
return this;
|
|
|
|
},
|
|
|
|
setFromVector3: function ( v ) {
|
|
|
|
return this.setFromCartesianCoords( v.x, v.y, v.z );
|
|
|
|
},
|
|
|
|
setFromCartesianCoords: function ( x, y, z ) {
|
|
|
|
this.radius = Math.sqrt( x * x + y * y + z * z );
|
|
|
|
if ( this.radius === 0 ) {
|
|
|
|
this.theta = 0;
|
|
this.phi = 0;
|
|
|
|
} else {
|
|
|
|
this.theta = Math.atan2( x, z );
|
|
this.phi = Math.acos( MathUtils.clamp( y / this.radius, - 1, 1 ) );
|
|
|
|
}
|
|
|
|
return this;
|
|
|
|
}
|
|
|
|
} ); |