|
|
@ -1937,34 +1937,51 @@ Graph3d.prototype._onMouseDown = function(event) { |
|
|
|
Graph3d.prototype._onMouseMove = function (event) { |
|
|
|
event = event || window.event; |
|
|
|
|
|
|
|
// calculate change in mouse position
|
|
|
|
var diffX = parseFloat(getMouseX(event)) - this.startMouseX; |
|
|
|
var diffY = parseFloat(getMouseY(event)) - this.startMouseY; |
|
|
|
// move with ctrl or rotate by other
|
|
|
|
if (event && event.ctrlKey === true) { |
|
|
|
// calculate change in mouse position
|
|
|
|
var camera = this.camera, |
|
|
|
offset = camera.getOffset(); |
|
|
|
var diffX = parseFloat(getMouseX(event)) - this.startMouseX; |
|
|
|
var diffY = parseFloat(getMouseY(event)) - this.startMouseY; |
|
|
|
|
|
|
|
var horizontalNew = this.startArmRotation.horizontal + diffX / 200; |
|
|
|
var verticalNew = this.startArmRotation.vertical + diffY / 200; |
|
|
|
var scale = this.frame.clientWidth * 0.6; |
|
|
|
|
|
|
|
var snapAngle = 4; // degrees
|
|
|
|
var snapValue = Math.sin(snapAngle / 360 * 2 * Math.PI); |
|
|
|
var offXNew = offset.x - ((diffX / scale) * this.camera.armLength) * 0.1; |
|
|
|
var offYNew = offset.y + ((diffY / scale) * this.camera.armLength) * 0.1; |
|
|
|
|
|
|
|
// snap horizontally to nice angles at 0pi, 0.5pi, 1pi, 1.5pi, etc...
|
|
|
|
// the -0.001 is to take care that the vertical axis is always drawn at the left front corner
|
|
|
|
if (Math.abs(Math.sin(horizontalNew)) < snapValue) { |
|
|
|
horizontalNew = Math.round((horizontalNew / Math.PI)) * Math.PI - 0.001; |
|
|
|
} |
|
|
|
if (Math.abs(Math.cos(horizontalNew)) < snapValue) { |
|
|
|
horizontalNew = (Math.round((horizontalNew/ Math.PI - 0.5)) + 0.5) * Math.PI - 0.001; |
|
|
|
} |
|
|
|
this.camera.setOffset(offXNew, offYNew); |
|
|
|
} else { |
|
|
|
|
|
|
|
// snap vertically to nice angles
|
|
|
|
if (Math.abs(Math.sin(verticalNew)) < snapValue) { |
|
|
|
verticalNew = Math.round((verticalNew / Math.PI)) * Math.PI; |
|
|
|
} |
|
|
|
if (Math.abs(Math.cos(verticalNew)) < snapValue) { |
|
|
|
verticalNew = (Math.round((verticalNew/ Math.PI - 0.5)) + 0.5) * Math.PI; |
|
|
|
// calculate change in mouse position
|
|
|
|
var diffX = parseFloat(getMouseX(event)) - this.startMouseX; |
|
|
|
var diffY = parseFloat(getMouseY(event)) - this.startMouseY; |
|
|
|
|
|
|
|
var horizontalNew = this.startArmRotation.horizontal + diffX / 200; |
|
|
|
var verticalNew = this.startArmRotation.vertical + diffY / 200; |
|
|
|
|
|
|
|
var snapAngle = 4; // degrees
|
|
|
|
var snapValue = Math.sin(snapAngle / 360 * 2 * Math.PI); |
|
|
|
|
|
|
|
// snap horizontally to nice angles at 0pi, 0.5pi, 1pi, 1.5pi, etc...
|
|
|
|
// the -0.001 is to take care that the vertical axis is always drawn at the left front corner
|
|
|
|
if (Math.abs(Math.sin(horizontalNew)) < snapValue) { |
|
|
|
horizontalNew = Math.round(horizontalNew / Math.PI) * Math.PI - 0.001; |
|
|
|
} |
|
|
|
if (Math.abs(Math.cos(horizontalNew)) < snapValue) { |
|
|
|
horizontalNew = (Math.round(horizontalNew / Math.PI - 0.5) + 0.5) * Math.PI - 0.001; |
|
|
|
} |
|
|
|
|
|
|
|
// snap vertically to nice angles
|
|
|
|
if (Math.abs(Math.sin(verticalNew)) < snapValue) { |
|
|
|
verticalNew = Math.round(verticalNew / Math.PI) * Math.PI; |
|
|
|
} |
|
|
|
if (Math.abs(Math.cos(verticalNew)) < snapValue) { |
|
|
|
verticalNew = (Math.round(verticalNew / Math.PI - 0.5) + 0.5) * Math.PI; |
|
|
|
} |
|
|
|
this.camera.setArmRotation(horizontalNew, verticalNew); |
|
|
|
} |
|
|
|
|
|
|
|
this.camera.setArmRotation(horizontalNew, verticalNew); |
|
|
|
this.redraw(); |
|
|
|
|
|
|
|
// fire a cameraPositionChange event
|
|
|
|