Three.js: style fixes. NFCI.
parent
6f9358ae95
commit
b97a80b6ed
|
@ -58,14 +58,14 @@ SolvespaceCamera.prototype.rotate = function(right, up) {
|
||||||
this.up.applyAxisAngle(oldRight, up);
|
this.up.applyAxisAngle(oldRight, up);
|
||||||
this.right.applyAxisAngle(oldUp, right);
|
this.right.applyAxisAngle(oldUp, right);
|
||||||
this.NormalizeProjectionVectors();
|
this.NormalizeProjectionVectors();
|
||||||
}
|
};
|
||||||
|
|
||||||
SolvespaceCamera.prototype.offsetProj = function(right, up) {
|
SolvespaceCamera.prototype.offsetProj = function(right, up) {
|
||||||
var shift = new THREE.Vector3(right * this.right.x + up * this.up.x,
|
var shift = new THREE.Vector3(right * this.right.x + up * this.up.x,
|
||||||
right * this.right.y + up * this.up.y,
|
right * this.right.y + up * this.up.y,
|
||||||
right * this.right.z + up * this.up.z);
|
right * this.right.z + up * this.up.z);
|
||||||
this.offset.add(shift);
|
this.offset.add(shift);
|
||||||
}
|
};
|
||||||
|
|
||||||
/* Calculate the offset in terms of up and right projection vectors
|
/* Calculate the offset in terms of up and right projection vectors
|
||||||
that will preserve the world coordinates of the current mouse position after
|
that will preserve the world coordinates of the current mouse position after
|
||||||
|
@ -86,7 +86,7 @@ SolvespaceCamera.prototype.zoomTo = function(x, y, delta) {
|
||||||
zoomFactor = (-delta * 0.002 + 1);
|
zoomFactor = (-delta * 0.002 + 1);
|
||||||
}
|
}
|
||||||
else if(delta > 0) {
|
else if(delta > 0) {
|
||||||
zoomFactor = (delta * (-1.0/600.0) + 1)
|
zoomFactor = (delta * (-1.0/600.0) + 1);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
return;
|
return;
|
||||||
|
@ -98,8 +98,7 @@ SolvespaceCamera.prototype.zoomTo = function(x, y, delta) {
|
||||||
|
|
||||||
this.offset.addScaledVector(this.right, centerRightF - centerRightI);
|
this.offset.addScaledVector(this.right, centerRightF - centerRightI);
|
||||||
this.offset.addScaledVector(this.up, centerUpF - centerUpI);
|
this.offset.addScaledVector(this.up, centerUpF - centerUpI);
|
||||||
}
|
};
|
||||||
|
|
||||||
|
|
||||||
SolvespaceControls = function(object, domElement) {
|
SolvespaceControls = function(object, domElement) {
|
||||||
var _this = this;
|
var _this = this;
|
||||||
|
@ -131,8 +130,6 @@ SolvespaceControls = function(object, domElement) {
|
||||||
};
|
};
|
||||||
|
|
||||||
var _changed = false;
|
var _changed = false;
|
||||||
var _mouseMoved = false;
|
|
||||||
//var _touchPoints = new Array();
|
|
||||||
var _offsetPrev = new THREE.Vector2(0, 0);
|
var _offsetPrev = new THREE.Vector2(0, 0);
|
||||||
var _offsetCur = new THREE.Vector2(0, 0);
|
var _offsetCur = new THREE.Vector2(0, 0);
|
||||||
var _rotatePrev = new THREE.Vector2(0, 0);
|
var _rotatePrev = new THREE.Vector2(0, 0);
|
||||||
|
@ -195,7 +192,6 @@ SolvespaceControls = function(object, domElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function mousemove_pan(event) {
|
function mousemove_pan(event) {
|
||||||
_mouseMoved = true;
|
|
||||||
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
_offsetCur.set(event.screenX / window.devicePixelRatio,
|
||||||
event.screenY / window.devicePixelRatio);
|
event.screenY / window.devicePixelRatio);
|
||||||
var diff = new THREE.Vector2().subVectors(_offsetCur, _offsetPrev)
|
var diff = new THREE.Vector2().subVectors(_offsetCur, _offsetPrev)
|
||||||
|
@ -230,9 +226,9 @@ SolvespaceControls = function(object, domElement) {
|
||||||
function pan(event) {
|
function pan(event) {
|
||||||
/* neWcur - prev does not necessarily equal (cur + diff) - prev.
|
/* neWcur - prev does not necessarily equal (cur + diff) - prev.
|
||||||
Floating point is not associative. */
|
Floating point is not associative. */
|
||||||
touchDiff = new THREE.Vector2(event.deltaX, event.deltaY);
|
var touchDiff = new THREE.Vector2(event.deltaX, event.deltaY);
|
||||||
_rotateCur.addVectors(_rotateOrig, touchDiff);
|
_rotateCur.addVectors(_rotateOrig, touchDiff);
|
||||||
incDiff = new THREE.Vector2().subVectors(_rotateCur, _rotatePrev)
|
var incDiff = new THREE.Vector2().subVectors(_rotateCur, _rotatePrev)
|
||||||
.multiplyScalar(1 / object.zoomScale);
|
.multiplyScalar(1 / object.zoomScale);
|
||||||
object.rotate(-0.3 * Math.PI / 180 * incDiff.x * object.zoomScale,
|
object.rotate(-0.3 * Math.PI / 180 * incDiff.x * object.zoomScale,
|
||||||
-0.3 * Math.PI / 180 * incDiff.y * object.zoomScale);
|
-0.3 * Math.PI / 180 * incDiff.y * object.zoomScale);
|
||||||
|
@ -275,9 +271,9 @@ SolvespaceControls = function(object, domElement) {
|
||||||
}
|
}
|
||||||
|
|
||||||
function panaftertap(event) {
|
function panaftertap(event) {
|
||||||
touchDiff = new THREE.Vector2(event.deltaX, event.deltaY);
|
var touchDiff = new THREE.Vector2(event.deltaX, event.deltaY);
|
||||||
_offsetCur.addVectors(_offsetOrig, touchDiff);
|
_offsetCur.addVectors(_offsetOrig, touchDiff);
|
||||||
incDiff = new THREE.Vector2().subVectors(_offsetCur, _offsetPrev)
|
var incDiff = new THREE.Vector2().subVectors(_offsetCur, _offsetPrev)
|
||||||
.multiplyScalar(1 / object.zoomScale);
|
.multiplyScalar(1 / object.zoomScale);
|
||||||
object.offsetProj(incDiff.x, -incDiff.y);
|
object.offsetProj(incDiff.x, -incDiff.y);
|
||||||
_changed = true;
|
_changed = true;
|
||||||
|
@ -302,7 +298,7 @@ SolvespaceControls = function(object, domElement) {
|
||||||
_this.dispatchEvent(changeEvent);
|
_this.dispatchEvent(changeEvent);
|
||||||
_changed = false;
|
_changed = false;
|
||||||
}
|
}
|
||||||
}
|
};
|
||||||
|
|
||||||
this.domElement.addEventListener('mousedown', mousedown, false);
|
this.domElement.addEventListener('mousedown', mousedown, false);
|
||||||
this.domElement.addEventListener('wheel', wheel, false);
|
this.domElement.addEventListener('wheel', wheel, false);
|
||||||
|
@ -322,7 +318,7 @@ SolvespaceControls = function(object, domElement) {
|
||||||
this.touchControls.on('panaftertapstart', panaftertapstart);
|
this.touchControls.on('panaftertapstart', panaftertapstart);
|
||||||
this.touchControls.on('panaftertap', panaftertap);
|
this.touchControls.on('panaftertap', panaftertap);
|
||||||
this.touchControls.on('panaftertapend', panaftertapend);
|
this.touchControls.on('panaftertapend', panaftertapend);
|
||||||
}
|
};
|
||||||
|
|
||||||
SolvespaceControls.prototype = Object.create(THREE.EventDispatcher.prototype);
|
SolvespaceControls.prototype = Object.create(THREE.EventDispatcher.prototype);
|
||||||
SolvespaceControls.prototype.constructor = SolvespaceControls;
|
SolvespaceControls.prototype.constructor = SolvespaceControls;
|
||||||
|
@ -370,12 +366,11 @@ solvespace = function(obj, params) {
|
||||||
projRight = params.projRight;
|
projRight = params.projRight;
|
||||||
}
|
}
|
||||||
|
|
||||||
domElement = init();
|
var domElement = init();
|
||||||
lightUpdate();
|
lightUpdate();
|
||||||
render();
|
render();
|
||||||
return domElement;
|
return domElement;
|
||||||
|
|
||||||
|
|
||||||
function init() {
|
function init() {
|
||||||
scene = new THREE.Scene();
|
scene = new THREE.Scene();
|
||||||
edgeScene = new THREE.Scene();
|
edgeScene = new THREE.Scene();
|
||||||
|
@ -440,7 +435,7 @@ solvespace = function(obj, params) {
|
||||||
// The original light positions were in camera space.
|
// The original light positions were in camera space.
|
||||||
// Project them into standard space using camera's basis
|
// Project them into standard space using camera's basis
|
||||||
// vectors (up, target, and their cross product).
|
// vectors (up, target, and their cross product).
|
||||||
n = new THREE.Vector3().crossVectors(camera.up, camera.right);
|
var n = new THREE.Vector3().crossVectors(camera.up, camera.right);
|
||||||
changeBasis.makeBasis(camera.right, camera.up, n);
|
changeBasis.makeBasis(camera.right, camera.up, n);
|
||||||
|
|
||||||
for (var i = 0; i < 2; i++) {
|
for (var i = 0; i < 2; i++) {
|
||||||
|
|
Loading…
Reference in New Issue