aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorPushkar Joshi2012-02-08 15:39:47 -0800
committerPushkar Joshi2012-02-08 15:39:47 -0800
commit802e92eb70b00849dadacf2c6590d27edbe65d99 (patch)
tree5ecc1e6eef0bb69820af500595fa22f6a68debaf /js/helper-classes
parent9b6b228524f14bf65ba60aaf3d0993c8ec5bff2d (diff)
downloadninja-802e92eb70b00849dadacf2c6590d27edbe65d99.tar.gz
bug fixes for better anchor point rotation and removing snapping on hover and mouse down
Diffstat (limited to 'js/helper-classes')
-rw-r--r--js/helper-classes/3D/math-utils.js18
-rw-r--r--js/helper-classes/RDGE/GLAnchorPoint.js11
-rw-r--r--js/helper-classes/RDGE/GLBrushStroke.js6
-rw-r--r--js/helper-classes/RDGE/GLSubpath.js4
4 files changed, 29 insertions, 10 deletions
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, {
802 getAxisAngleBetween3DVectors: { 802 getAxisAngleBetween3DVectors: {
803 value: function (vec1, vec2, axis) { 803 value: function (vec1, vec2, axis) {
804 //compute magnitudes of the vectors 804 //compute magnitudes of the vectors
805 var mag1 = VecUtils.vecMag(3, vec1); 805 var v1n = VecUtils.vecNormalize(3, vec1, 1.0);
806 var mag2 = VecUtils.vecMag(3, vec2); 806 var v2n = VecUtils.vecNormalize(3, vec2, 1.0);
807
808 if (mag1 < this.EPSILON || mag2 < this.EPSILON) {
809 return 0; //if angle 0 is returned nothing from this function should be used
810 }
811 //angle between the vectors (acos for now...) 807 //angle between the vectors (acos for now...)
812 var angle = Math.acos(VecUtils.vecDot(3, vec1, vec2) / (mag1 * mag2)); 808 var angle = Math.acos(VecUtils.vecDot(3, v1n, v2n));
813 if (Math.abs(angle) < this.EPSILON) { 809 if (Math.abs(angle) < this.EPSILON) {
814 return 0; 810 return 0;
815 } 811 }
812 //TODO testing...remove this block
813 console.log("getAxisAngleBetween3DVectors Angle: "+angle);
814 if (isNaN(angle)){
815 console.log("getAxisAngleBetween3DVectors Angle is NaN");
816 }
817 //TODO end testing block
816 //optionally, if axis is provided, create the axis of rotation as well 818 //optionally, if axis is provided, create the axis of rotation as well
817 var rotAxis = VecUtils.vecCross(3, vec1, vec2); 819 var rotAxis = VecUtils.vecCross(3, v1n, v2n);
818 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1); 820 rotAxis = VecUtils.vecNormalize(3, rotAxis, 1);
819 axis[0] = rotAxis[0]; 821 axis[0] = rotAxis[0];
820 axis[1] = rotAxis[1]; 822 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 () {
55 55
56//translate the next point from the translation that was applied to the prev. point 56//translate the next point from the translation that was applied to the prev. point
57GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) { 57GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) {
58 //do nothing if the total translation is zero
59 var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz);
60 if (totalTransSq < 0.0000001)
61 return;
62
58 // *** compute the rotation of the prev vector *** 63 // *** compute the rotation of the prev vector ***
59 var oldP = Vector.create([this._prevX + tx - this._x, this._prevY + ty - this._y, this._prevZ + tz - this._z]); 64 var oldP = Vector.create([this._prevX + tx - this._x, this._prevY + ty - this._y, this._prevZ + tz - this._z]);
60 var newP = Vector.create([this._prevX - this._x, this._prevY - this._y, this._prevZ - this._z]); 65 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) {
71 76
72 //TEMP for some situations the axis angle computation returns NaNs 77 //TEMP for some situations the axis angle computation returns NaNs
73 if (isNaN(newN[0]) || isNaN(newN[1]) || isNaN(newN[2])) { 78 if (isNaN(newN[0]) || isNaN(newN[1]) || isNaN(newN[2])) {
79 console.log("NaN in translateNextFromPrev");
74 return; 80 return;
75 } 81 }
76 //end TEMP 82 //end TEMP
@@ -80,6 +86,11 @@ GLAnchorPoint.prototype.translateNextFromPrev = function (tx, ty, tz) {
80} 86}
81//translate the next point from the translation that was applied to the prev. point 87//translate the next point from the translation that was applied to the prev. point
82GLAnchorPoint.prototype.translatePrevFromNext = function (tx, ty, tz) { 88GLAnchorPoint.prototype.translatePrevFromNext = function (tx, ty, tz) {
89 //do nothing if the total translation is zero
90 var totalTransSq = (tx*tx) + (ty*ty) + (tz*tz);
91 if (totalTransSq < 0.0000001)
92 return;
93
83 // *** compute the rotation of the next vector *** 94 // *** compute the rotation of the next vector ***
84 var oldN = Vector.create([this._nextX + tx - this._x, this._nextY + ty - this._y, this._nextZ + tz - this._z]); 95 var oldN = Vector.create([this._nextX + tx - this._x, this._nextY + ty - this._y, this._nextZ + tz - this._z]);
85 var newN = Vector.create([this._nextX - this._x, this._nextY - this._y, this._nextZ - this._z]); 96 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
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Todo: This shoudl be converted to a module 7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9 9
10/////////////////////////////////////////////////////////////////////// 10///////////////////////////////////////////////////////////////////////
@@ -140,6 +140,10 @@ function GLBrushStroke() {
140 this._dirty = false; 140 this._dirty = false;
141 } 141 }
142 142
143 this.buildBuffers = function () {
144 return; //no need to do anything for now
145 }//buildBuffers()
146
143 //render 147 //render
144 // specify how to render the subpath in Canvas2D 148 // specify how to render the subpath in Canvas2D
145 this.render = function () { 149 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
4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved. 4(c) Copyright 2011 Motorola Mobility, Inc. All Rights Reserved.
5</copyright> */ 5</copyright> */
6 6
7// Todo: This shoudl be converted to a module 7// Todo: This entire class should be converted to a module
8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils; 8var VecUtils = require("js/helper-classes/3D/vec-utils").VecUtils;
9 9
10 10
@@ -163,6 +163,7 @@ function GLSubpath() {
163 } 163 }
164 */ 164 */
165 165
166
166 var numPoints = this._samples.length/3; 167 var numPoints = this._samples.length/3;
167 ctx.moveTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]); 168 ctx.moveTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]);
168 for (var i=0;i<numPoints;i++){ 169 for (var i=0;i<numPoints;i++){
@@ -172,6 +173,7 @@ function GLSubpath() {
172 ctx.lineTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]); 173 ctx.lineTo(this._samples[0]-bboxMin[0],this._samples[1]-bboxMin[1]);
173 ctx.fill(); 174 ctx.fill();
174 } 175 }
176
175 ctx.stroke(); 177 ctx.stroke();
176 ctx.restore(); 178 ctx.restore();
177 } //render() 179 } //render()