Browse Source

Readied 3d camera orientation code for merge into develop branch

codeClimate
Wim Rijnders 8 years ago
parent
commit
2d42284527
1 changed files with 23 additions and 25 deletions
  1. +23
    -25
      lib/graph3d/Graph3d.js

+ 23
- 25
lib/graph3d/Graph3d.js View File

@ -1888,6 +1888,19 @@ Graph3d.prototype._redrawDataGraph = function() {
// End methods for drawing points per graph style.
// -----------------------------------------------------------------------------
/**
* Store startX, startY and startOffset for mouse operations
*
* @param {Event} event The event that occurred
*/
Graph3d.prototype._storeMousePosition = function(event) {
// get mouse position (different code for IE and all other browsers)
this.startMouseX = getMouseX(event);
this.startMouseY = getMouseY(event);
this._startCameraOffset = this.camera.getOffset();
};
/**
* Start a moving operation inside the provided parent element
@ -1907,11 +1920,7 @@ Graph3d.prototype._onMouseDown = function(event) {
this.leftButtonDown = event.which ? (event.which === 1) : (event.button === 1);
if (!this.leftButtonDown && !this.touchDown) return;
// get mouse position (different code for IE and all other browsers)
this.startMouseX = getMouseX(event);
this.startMouseY = getMouseY(event);
this._startCameraOffset = this.camera.getOffset();
this._storeMousePosition(event);
this.startStart = new Date(this.start);
this.startEnd = new Date(this.end);
@ -1938,36 +1947,25 @@ 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
// 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 scaleX = this.frame.clientWidth * 0.5;
var scaleY = this.frame.clientHeight * 0.5;
var scaleX = this.frame.clientWidth * 0.5;
var scaleY = this.frame.clientHeight * 0.5;
var offXNew = (this._startCameraOffset.x || 0) - ((diffX / scaleX) * this.camera.armLength) * 0.8;
var offYNew = (this._startCameraOffset.y || 0) + ((diffY / scaleY) * this.camera.armLength) * 0.8;
this.camera.setOffset(offXNew, offYNew);
// меняем startX, startY и startOffset
this._startCameraOffset = this.camera.getOffset();
this.startMouseX = getMouseX(event);
this.startMouseY = getMouseY(event);
this._storeMousePosition(event);
} else {
// 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 verticalNew = this.startArmRotation.vertical + diffY / 200;
var snapAngle = 4; // degrees
var snapValue = Math.sin(snapAngle / 360 * 2 * Math.PI);

Loading…
Cancel
Save