diff options
author | Kris Kowal | 2012-07-09 16:38:08 -0700 |
---|---|---|
committer | Kris Kowal | 2012-07-09 16:38:08 -0700 |
commit | 7bee50379c1df86bb571e0e8d6c08e24d25231f5 (patch) | |
tree | 5b11abd0414e0a3ab50ec6276b6334fbd168db7e /js/helper-classes/3D/snap-manager.js | |
parent | 26d4b5ce30e6e0ea6e0fde870853c1e2a673a7b4 (diff) | |
download | ninja-7bee50379c1df86bb571e0e8d6c08e24d25231f5.tar.gz |
BSD License
Diffstat (limited to 'js/helper-classes/3D/snap-manager.js')
-rwxr-xr-x | js/helper-classes/3D/snap-manager.js | 63 |
1 files changed, 32 insertions, 31 deletions
diff --git a/js/helper-classes/3D/snap-manager.js b/js/helper-classes/3D/snap-manager.js index ab6d106d..5eb93b8c 100755 --- a/js/helper-classes/3D/snap-manager.js +++ b/js/helper-classes/3D/snap-manager.js | |||
@@ -1,24 +1,25 @@ | |||
1 | /* <copyright> | 1 | /* <copyright> |
2 | Copyright (c) 2012, Motorola Mobility, Inc | 2 | Copyright (c) 2012, Motorola Mobility LLC. |
3 | All Rights Reserved. | 3 | All Rights Reserved. |
4 | BSD License. | ||
5 | 4 | ||
6 | Redistribution and use in source and binary forms, with or without | 5 | Redistribution and use in source and binary forms, with or without |
7 | modification, are permitted provided that the following conditions are met: | 6 | modification, are permitted provided that the following conditions are met: |
8 | 7 | ||
9 | - Redistributions of source code must retain the above copyright notice, | 8 | * Redistributions of source code must retain the above copyright notice, |
10 | this list of conditions and the following disclaimer. | 9 | this list of conditions and the following disclaimer. |
11 | - Redistributions in binary form must reproduce the above copyright | 10 | |
12 | notice, this list of conditions and the following disclaimer in the | 11 | * Redistributions in binary form must reproduce the above copyright notice, |
13 | documentation and/or other materials provided with the distribution. | 12 | this list of conditions and the following disclaimer in the documentation |
14 | - Neither the name of Motorola Mobility nor the names of its contributors | 13 | and/or other materials provided with the distribution. |
15 | may be used to endorse or promote products derived from this software | 14 | |
16 | without specific prior written permission. | 15 | * Neither the name of Motorola Mobility LLC nor the names of its |
16 | contributors may be used to endorse or promote products derived from this | ||
17 | software without specific prior written permission. | ||
17 | 18 | ||
18 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" | 19 | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" |
19 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | 20 | AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE |
20 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | 21 | IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE |
21 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE | 22 | ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE |
22 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR | 23 | LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR |
23 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF | 24 | CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF |
24 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS | 25 | SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS |
@@ -210,7 +211,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
210 | }, | 211 | }, |
211 | 212 | ||
212 | snap : { | 213 | snap : { |
213 | value: function (xScreen, yScreen, snap3D, quadPt) | 214 | value: function (xScreen, yScreen, snap3D, quadPt) |
214 | { | 215 | { |
215 | // force a 3D snap if a 2D snap is requested but the 2D cache has not been initialized | 216 | // force a 3D snap if a 2D snap is requested but the 2D cache has not been initialized |
216 | if (!snap3D && !this._elementCache) snap3D = true; | 217 | if (!snap3D && !this._elementCache) snap3D = true; |
@@ -282,7 +283,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
282 | this.deactivateDragPlane(); | 283 | this.deactivateDragPlane(); |
283 | 284 | ||
284 | this.setLastHit( rtnHit ); | 285 | this.setLastHit( rtnHit ); |
285 | 286 | ||
286 | //rtnHit.test(); // DEBUG CODE. REMOVE THIS | 287 | //rtnHit.test(); // DEBUG CODE. REMOVE THIS |
287 | return rtnHit; | 288 | return rtnHit; |
288 | } | 289 | } |
@@ -305,7 +306,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
305 | var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ), | 306 | var stageWorldPt0 = viewUtils.localToStageWorld( localPt0, stage ), |
306 | stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage ); | 307 | stageWorldPt1 = viewUtils.localToStageWorld( localPt1, stage ); |
307 | var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 ); | 308 | var vec = vecUtils.vecSubtract( 3, stageWorldPt1, stageWorldPt0 ); |
308 | 309 | ||
309 | var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane); | 310 | var ptOnWorkingPlane = MathUtils.vecIntersectPlane(stageWorldPt0, vec, workingPlane); |
310 | 311 | ||
311 | var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)), | 312 | var wpMat = drawUtils.getPlaneToWorldMatrix(workingPlane, MathUtils.getPointOnPlane(workingPlane)), |
@@ -1023,7 +1024,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1023 | } | 1024 | } |
1024 | }, | 1025 | }, |
1025 | 1026 | ||
1026 | hSnapToElements : | 1027 | hSnapToElements : |
1027 | { | 1028 | { |
1028 | value: function( elt, hitRecs, depth, globalScrPt ) | 1029 | value: function( elt, hitRecs, depth, globalScrPt ) |
1029 | { | 1030 | { |
@@ -1081,9 +1082,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1081 | } | 1082 | } |
1082 | }, | 1083 | }, |
1083 | 1084 | ||
1084 | snapToElement : | 1085 | snapToElement : |
1085 | { | 1086 | { |
1086 | value: function( elt, globalScrPt ) | 1087 | value: function( elt, globalScrPt ) |
1087 | { | 1088 | { |
1088 | if (this.isAvoidedElement(elt) ) return null; | 1089 | if (this.isAvoidedElement(elt) ) return null; |
1089 | 1090 | ||
@@ -1096,7 +1097,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1096 | var eltMat = viewUtils.getLocalToGlobalMatrix( elt ); | 1097 | var eltMat = viewUtils.getLocalToGlobalMatrix( elt ); |
1097 | for (var i=0; i<4; i++) | 1098 | for (var i=0; i<4; i++) |
1098 | bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat); | 1099 | bounds3D[i] = viewUtils.localToGlobal2(bounds[i], eltMat); |
1099 | 1100 | ||
1100 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); | 1101 | var hitRec = this.snapToScreenBounds( elt, globalScrPt, bounds, bounds3D ); |
1101 | 1102 | ||
1102 | // see if we can snap to a contained geometry object | 1103 | // see if we can snap to a contained geometry object |
@@ -1117,9 +1118,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1117 | } | 1118 | } |
1118 | }, | 1119 | }, |
1119 | 1120 | ||
1120 | snapToScreenBounds : | 1121 | snapToScreenBounds : |
1121 | { | 1122 | { |
1122 | value: function( elt, scrPt, bounds, bounds3D ) | 1123 | value: function( elt, scrPt, bounds, bounds3D ) |
1123 | { | 1124 | { |
1124 | // push the element as the current viewport element | 1125 | // push the element as the current viewport element |
1125 | viewUtils.pushViewportObj( elt ); | 1126 | viewUtils.pushViewportObj( elt ); |
@@ -1328,9 +1329,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1328 | } | 1329 | } |
1329 | }, | 1330 | }, |
1330 | 1331 | ||
1331 | hSnapToContainedElements : | 1332 | hSnapToContainedElements : |
1332 | { | 1333 | { |
1333 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) | 1334 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) |
1334 | { | 1335 | { |
1335 | if (!glObj) return false; | 1336 | if (!glObj) return false; |
1336 | 1337 | ||
@@ -1345,7 +1346,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1345 | 1346 | ||
1346 | doSnapToContainedElement: | 1347 | doSnapToContainedElement: |
1347 | { | 1348 | { |
1348 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) | 1349 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) |
1349 | { | 1350 | { |
1350 | var rtnVal = false; | 1351 | var rtnVal = false; |
1351 | 1352 | ||
@@ -1443,9 +1444,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1443 | } | 1444 | } |
1444 | }, | 1445 | }, |
1445 | 1446 | ||
1446 | snapToContainedElement : | 1447 | snapToContainedElement : |
1447 | { | 1448 | { |
1448 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) | 1449 | value: function( eyePt, dir, glObj, hitRec, targetScrPt ) |
1449 | { | 1450 | { |
1450 | var rtnVal = false; | 1451 | var rtnVal = false; |
1451 | var elt = hitRec.getElement(); | 1452 | var elt = hitRec.getElement(); |
@@ -1466,10 +1467,10 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1466 | case glObj.GEOM_TYPE_PATH: | 1467 | case glObj.GEOM_TYPE_PATH: |
1467 | // Snapping not implemented for these type, but don't throw an error... | 1468 | // Snapping not implemented for these type, but don't throw an error... |
1468 | break; | 1469 | break; |
1469 | 1470 | ||
1470 | case glObj.GEOM_TYPE_BRUSH_STROKE: | 1471 | case glObj.GEOM_TYPE_BRUSH_STROKE: |
1471 | break; //don't throw error because snapping not yet implemented | 1472 | break; //don't throw error because snapping not yet implemented |
1472 | 1473 | ||
1473 | case glObj.GEOM_TYPE_CUBIC_BEZIER: | 1474 | case glObj.GEOM_TYPE_CUBIC_BEZIER: |
1474 | rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); | 1475 | rtnVal = this.doSnapToContainedElement( eyePt, dir, glObj, hitRec, targetScrPt ); |
1475 | break; | 1476 | break; |
@@ -1519,7 +1520,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1519 | // add the projection matrix | 1520 | // add the projection matrix |
1520 | var projMat = world.makePerspectiveMatrix(); | 1521 | var projMat = world.makePerspectiveMatrix(); |
1521 | //var projInv = projMat.inverse(); | 1522 | //var projInv = projMat.inverse(); |
1522 | var projInv = glmat4.inverse(projMat, []); | 1523 | var projInv = glmat4.inverse(projMat, []); |
1523 | var camInv = world.getCameraMatInverse(); | 1524 | var camInv = world.getCameraMatInverse(); |
1524 | //var glToNDC = projMat.multiply( camInv ); | 1525 | //var glToNDC = projMat.multiply( camInv ); |
1525 | var glToNDC = glmat4.multiply( projMat, camInv, [] ); | 1526 | var glToNDC = glmat4.multiply( projMat, camInv, [] ); |
@@ -1569,9 +1570,9 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
1569 | } | 1570 | } |
1570 | }, | 1571 | }, |
1571 | 1572 | ||
1572 | GLToView : | 1573 | GLToView : |
1573 | { | 1574 | { |
1574 | value: function( glPt, world ) | 1575 | value: function( glPt, world ) |
1575 | { | 1576 | { |
1576 | var projMat = world.makePerspectiveMatrix(); | 1577 | var projMat = world.makePerspectiveMatrix(); |
1577 | //var mat = projMat.multiply( world.getCameraMatInverse() ); | 1578 | //var mat = projMat.multiply( world.getCameraMatInverse() ); |
@@ -2134,7 +2135,7 @@ var SnapManager = exports.SnapManager = Montage.create(Component, { | |||
2134 | 2135 | ||
2135 | drawHit : | 2136 | drawHit : |
2136 | { | 2137 | { |
2137 | value: function( hitRec ) | 2138 |