aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorValerio Virgillito2012-05-22 14:54:51 -0700
committerValerio Virgillito2012-05-22 14:54:51 -0700
commit3493df6f1b1eaa20bb4f391e19c19bb7f3c872a0 (patch)
treed0ca79f7a7be334d2a0580553bd9de3ba0bbe30b /js/helper-classes
parentb3e85f609f704d668c8022c53418f8056bc71260 (diff)
parent862ee363584dfba4bdd9abacbc3a3244c7ec66b5 (diff)
downloadninja-3493df6f1b1eaa20bb4f391e19c19bb7f3c872a0.tar.gz
Merge branch 'refs/heads/master' into dom-architecture
Conflicts: js/io/system/ninjalibrary.json Signed-off-by: Valerio Virgillito <valerio@motorola.com>
Diffstat (limited to 'js/helper-classes')
-rwxr-xr-xjs/helper-classes/3D/snap-manager.js146
-rwxr-xr-xjs/helper-classes/3D/view-utils.js13
2 files changed, 86 insertions, 73 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js
index e22ac3ad..0f456e1e 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -223,64 +223,22 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
223 else 223 else
224 parentPt = [xScreen, yScreen, 0.0]; 224 parentPt = [xScreen, yScreen, 0.0];
225 225
226 var eyePt = []; 226 if (!snap3D && this._hasDragPlane)
227 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); 227 this.activateDragPlane();
228 if (vec) 228
229 { 229 var hitRec = this.snapToStage( parentPt, quadPt );
230 // activate the drag working plane 230
231 if (!snap3D && this.hasDragPlane()) 231 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
232 this.activateDragPlane(); 232 if (this.gridSnapEnabled())
233 233 this.snapToGrid( hitRec );
234 // project to the working plane 234
235 var currentWorkingPlane = workingPlane.slice(0); 235 // save the hit record
236 var wp = currentWorkingPlane.slice(0); 236 hitRecArray.push( hitRec );
237 var mat = viewUtils.getMatrixFromElement(stage); 237
238 wp = MathUtils.transformPlane(wp, mat); 238 // restore the original working plane
239 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 239 if (!snap3D && this.hasDragPlane())
240 if (projPt) 240 this.deactivateDragPlane();
241 { 241
242 // the local point gets stored in the coordinate space of the plane
243 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
244 projPt[3] = 1.0;
245 //var planeToViewMat = mat.multiply(wpMat);
246 var planeToViewMat = glmat4.multiply(mat, wpMat, []);
247 //var viewToPlaneMat = planeToViewMat.inverse();
248 var viewToPlaneMat = glmat4.inverse( planeToViewMat, [] );
249 var planePt = projPt.slice(0);
250 planePt[3] = 1.0;
251 //planePt = viewToPlaneMat.multiply(planePt);
252 planePt = glmat4.multiplyVec3( viewToPlaneMat, planePt );
253
254 // get the screen position of the projected point
255 viewUtils.setViewportObj(stage);
256 var offset = viewUtils.getElementOffset(stage);
257 offset[2] = 0;
258 var scrPt = viewUtils.viewToScreen(projPt);
259 //scrPt = scrPt.add(offset);
260 scrPt = vecUtils.vecAdd(3, scrPt, offset);
261
262 // create the hit record
263 var hitRec = Object.create(HitRecord);//new HitRecord();
264 hitRec.setLocalPoint(planePt);
265 hitRec.setPlaneMatrix( wpMat );
266 hitRec.setScreenPoint(scrPt);
267 hitRec.setPlane(currentWorkingPlane);
268 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
269 hitRec.setElt( stage );
270 if (quadPt) hitRec.setUseQuadPoint( true );
271
272 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
273 if (this.gridSnapEnabled())
274 this.snapToGrid( hitRec );
275
276 // save the hit record
277 hitRecArray.push( hitRec );
278
279 // restore the original working plane
280 if (!snap3D && this.hasDragPlane())
281 this.deactivateDragPlane();
282 }
283 }
284 } //if (hitRecArray.length == 0) 242 } //if (hitRecArray.length == 0)
285 243
286 var rtnHit; 244 var rtnHit;
@@ -305,6 +263,62 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
305 } 263 }
306 }, 264 },
307 265
266 snapToStage:
267 {
268 value: function( scrPt, quadPt )
269 {
270 var stage = this.getStage();
271 var l2g = viewUtils.getLocalToGlobalMatrix( stage );
272 var g2l = glmat4.inverse( l2g, [] );
273
274 var pt0 = scrPt.slice(), pt1 = scrPt.slice();
275 pt0[2] = 0.0; pt1[2] = 10;
276
277 var localPt0 = MathUtils.transformAndDivideHomogeneousPoint( pt0, g2l ),
278 localPt1 = MathUtils.transformAndDivideHomogeneousPoint( pt1, g2l );
279
280 var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ),
281 stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage );
282 var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 );
283
284 var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane);
285
286 var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)),
287 wpMatInv = glmat4.inverse( wpMat, [] );
288 var localPt = MathUtils.transformPoint( ptOnWorkingPlane, wpMatInv );
289
290 // create the hit record
291 var hitRec = Object.create(HitRecord);
292 hitRec.setLocalPoint( localPt );
293 hitRec.setPlaneMatrix( wpMat );
294 hitRec.setScreenPoint(scrPt);
295 hitRec.setPlane(workingPlane);
296 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
297 hitRec.setElt( stage );
298 if (quadPt) hitRec.setUseQuadPoint( true );
299
300 // DEBUG CODE
301 // check that the point is on the working plane
302 var tmpStageWorldPt = hitRec.calculateStageWorldPoint();
303 var err = vecUtils.vecDot(3, tmpStageWorldPt, workingPlane) + workingPlane[3];
304 if (MathUtils.fpSign(err) !== 0)
305 console.log( "snapToStage (function) not on working plane: " + err );
306 //////////////////////////////////////////////////////////////////////
307
308 var calculatedScreenPt = hitRec.calculateScreenPoint();
309 hitRec.setScreenPoint(calculatedScreenPt);
310
311 // DEBUG CODE
312 // check that the point is on the working plane
313 var err2 = vecUtils.vecDist(2, calculatedScreenPt, scrPt );
314 if (MathUtils.fpSign(err2) !== 0)
315 console.log( "snapToStage (function) error in screen point: " + err2 );
316 //////////////////////////////////////////////////////////////////////
317
318 return hitRec;
319 }
320 },
321
308 snapToGrid : { 322 snapToGrid : {
309 value: function( hitRec ) 323 value: function( hitRec )
310 { 324 {
@@ -1791,8 +1805,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1791 hSnap.setScreenPoint( scrPt ); 1805 hSnap.setScreenPoint( scrPt );
1792 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1806 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1793 hSnap.setElement( stage ); 1807 hSnap.setElement( stage );
1794 hSnap.setPlane( [0,0,1,0] ); 1808 //hSnap.setPlane( [0,0,1,0] );
1795 hSnap.setPlaneMatrix( Matrix.I(4) ); 1809 //hSnap.setPlaneMatrix( Matrix.I(4) );
1796 if (vSnap.hasAssociatedScreenPoint() ) 1810 if (vSnap.hasAssociatedScreenPoint() )
1797 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1811 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1798 if (vSnap.hasAssociatedScreenPoint2() ) 1812 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1840,8 +1854,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1840 hSnap.setScreenPoint( scrPt ); 1854 hSnap.setScreenPoint( scrPt );
1841 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1855 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1842 hSnap.setElement( stage ); 1856 hSnap.setElement( stage );
1843 hSnap.setPlane( [0,0,1,0] ); 1857 //hSnap.setPlane( [0,0,1,0] );
1844 hSnap.setPlaneMatrix( Matrix.I(4) ); 1858 //hSnap.setPlaneMatrix( Matrix.I(4) );
1845 if (vSnap.hasAssociatedScreenPoint() ) 1859 if (vSnap.hasAssociatedScreenPoint() )
1846 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1860 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1847 if (vSnap.hasAssociatedScreenPoint2() ) 1861 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1895,8 +1909,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1895 hSnap.setScreenPoint( scrPt ); 1909 hSnap.setScreenPoint( scrPt );
1896 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1910 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1897 hSnap.setElement( stage ); 1911 hSnap.setElement( stage );
1898 hSnap.setPlane( [0,0,1,0] ); 1912 //hSnap.setPlane( [0,0,1,0] );
1899 hSnap.setPlaneMatrix( Matrix.I(4) ); 1913 //hSnap.setPlaneMatrix( Matrix.I(4) );
1900 if (vSnap.hasAssociatedScreenPoint() ) 1914 if (vSnap.hasAssociatedScreenPoint() )
1901 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1915 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1902 if (vSnap.hasAssociatedScreenPoint2() ) 1916 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1937,6 +1951,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1937 //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse(); 1951 //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse();
1938 this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] ); 1952 this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] );
1939 1953
1954 //console.log( "setupDragPlane: " + this._dragPlane );
1955
1940 // load the 2D elements 1956 // load the 2D elements
1941 this.load2DCache( this._dragPlane ); 1957 this.load2DCache( this._dragPlane );
1942 } 1958 }
@@ -2028,7 +2044,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
2028 var z = s0[2]; 2044 var z = s0[2];
2029 2045
2030 var typeStr = hitRec.getTypeString();