From 802e92eb70b00849dadacf2c6590d27edbe65d99 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 8 Feb 2012 15:39:47 -0800 Subject: bug fixes for better anchor point rotation and removing snapping on hover and mouse down --- js/helper-classes/3D/math-utils.js | 18 ++-- js/helper-classes/RDGE/GLAnchorPoint.js | 11 ++ js/helper-classes/RDGE/GLBrushStroke.js | 6 +- js/helper-classes/RDGE/GLSubpath.js | 4 +- js/tools/PenTool.js | 182 ++++++++------------------------ 5 files changed, 75 insertions(+), 146 deletions(-) (limited to 'js') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 71ed62a0..3d24f76e 100644 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -802,19 +802,21 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { getAxisAngleBetween3DVectors: { value: function (vec1, vec2, axis) { //compute magnitudes of the vectors - var mag1 = VecUtils.vecMag(3, vec1); - var mag2 = VecUtils.vecMag(3, vec2); - - if (mag1 < this.EPSILON || mag2 < this.EPSILON) { - return 0; //if angle 0 is returned nothing from this function should be used - } + var v1n = VecUtils.vecNormalize(3, vec1, 1.0); + var v2n = VecUtils.vecNormalize(3, vec2, 1.0); //angle between the vectors (acos for now...) - var angle = Math.acos(VecUtils.vecDot(3, vec1, vec2) / (mag1 * mag2)); + var angle = Math.acos(VecUtils.vecDot(3, v1n, v2n)); if (Math.abs(angle) < this.EPSILON) { return 0; } + //TODO testing...remove this block + console.log("getAxisAngleBetween3DVectors Angle: "+angle); + if (isNaN(angle)){ + console.log("getAxisAngleBetween3DVectors Angle is NaN"); + } + //TODO end testing block //optionally, if axis is provided, create the axis of rotation as well - var rotAxis = VecUtils.vecCross(3, vec1, vec2); + var rotAxis = VecUtils.vecCross(3, v1n, v2n); rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); axis[0] = rotAxis[0]; axis[1] = rotAxis[1]; diff --git a/js/helper-classes/RDGE/GLAnchorPoint.js b/js/helper-classes/RDGE/GLAnchorPoint.js index 6b4af072..716f59d4 100644 --- a/js/helper-classes/RDGE/GLAnchorPoint.js +++ b/js/helper-classes/RDGE/GLAnchorPoint.js @@ -55,6 +55,11 @@ GLAnchorPoint.prototype.setNextFromPrev = function () { //translate the next point from the translation that was applied to the prev. point GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) { + //do nothing if the total translation is zero + var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz); + if (totalTransSq < 0.0000001) + return; + // *** compute the rotation of the prev vector *** var oldP = Vector.create([this._prevX + tx - this._x, this._prevY + ty - this._y, this._prevZ + tz - this._z]); var newP = Vector.create([this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]); @@ -71,6 +76,7 @@ GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) { //TEMP for some situations the axis angle computation returns NaNs if (isNaN(newN[0]) || isNaN(newN[1]) || isNaN(newN[2])) { + console.log("NaN in translateNextFromPrev"); return; } //end TEMP @@ -80,6 +86,11 @@ GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) { } //translate the next point from the translation that was applied to the prev. point GLAnchorPoint.prototype.translatePrevFromNext = function (tx, ty, tz) { + //do nothing if the total translation is zero + var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz); + if (totalTransSq < 0.0000001) + return; + // *** compute the rotation of the next vector *** var oldN = Vector.create([this._nextX + tx - this._x, this._nextY + ty - this._y, this._nextZ + tz - this._z]); var newN = Vector.create([this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]); diff --git a/js/helper-classes/RDGE/GLBrushStroke.js b/js/helper-classes/RDGE/GLBrushStroke.js index 552545f0..fdf1595c 100644 --- a/js/helper-classes/RDGE/GLBrushStroke.js +++ b/js/helper-classes/RDGE/GLBrushStroke.js @@ -4,7 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -// Todo: This shoudl be converted to a module +// Todo: This entire class should be converted to a module var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; /////////////////////////////////////////////////////////////////////// @@ -140,6 +140,10 @@ function GLBrushStroke() { this._dirty = false; } + this.buildBuffers = function () { + return; //no need to do anything for now + }//buildBuffers() + //render // specify how to render the subpath in Canvas2D this.render = function () { diff --git a/js/helper-classes/RDGE/GLSubpath.js b/js/helper-classes/RDGE/GLSubpath.js index 383194d4..a14fdda0 100644 --- a/js/helper-classes/RDGE/GLSubpath.js +++ b/js/helper-classes/RDGE/GLSubpath.js @@ -4,7 +4,7 @@ No rights, expressed or implied, whatsoever to this software are provided by Mot (c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. */ -// Todo: This shoudl be converted to a module +// Todo: This entire class should be converted to a module var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; @@ -163,6 +163,7 @@ function GLSubpath() { } */ + var numPoints = this._samples.length/3; ctx.moveTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]); for (var i=0;i=0) { @@ -371,7 +357,7 @@ exports.PenTool = Montage.create(ShapeTool, { }//value: function(event) },//HandleMouseMove - //TODO Optimize! This function is probably no longer needed + TranslateSelectedSubpathPerPenCanvas:{ value: function() { if (this._penCanvas!==null) { @@ -491,9 +477,11 @@ exports.PenTool = Montage.create(ShapeTool, { this._editMode = this.EDIT_NONE; this.DrawHandles(); - if (this._entryEditMode === this.ENTRY_SELECT_PATH || !this._selectedSubpath.getIsClosed()){ + //if (this._entryEditMode === this.ENTRY_SELECT_PATH || !this._selectedSubpath.getIsClosed()){ + if (this._selectedSubpath){ this.DrawSubpathAnchors(this._selectedSubpath);//render the subpath anchors on canvas (not GL) } + //} if (!g_DoPenToolMouseMove){ NJevent("disableStageMove"); @@ -518,7 +506,6 @@ exports.PenTool = Montage.create(ShapeTool, { value: function(event) { this._isEscapeDown = true; //close the current subpath and reset the pen tool - this._subpaths.push(this._selectedSubpath); this._penCanvas = null; this._penPlaneMat = null; this._snapTarget = null; @@ -551,7 +538,7 @@ exports.PenTool = Montage.create(ShapeTool, { event.preventDefault(); this.HandleSpaceKeyDown(event); } else if (event.keyCode == Keyboard.BACKSPACE || event.keyCode === Keyboard.DELETE) { - //TODO this is probably unnecessary since we handle delete and backspace via the delete delegate + //this is probably unnecessary since we handle delete and backspace via the delete delegate event.stopImmediatePropagation(); event.preventDefault(); } else if (event.keyCode === Keyboard.ESCAPE){ @@ -663,35 +650,6 @@ exports.PenTool = Montage.create(ShapeTool, { } //value: function(p0, p2, p3) { }, //BuildSecondCtrlPoint:{ - - /* - deleteSelection: { - value: function() { - //clear the selected subpath...the only new additions to this function w.r.t. ToolBase - if (this._selectedSubpath){ - if (this._selectedSubpath.getSelectedAnchorIndex()>=0){ - this._selectedSubpath.removeAnchor(this._selectedSubpath.getSelectedAnchorIndex()); - this._selectedSubpath.createSamples(); - //clear the canvas - this.application.ninja.stage.clearDrawingCanvas(); - this.DrawSubpathAnchors(this._selectedSubpath); - this.ShowSelectedSubpath(); - } - else { - this._selectedSubpath.clearAllAnchors(); - - this._selectedSubpath.createSamples(); - this._selectedSubpath = null; - //clear the canvas - this.application.ninja.stage.clearDrawingCanvas(); - this._penCanvas = null; - } - } - } - }, - */ - - HandleDoubleClick: { value: function () { //if there is a selected anchor point @@ -869,7 +827,7 @@ exports.PenTool = Montage.create(ShapeTool, { //display the hovered over anchor point ctx.lineWidth = 2; ctx.strokeStyle = "black"; - if (this._hoveredAnchorIndex && this._hoveredAnchorIndex>=0) { + if (this._hoveredAnchorIndex && this._hoveredAnchorIndex>=0 && this._hoveredAnchorIndex