diff options
author | Pushkar Joshi | 2012-04-17 14:49:18 -0700 |
---|---|---|
committer | Pushkar Joshi | 2012-04-17 14:49:18 -0700 |
commit | df903a01e14134cadf109b733d09c6eadfa3966b (patch) | |
tree | 2351f1c05b2f852053fa0be533072088a9ad4e7c /js/helper-classes/3D/view-utils.js | |
parent | 036cf034e124dbc1f4893e90f7c6d240904a3faf (diff) | |
parent | cacb4a21825818af392c2949967b0f3c1df509c5 (diff) | |
download | ninja-df903a01e14134cadf109b733d09c6eadfa3966b.tar.gz |
Merge branch 'master' into pentool
Conflicts:
js/tools/PenTool.js
Diffstat (limited to 'js/helper-classes/3D/view-utils.js')
-rwxr-xr-x | js/helper-classes/3D/view-utils.js | 257 |
1 files changed, 145 insertions, 112 deletions
diff --git a/js/helper-classes/3D/view-utils.js b/js/helper-classes/3D/view-utils.js index 35f4a568..dabb1fcf 100755 --- a/js/helper-classes/3D/view-utils.js +++ b/js/helper-classes/3D/view-utils.js | |||
@@ -37,10 +37,8 @@ exports.ViewUtils = Montage.create(Component, { | |||
37 | setViewportObj: { | 37 | setViewportObj: { |
38 | value: function( vp ) { | 38 | value: function( vp ) { |
39 | this.m_viewportObj = vp; | 39 | this.m_viewportObj = vp; |
40 | this._perspectiveDist = 1400; | ||
41 | 40 | ||
42 | var dist = this.getPerspectiveDistFromElement( vp ); | 41 | this._perspectiveDist = this.getPerspectiveDistFromElement( vp ); |
43 | var mode = this.getPerspectiveModeFromElement( vp ); | ||
44 | } | 42 | } |
45 | }, | 43 | }, |
46 | getViewportObj: { value: function() { return this.m_viewportObj; } }, | 44 | getViewportObj: { value: function() { return this.m_viewportObj; } }, |
@@ -260,7 +258,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
260 | 258 | ||
261 | // transform the point up the tree | 259 | // transform the point up the tree |
262 | var child = elt; | 260 | var child = elt; |
263 | var parent = elt.parentElement; | 261 | var parent = elt.offsetParent; |
264 | while ( parent ) | 262 | while ( parent ) |
265 | { | 263 | { |
266 | // go to screen space of the current child | 264 | // go to screen space of the current child |
@@ -288,7 +286,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
288 | } | 286 | } |
289 | 287 | ||
290 | child = parent; | 288 | child = parent; |
291 | parent = parent.parentElement; | 289 | parent = parent.offsetParent; |
292 | } | 290 | } |
293 | 291 | ||
294 | return pt; | 292 | return pt; |
@@ -304,7 +302,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
304 | 302 | ||
305 | // transform the bounds up the tree | 303 | // transform the bounds up the tree |
306 | var child = elt; | 304 | var child = elt; |
307 | var parent = elt.parentElement; | 305 | var parent = elt.offsetParent; |
308 | while ( parent ) | 306 | while ( parent ) |
309 | { | 307 | { |
310 | pt = this.childToParent( pt, child ); | 308 | pt = this.childToParent( pt, child ); |
@@ -312,7 +310,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
312 | if (parent === this._rootElement) break; | 310 | if (parent === this._rootElement) break; |
313 | 311 | ||
314 | child = parent; | 312 | child = parent; |
315 | parent = parent.parentElement; | 313 | parent = parent.offsetParent; |
316 | } | 314 | } |
317 | 315 | ||
318 | ///////////////////////////////////////////////////////// | 316 | ///////////////////////////////////////////////////////// |
@@ -347,7 +345,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
347 | if (pt.length == 2) pt[2] = 0; | 345 | if (pt.length == 2) pt[2] = 0; |
348 | 346 | ||
349 | // transform the bounds up the tree | 347 | // transform the bounds up the tree |
350 | var parent = child.parentElement; | 348 | var parent = child.offsetParent; |
351 | if ( parent ) | 349 | if ( parent ) |
352 | { | 350 | { |
353 | this.setViewportObj( child ); | 351 | this.setViewportObj( child ); |
@@ -359,11 +357,21 @@ exports.ViewUtils = Montage.create(Component, { | |||
359 | 357 | ||
360 | if (this.elementHas3D( child )) | 358 | if (this.elementHas3D( child )) |
361 | { | 359 | { |
360 | // TODO - Commenting out flatten support until new perspective workflow is fully working | ||
362 | // if (flatten) pt[2] = 0; | 361 | // if (flatten) pt[2] = 0; |
362 | // var flatten = (parent !== this._rootElement) && (ElementsMediator.getProperty(parent, "-webkit-transform-style") !== "preserve-3d"); | ||
363 | // if(flatten) | ||
364 | // { | ||
365 | // pt[2] = 0; | ||
366 | // } | ||
363 | pt = this.screenToView( pt[0], pt[1], pt[2] ); | 367 | pt = this.screenToView( pt[0], pt[1], pt[2] ); |
364 | pt[3] = 1; | 368 | pt[3] = 1; |
365 | //var wPt = childMat.multiply( pt ); | 369 | //var wPt = childMat.multiply( pt ); |
366 | var wPt = glmat4.multiplyVec3( childMat, pt, [] ); | 370 | var wPt = glmat4.multiplyVec3( childMat, pt, [] ); |
371 | // if(flatten) | ||
372 | // { | ||
373 | // wPt[2] = 0; | ||
374 | // } | ||
367 | var scrPt = this.viewToScreen( wPt ); | 375 | var scrPt = this.viewToScreen( wPt ); |
368 | pt = scrPt; | 376 | pt = scrPt; |
369 | } | 377 | } |
@@ -385,7 +393,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
385 | pt[3] = 1; | 393 | pt[3] = 1; |
386 | 394 | ||
387 | // transform the bounds up the tree | 395 | // transform the bounds up the tree |
388 | var parent = child.parentElement; | 396 | var parent = child.offsetParent; |
389 | if ( parent ) | 397 | if ( parent ) |
390 | { | 398 | { |
391 | this.setViewportObj( child ); | 399 | this.setViewportObj( child ); |
@@ -420,7 +428,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
420 | 428 | ||
421 | /* | 429 | /* |
422 | this.pushViewportObj( elt ); | 430 | this.pushViewportObj( elt ); |
423 | var parent = elt.parentElement; | 431 | var parent = elt.offsetParent; |
424 | var offset = this.getElementOffset( elt ); | 432 | var offset = this.getElementOffset( elt ); |
425 | offset[2] = 0; | 433 | offset[2] = 0; |
426 | var localEyePt = this.getCenterOfProjection(); | 434 | var localEyePt = this.getCenterOfProjection(); |
@@ -479,7 +487,15 @@ exports.ViewUtils = Montage.create(Component, { | |||
479 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); | 487 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); |
480 | 488 | ||
481 | // project the view point onto the plane | 489 | // project the view point onto the plane |
482 | var eyePt = this.getEyePoint(); | 490 | var eyePt; |
491 | if(this.getPerspectiveDistFromElement(child)) | ||
492 | { | ||
493 | eyePt = this.getEyePoint(); | ||
494 | } | ||
495 | else | ||
496 | { | ||
497 | eyePt = [viewPt[0], viewPt[1], 1400]; | ||
498 | } | ||
483 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); | 499 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); |
484 | 500 | ||
485 | var childPt; | 501 | var childPt; |
@@ -521,7 +537,15 @@ exports.ViewUtils = Montage.create(Component, { | |||
521 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); | 537 | var plane = MathUtils.transformPlane( [0,0,1,0], mat ); |
522 | 538 | ||
523 | // project the view point onto the plane | 539 | // project the view point onto the plane |
524 | var eyePt = this.getEyePoint(); | 540 | var eyePt; |
541 | if(this.getPerspectiveDistFromElement(child)) | ||
542 | { | ||
543 | eyePt = this.getEyePoint(); | ||
544 | } | ||
545 | else | ||
546 | { | ||
547 | eyePt = [viewPt[0], viewPt[1], 1400]; | ||
548 | } | ||
525 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); | 549 | var projPt = MathUtils.vecIntersectPlane( eyePt, MathUtils.vecSubtract(viewPt,eyePt), plane ); |
526 | 550 | ||
527 | this.popViewportObj(); | 551 | this.popViewportObj(); |
@@ -532,7 +556,7 @@ exports.ViewUtils = Montage.create(Component, { | |||
532 | 556 | ||
533 | 557 | ||
534 | parentToChildVec: { | 558 | parentToChildVec: { |
535 | value: function( parentPt, child ) { | 559 | value: function( parentPt, child, rtnEyePt ) { |
536 | var pt = parentPt.slice(0); | 560 | var pt = parentPt.slice(0); |
537 | if (pt.length == 2) pt[2] = 0.0; | 561 | if (pt.length == 2) pt[2] = 0.0; |
538 | 562 | ||
@@ -545,12 +569,24 @@ exports.ViewUtils = Montage.create(Component, { | |||
545 | this.setViewportObj( child ); | 569 | this.setViewportObj( child ); |
546 | pt = this.screenToView( pt[0], pt[1], pt[2] ); | 570 | pt = this.screenToView( pt[0], pt[1], pt[2] ); |
547 | 571 | ||
548 | var eyePt = this.getEyePoint(); | 572 | var eyePt; |
549 | //var eyePt = [0, 0, 0]; | 573 | if(this.getPerspectiveDistFromElement(child)) |
550 | //var vec = [pt[0], pt[1], pt[2]].subtract( eyePt ); | 574 | { |
575 | eyePt = this.getEyePoint(); | ||
576 | } | ||
577 | else | ||
578 | { | ||
579 | eyePt = [pt[0], pt[1], 1400]; | ||
580 | } | ||
551 | var vec = vecUtils.vecSubtract(3, [pt[0], pt[1], pt[2]], eyePt); | 581 | var vec = vecUtils.vecSubtract(3, [pt[0], pt[1], pt[2]], eyePt); |
552 | vec = vecUtils.vecNormalize( 3, vec ); | 582 | vec = vecUtils.vecNormalize( 3, vec ); |
553 | 583 | ||
584 | if(rtnEyePt) | ||
585 | { | ||
586 | rtnEyePt[0] = eyePt[0]; | ||
587 | rtnEyePt[1] = eyePt[1]; | ||
588 | rtnEyePt[2] = eyePt[2]; | ||
589 | } | ||
554 | return vec; | 590 | return vec; |
555 | } | 591 | } |
556 | }, | 592 | }, |
@@ -566,19 +602,6 @@ exports.ViewUtils = Montage.create(Component, { | |||
566 | w = elt.offsetWidth, | 602 | w = elt.offsetWidth, |
567 | h = elt.offsetHeight; | 603 | h = elt.offsetHeight; |
568 | 604 | ||
569 | if(elt.width) | ||
570 | w = elt.width; | ||
571 | if(elt.height) | ||
572 | h = elt.height; | ||
573 | |||
574 | if (elt.style) | ||
575 | { | ||
576 | if (elt.style.left) left = MathUtils.styleToNumber(elt.style.left); | ||
577 | if (elt.style.top) top = MathUtils.styleToNumber(elt.style.top); | ||
578 | if (elt.style.width) w = MathUtils.styleToNumber(elt.style.width); | ||
579 | if (elt.style.height) h = MathUtils.styleToNumber(elt.style.height); | ||
580 | } | ||
581 | |||
582 | // if (elt instanceof SVGSVGElement) { | 605 | // if (elt instanceof SVGSVGElement) { |