From 51b4e61d6c6df5e88e9a5dfcdfd7944e2a3f64e7 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Mon, 30 Jan 2012 13:25:15 -0800 Subject: Syncing stage view when rotating stage. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index 3fd6e8fc..c26a5cd1 100644 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -107,6 +107,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { this.eventManager.addEventListener("elementAdded", this, false); this.eventManager.addEventListener("elementDeleted", this, false); + this.eventManager.addEventListener("elementChange", this, false); } }, @@ -124,6 +125,27 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { }, + handleElementChange: { + value: function(event) { + var els = event.detail.data.els; + if(els) + { + var len = els.length, + i = 0, + item, + el; + + for(i=0; i < len; i++) { + item = els[i]; + el = item._element || item; + el.elementModel.props3D.elementPlane.init(); + } + + this.drawWorkingPlane(); + } + } + }, + /////////////////////////////////////////////////////////////////////// // Methods /////////////////////////////////////////////////////////////////////// @@ -150,6 +172,7 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { plane.setElement( elt ); plane.init(); this._planesArray.push( plane ); + elt.elementModel.props3D.elementPlane = plane; } }, @@ -166,6 +189,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { // Then remove the element this._eltArray.splice(i, 1); + + // TODO - May need to delete props3D and elementPlane as well return; } } -- cgit v1.2.3 From 7534bd7acc822dea641b1547cd955801920055aa Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 2 Feb 2012 13:55:55 -0800 Subject: Adding legal attribution for decompose matrix routine. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/math-utils.js | 54 ++++++++++++++++++++------------------ 1 file changed, 29 insertions(+), 25 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/math-utils.js b/js/helper-classes/3D/math-utils.js index 49c77c41..71ed62a0 100644 --- a/js/helper-classes/3D/math-utils.js +++ b/js/helper-classes/3D/math-utils.js @@ -891,36 +891,32 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, +/** +* decompose matrix in javascript found at https://github.com/joelambert/morf/blob/master/js/src/WebkitCSSMatrix.ext.js +* used with permission from Joe Lambert: "as long as the original licence text and attribution is left in then you're +* good to use it as you see fit." +* +* WebKitCSSMatrix Extensions +* +* Copyright 2011, Joe Lambert (http://www.joelambert.co.uk) +* Free to use under the MIT license. +* http://joelambert.mit-license.org/ +*/ + +/** +* Decomposes the matrix into its component parts. +* A Javascript implementation of the pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition +* @author Joe Lambert +* @returns {Object} An object with each of the components of the matrix (perspective, translate, skew, scale, rotate) or identity matrix on failure +*/ + // Input: matrix ; a 4x4 matrix // Output: translation ; a 3 component vector // rotation ; Euler angles, represented as a 3 component vector // scale ; a 3 component vector // skew ; skew factors XY,XZ,YZ represented as a 3 component vector // perspective ; a 4 component vector -// Returns false if the matrix cannot be decomposed, an object with the above output values if it can -// -// Supporting functions (point is a 3 component vector, matrix is a 4x4 matrix): -// float determinant(matrix) returns the 4x4 determinant of the matrix -// matrix inverse(matrix) returns the inverse of the passed matrix -// matrix transpose(matrix) returns the transpose of the passed matrix -// point multVecMatrix(point, matrix) multiplies the passed point by the passed matrix -// and returns the transformed point -// float length(point) returns the length of the passed vector -// point normalize(point) normalizes the length of the passed point to 1 -// float dot(point, point) returns the dot product of the passed points -// float cos(float) returns the cosine of the passed angle in radians -// float asin(float) returns the arcsine in radians of the passed value -// float atan2(float y, float x) returns the principal value of the arc tangent of -// y/x, using the signs of both arguments to determine -// the quadrant of the return value -// -// Decomposition also makes use of the following function: -// point combine(point a, point b, float ascl, float bscl) -// result[0] = (ascl * a[0]) + (bscl * b[0]) -// result[1] = (ascl * a[1]) + (bscl * b[1]) -// result[2] = (ascl * a[2]) + (bscl * b[2]) -// return result -// +// Returns false if the matrix cannot be decomposed. An object with the above output values if it can. decomposeMatrix2: { value: function(m) { @@ -1077,7 +1073,6 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { rotate[2] = 0; } -// return true; return {translation: translate, rotation: rotate, scale: scale, @@ -1087,6 +1082,15 @@ var MathUtilsClass = exports.MathUtilsClass = Object.create(Object.prototype, { } }, +/** +* Helper function required for matrix decomposition +* A Javascript implementation of pseudo code available from http://www.w3.org/TR/css3-2d-transforms/#matrix-decomposition +* @param {Vector4} aPoint A 3D point +* @param {float} ascl +* @param {float} bscl +* @author Joe Lambert +* @returns {Vector4} +*/ combine: { value: function(a, b, ascl, bscl) { -- cgit v1.2.3 From d41dee0c552a30724a146965ae4272a268777fc5 Mon Sep 17 00:00:00 2001 From: Nivesh Rajbhandari Date: Thu, 2 Feb 2012 14:53:14 -0800 Subject: Integrating Pan and Zoom tool and snap manager fixes. Signed-off-by: Nivesh Rajbhandari --- js/helper-classes/3D/draw-utils.js | 3 ++- js/helper-classes/3D/snap-manager.js | 11 ++++++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'js/helper-classes/3D') diff --git a/js/helper-classes/3D/draw-utils.js b/js/helper-classes/3D/draw-utils.js index c26a5cd1..fd96af4d 100644 --- a/js/helper-classes/3D/draw-utils.js +++ b/js/helper-classes/3D/draw-utils.js @@ -1089,7 +1089,8 @@ var DrawUtils = exports.DrawUtils = Montage.create(Component, { var resMat = glmat4.multiply( tMat, mat, [] ); var origin = [0,0,0,1]; - var arrowSize = 50; + var zoomFactor = this.application.ninja.documentBar.zoomFactor/100.0; + var arrowSize = 50 / zoomFactor; var xAxis = [arrowSize,0,0,1]; //var rO = resMat.multiply(origin); var rO = glmat4.multiplyVec3( resMat, origin, []); diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index 3ed96082..8819f637 100644 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js @@ -1780,7 +1780,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { var mergedSnap = this.mergeHitRecords( hitRecs ); if (mergedSnap) { - while (hitRecs.length > 0) hitRecs.pop(); + while (hitRecs.length > 0) hitRecs.pop(); hitRecs.push( mergedSnap ); //console.log( "merged snaps" ); } @@ -1836,6 +1836,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) @@ -1882,6 +1885,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) @@ -1934,6 +1940,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { hSnap.setLocalPoint( localPt ); hSnap.setScreenPoint( scrPt ); hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); + hSnap.setElement( stage ); + hSnap.setPlane( [0,0,1,0] ); + hSnap.setPlaneMatrix( Matrix.I(4) ); if (vSnap.hasAssociatedScreenPoint() ) hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); if (vSnap.hasAssociatedScreenPoint2() ) -- cgit v1.2.3