aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
authorhwc4872012-05-22 16:40:42 -0700
committerhwc4872012-05-22 16:40:42 -0700
commit08851078e89e9d4cb8fa341fa697a91be8de8ab9 (patch)
treefee8c0d38c1c540ef00c33e728346d765a4e699c /js/helper-classes
parent50ede4afa801f53caff7939dad0408f9a0a8b744 (diff)
parent862ee363584dfba4bdd9abacbc3a3244c7ec66b5 (diff)
downloadninja-08851078e89e9d4cb8fa341fa697a91be8de8ab9.tar.gz
Merge branch 'master' of github.com:Motorola-Mobility/ninja-internal into Textures
Conflicts: js/lib/geom/shape-primitive.js js/lib/rdge/materials/linear-gradient-material.js
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 6766ac7f..97901d50 100755
--- a/js/helper-classes/3D/snap-manager.js
+++ b/js/helper-classes/3D/snap-manager.js
@@ -230,64 +230,22 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
230 else 230 else
231 parentPt = [xScreen, yScreen, 0.0]; 231 parentPt = [xScreen, yScreen, 0.0];
232 232
233 var eyePt = []; 233 if (!snap3D && this._hasDragPlane)
234 var vec = viewUtils.parentToChildVec(parentPt, stage, eyePt); 234 this.activateDragPlane();
235 if (vec) 235
236 { 236 var hitRec = this.snapToStage( parentPt, quadPt );
237 // activate the drag working plane 237
238 if (!snap3D && this.hasDragPlane()) 238 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
239 this.activateDragPlane(); 239 if (this.gridSnapEnabled())
240 240 this.snapToGrid( hitRec );
241 // project to the working plane 241
242 var currentWorkingPlane = workingPlane.slice(0); 242 // save the hit record
243 var wp = currentWorkingPlane.slice(0); 243 hitRecArray.push( hitRec );
244 var mat = viewUtils.getMatrixFromElement(stage); 244
245 wp = MathUtils.transformPlane(wp, mat); 245 // restore the original working plane
246 var projPt = MathUtils.vecIntersectPlane(eyePt, vec, wp); 246 if (!snap3D && this.hasDragPlane())
247 if (projPt) 247 this.deactivateDragPlane();
248 { 248
249 // the local point gets stored in the coordinate space of the plane
250 var wpMat = drawUtils.getPlaneToWorldMatrix(currentWorkingPlane, MathUtils.getPointOnPlane(currentWorkingPlane));
251 projPt[3] = 1.0;
252 //var planeToViewMat = mat.multiply(wpMat);
253 var planeToViewMat = glmat4.multiply(mat, wpMat, []);
254 //var viewToPlaneMat = planeToViewMat.inverse();
255 var viewToPlaneMat = glmat4.inverse( planeToViewMat, [] );
256 var planePt = projPt.slice(0);
257 planePt[3] = 1.0;
258 //planePt = viewToPlaneMat.multiply(planePt);
259 planePt = glmat4.multiplyVec3( viewToPlaneMat, planePt );
260
261 // get the screen position of the projected point
262 viewUtils.setViewportObj(stage);
263 var offset = viewUtils.getElementOffset(stage);
264 offset[2] = 0;
265 var scrPt = viewUtils.viewToScreen(projPt);
266 //scrPt = scrPt.add(offset);
267 scrPt = vecUtils.vecAdd(3, scrPt, offset);
268
269 // create the hit record
270 var hitRec = Object.create(HitRecord);//new HitRecord();
271 hitRec.setLocalPoint(planePt);
272 hitRec.setPlaneMatrix( wpMat );
273 hitRec.setScreenPoint(scrPt);
274 hitRec.setPlane(currentWorkingPlane);
275 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
276 hitRec.setElt( stage );
277 if (quadPt) hitRec.setUseQuadPoint( true );
278
279 // try snapping to the 3D grid, or to the stage boundaries if the grid is not displayed
280 if (this.gridSnapEnabled())
281 this.snapToGrid( hitRec );
282
283 // save the hit record
284 hitRecArray.push( hitRec );
285
286 // restore the original working plane
287 if (!snap3D && this.hasDragPlane())
288 this.deactivateDragPlane();
289 }
290 }
291 } //if (hitRecArray.length == 0) 249 } //if (hitRecArray.length == 0)
292 250
293 var rtnHit; 251 var rtnHit;
@@ -312,6 +270,62 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
312 } 270 }
313 }, 271 },
314 272
273 snapToStage:
274 {
275 value: function( scrPt, quadPt )
276 {
277 var stage = this.getStage();
278 var l2g = viewUtils.getLocalToGlobalMatrix( stage );
279 var g2l = glmat4.inverse( l2g, [] );
280
281 var pt0 = scrPt.slice(), pt1 = scrPt.slice();
282 pt0[2] = 0.0; pt1[2] = 10;
283
284 var localPt0 = MathUtils.transformAndDivideHomogeneousPoint( pt0, g2l ),
285 localPt1 = MathUtils.transformAndDivideHomogeneousPoint( pt1, g2l );
286
287 var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ),
288 stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage );
289 var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 );
290
291 var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane);
292
293 var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)),
294 wpMatInv = glmat4.inverse( wpMat, [] );
295 var localPt = MathUtils.transformPoint( ptOnWorkingPlane, wpMatInv );
296
297 // create the hit record
298 var hitRec = Object.create(HitRecord);
299 hitRec.setLocalPoint( localPt );
300 hitRec.setPlaneMatrix( wpMat );
301 hitRec.setScreenPoint(scrPt);
302 hitRec.setPlane(workingPlane);
303 hitRec.setType( hitRec.SNAP_TYPE_STAGE );
304 hitRec.setElt( stage );
305 if (quadPt) hitRec.setUseQuadPoint( true );
306
307 // DEBUG CODE
308 // check that the point is on the working plane
309 var tmpStageWorldPt = hitRec.calculateStageWorldPoint();
310 var err = vecUtils.vecDot(3, tmpStageWorldPt, workingPlane) + workingPlane[3];
311 if (MathUtils.fpSign(err) !== 0)
312 console.log( "snapToStage (function) not on working plane: " + err );
313 //////////////////////////////////////////////////////////////////////
314
315 var calculatedScreenPt = hitRec.calculateScreenPoint();
316 hitRec.setScreenPoint(calculatedScreenPt);
317
318 // DEBUG CODE
319 // check that the point is on the working plane
320 var err2 = vecUtils.vecDist(2, calculatedScreenPt, scrPt );
321 if (MathUtils.fpSign(err2) !== 0)
322 console.log( "snapToStage (function) error in screen point: " + err2 );
323 //////////////////////////////////////////////////////////////////////
324
325 return hitRec;
326 }
327 },
328
315 snapToGrid : { 329 snapToGrid : {
316 value: function( hitRec ) 330 value: function( hitRec )
317 { 331 {
@@ -1799,8 +1813,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1799 hSnap.setScreenPoint( scrPt ); 1813 hSnap.setScreenPoint( scrPt );
1800 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1814 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1801 hSnap.setElement( stage ); 1815 hSnap.setElement( stage );
1802 hSnap.setPlane( [0,0,1,0] ); 1816 //hSnap.setPlane( [0,0,1,0] );
1803 hSnap.setPlaneMatrix( Matrix.I(4) ); 1817 //hSnap.setPlaneMatrix( Matrix.I(4) );
1804 if (vSnap.hasAssociatedScreenPoint() ) 1818 if (vSnap.hasAssociatedScreenPoint() )
1805 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1819 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1806 if (vSnap.hasAssociatedScreenPoint2() ) 1820 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1848,8 +1862,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1848 hSnap.setScreenPoint( scrPt ); 1862 hSnap.setScreenPoint( scrPt );
1849 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1863 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1850 hSnap.setElement( stage ); 1864 hSnap.setElement( stage );
1851 hSnap.setPlane( [0,0,1,0] ); 1865 //hSnap.setPlane( [0,0,1,0] );
1852 hSnap.setPlaneMatrix( Matrix.I(4) ); 1866 //hSnap.setPlaneMatrix( Matrix.I(4) );
1853 if (vSnap.hasAssociatedScreenPoint() ) 1867 if (vSnap.hasAssociatedScreenPoint() )
1854 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1868 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1855 if (vSnap.hasAssociatedScreenPoint2() ) 1869 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1903,8 +1917,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1903 hSnap.setScreenPoint( scrPt ); 1917 hSnap.setScreenPoint( scrPt );
1904 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED ); 1918 hSnap.setType( hSnap.SNAP_TYPE_ALIGN_MERGED );
1905 hSnap.setElement( stage ); 1919 hSnap.setElement( stage );
1906 hSnap.setPlane( [0,0,1,0] ); 1920 //hSnap.setPlane( [0,0,1,0] );
1907 hSnap.setPlaneMatrix( Matrix.I(4) ); 1921 //hSnap.setPlaneMatrix( Matrix.I(4) );
1908 if (vSnap.hasAssociatedScreenPoint() ) 1922 if (vSnap.hasAssociatedScreenPoint() )
1909 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() ); 1923 hSnap.setAssociatedScreenPoint( vSnap.getAssociatedScreenPoint() );
1910 if (vSnap.hasAssociatedScreenPoint2() ) 1924 if (vSnap.hasAssociatedScreenPoint2() )
@@ -1945,6 +1959,8 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
1945 //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse(); 1959 //this._globalToStageWorldMat = this._stageWorldToGlobalMat.inverse();
1946 this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] ); 1960 this._globalToStageWorldMat = glmat4.inverse( this._stageWorldToGlobalMat, [] );
1947 1961
1962 //console.log( "setupDragPlane: " + this._dragPlane );
1963
1948 // load the 2D elements 1964 // load the 2D elements
1949 this.load2DCache( this._dragPlane ); 1965 this.load2DCache( this._dragPlane );
1950 } 1966 }
@@ -2036,7 +2052,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, {
2036 var z = s0[2]; 2052 var z = s0[2];
2037 2053
2038 var typeStr = hitRec.getTypeString();