Skip to content

Commit

Permalink
simple rotation calcs cleanup
Browse files Browse the repository at this point in the history
  • Loading branch information
Paul Elliott committed Oct 6, 2020
1 parent 195d6f8 commit a406f36
Showing 1 changed file with 22 additions and 26 deletions.
48 changes: 22 additions & 26 deletions SpinControls.js
Original file line number Diff line number Diff line change
Expand Up @@ -206,8 +206,8 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) {
var getPointerInSphere = ( function () {

var point = new THREE.Vector3(),
objPos = new THREE.Vector3();
objEdgePos = new THREE.Vector3();
objPos = new THREE.Vector3(),
objEdgePos = new THREE.Vector3(),
objToPointer = new THREE.Vector2();

return function getPointerInSphere( ndc ) {
Expand All @@ -221,7 +221,7 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) {
objToPointer.set(objPos.x, objPos.y);
objToPointer.subVectors(ndc, objToPointer);

// scale by object screen size
// Scale by object screen size
radiusObjWorld = _this.trackballRadius;
objEdgePos.setFromMatrixPosition(_this.object.matrixWorld);
var offset = new THREE.Vector3().set(radiusObjWorld, 0, 0);
Expand All @@ -234,40 +234,36 @@ var SpinControls = function ( object, trackBallRadius, camera, domElement ) {
objPos.z = 0;
var objRadiusNDC = objEdgePos.distanceTo(objPos);
objToPointer.x = objToPointer.x * (1 / objRadiusNDC)
if(_this.camera.aspect) { // Perspective or Orthographic
objToPointer.y = (objToPointer.y * (1 / objRadiusNDC) ) / _this.camera.aspect;
}
else {
objToPointer.y = objToPointer.y * (1 / objRadiusNDC) ;
objToPointer.y = (objToPointer.y * (1 / objRadiusNDC) )
if(_this.camera.aspect) { // if Perspective camera
objToPointer.y /= _this.camera.aspect;
}

var t = objToPointer.lengthSq();
console.log(t)

// Shoemake pointer mapping
if (t < 1.0) {
point.set(objToPointer.x, objToPointer.y, Math.sqrt(1.0 - t));
}
else {
objToPointer.normalize();
point.set(objToPointer.x, objToPointer.y, 0.0);
}

// Holroyd pointer mapping
// if (t < 0.5) {
// if (t < 1.0) {
// point.set(objToPointer.x, objToPointer.y, Math.sqrt(1.0 - t));
// }
// else {
// point.set(objToPointer.x, objToPointer.y, 1.0 / (2.0 * Math.sqrt(t)));
// point.normalize();
// objToPointer.normalize();
// point.set(objToPointer.x, objToPointer.y, 0.0);
// }

// Azimuthal equidistant
// t = (Math.PI / 2.0) * ndc.length();
// var v3 = ndc.clone();
// Holroyd pointer mapping
if (t < 0.5) {
point.set(objToPointer.x, objToPointer.y, Math.sqrt(1.0 - t));
}
else {
point.set(objToPointer.x, objToPointer.y, 1.0 / (2.0 * Math.sqrt(t)));
point.normalize();
}

// Azimuthal equidistant pointer mapping
// t = (Math.PI / 2.0) * objToPointer.length();
// var sined = t < Number.EPSILON ? 1.0 : Math.sin(t) / t;
// v3.multiplyScalar((Math.PI / 2.0) * sined);
// point.set(v3.x, v3.y, Math.cos(t));
// objToPointer.multiplyScalar((Math.PI / 2.0) * sined);
// point.set(objToPointer.x, objToPointer.y, Math.cos(t));

return point;

Expand Down

0 comments on commit a406f36

Please sign in to comment.