aboutsummaryrefslogtreecommitdiff
path: root/js
diff options
context:
space:
mode:
Diffstat (limited to 'js')
-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
-rw-r--r--js/tools/PenTool.js182
5 files changed, 75 insertions, 146 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()
diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js
index 5b48d3c9..9a69b53d 100644
--- a/js/tools/PenTool.js
+++ b/js/tools/PenTool.js
@@ -37,7 +37,6 @@ exports.PenTool = Montage.create(ShapeTool, {
37 _currentY: { value: 0, writable: true }, 37 _currentY: { value: 0, writable: true },
38 38
39 //the subpaths are what is displayed on the screen currently, with _selectedSubpath being the active one currently being edited 39 //the subpaths are what is displayed on the screen currently, with _selectedSubpath being the active one currently being edited
40 _subpaths: { value: [], writable: true },
41 _selectedSubpath: { value: null, writable: true }, 40 _selectedSubpath: { value: null, writable: true },
42 _makeMultipleSubpaths: { value: true, writable: true }, //set this to true if you want to keep making subpaths after closing current subpath 41 _makeMultipleSubpaths: { value: true, writable: true }, //set this to true if you want to keep making subpaths after closing current subpath
43 42
@@ -90,39 +89,29 @@ exports.PenTool = Montage.create(ShapeTool, {
90 ENTRY_SELECT_PATH: { value: 2, writable: false}, 89 ENTRY_SELECT_PATH: { value: 2, writable: false},
91 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true}, 90 _entryEditMode: {value: this.ENTRY_SELECT_NONE, writable: true},
92 91
93 // ******** Logic for selection *******
94 // (update if you change functionality!)
95 // NOTE: this is out of date...needs to be updated
96 //
97 // Start by setting edit mode to EDIT_NONE
98 //
99 // DOUBLE_CLICK (Left mouse button only):
100 //
101 //
102 // SINGLE_CLICK (Left mouse button only):
103 // If LeftClick selects an anchor point
104 // append EDIT_ANCHOR mode
105 // If LeftClick selects a previous point of selected anchor
106 // append EDIT_PREV mode
107 // If LeftClick selects a next point of selected anchor
108 // append EDIT_NEXT mode
109 //
110
111 // ********* Logic for editing *******
112 // (update if you change functionality!)
113 // NOTE: this is out of date...needs to be updated
114 //
115 // Start by computing mouse disp
116 //
117 // If EDIT_PREV_NEXT mode
118 // add disp to next and mirror it to prev
119 // ELSE
120 // If EDIT_ANCHOR (or _PREV, _NEXT)
121 // map displacement to anchor (similarly to prev and next)
122 //
123 //
124 92
125 93
94 _getUnsnappedPosition: {
95 value: function(x,y){
96 var elemSnap = snapManager.elementSnapEnabled();
97 var gridSnap = snapManager.gridSnapEnabled();
98 var alignSnap = snapManager.snapAlignEnabled();
99
100 snapManager.enableElementSnap(false);
101 snapManager.enableGridSnap(false);
102 snapManager.enableSnapAlign(false);
103
104 var point = webkitConvertPointFromPageToNode(this.application.ninja.stage.canvas, new WebKitPoint(x,y));
105 var unsnappedpos = DrawingToolBase.getHitRecPos(snapManager.snap(point.x, point.y, false));
106
107 snapManager.enableElementSnap(elemSnap);
108 snapManager.enableGridSnap(gridSnap);
109 snapManager.enableSnapAlign(alignSnap);
110
111 return unsnappedpos;
112 }
113 },
114
126 ShowToolProperties: { 115 ShowToolProperties: {
127 value: function () { 116 value: function () {
128 this._penView = PenView.create(); 117 this._penView = PenView.create();
@@ -153,7 +142,7 @@ exports.PenTool = Montage.create(ShapeTool, {
153 this._isNewPath = false; 142 this._isNewPath = false;
154 143
155 //add an anchor point by computing position of mouse down 144 //add an anchor point by computing position of mouse down
156 var mouseDownPos = this.getMouseDownPos(); 145 var mouseDownPos = this._getUnsnappedPosition(event.pageX, event.pageY); //this.getMouseDownPos();
157 if (mouseDownPos) { 146 if (mouseDownPos) {
158 //if we had closed the selected subpath previously, or if we have not yet started anything, create a subpath