@@ -15,10 +15,6 @@ var Q = glm.quat;
1515var ORIGINS = 0 ;
1616var TARGETS = 1 ;
1717
18- // Constants for weightingMode
19- var SIMPLE = 0 ;
20- var DIRECTIONAL = 1 ;
21-
2218var TWO_PI = Math . PI * 2 ;
2319
2420/**
@@ -505,7 +501,6 @@ function Anchor(pOrigin, pTarget) {
505501 this . originPosition = V . create ( ) ;
506502 this . targetPosition = V . create ( ) ;
507503 this . transformMatrix = M . create ( ) ;
508- this . directionalMatrices = [ ] ;
509504
510505 if ( pTarget == undefined ) pTarget = pOrigin ;
511506
@@ -551,138 +546,6 @@ function Anchor(pOrigin, pTarget) {
551546 }
552547
553548
554- Anchor . prototype . updateDirectionalMatrices = function ( anchors ) {
555- this . directionalMatrices = [ ] ;
556-
557- for ( var i = 0 ; i < anchors . length ; i ++ ) {
558- var otherAnchor = anchors [ i ] ;
559- var matrix = M . create ( ) ;
560- var matrixDirection = V . create ( ) ;
561-
562- if ( otherAnchor != this ) {
563- var originI = this . getOriginPosition ( ) ;
564- var originJ = otherAnchor . getOriginPosition ( ) ;
565- var targetI = this . getTargetPosition ( ) ;
566- var targetJ = otherAnchor . getTargetPosition ( ) ;
567-
568- // translation
569- M . fromTranslation ( matrix , V . fromValues ( this . targetPosition [ 0 ] - this . originPosition [ 0 ] , this . targetPosition [ 1 ] - this . originPosition [ 1 ] , 0 , 0 ) ) ;
570-
571- // rotation
572- var w1 = Math . atan2 ( originJ [ 1 ] - originI [ 1 ] , originJ [ 0 ] - originI [ 0 ] ) ;
573- var w2 = Math . atan2 ( targetJ [ 1 ] - targetI [ 1 ] , targetJ [ 0 ] - targetI [ 0 ] ) ;
574- var w = H . angleDifference ( w2 , w1 ) ;
575-
576- M . rotate ( matrix , matrix , w ) ;
577-
578- // scaling
579- var d1 = V . dist ( originJ , originI ) ;
580- var d2 = V . dist ( targetJ , targetI ) ;
581- var s = d2 / d1 ;
582-
583- if ( d1 == 0 && d2 == 0 )
584- s = 1 ;
585- else if ( d1 == 0 )
586- s = 10 ;
587-
588- M . scale ( matrix , matrix , [ s , s ] ) ;
589-
590- // direction for this directionalMatrix
591- matrixDirection = V . clone ( originJ ) ;
592- V . sub ( matrixDirection , matrixDirection , originI ) ;
593- V . normalize ( matrixDirection , matrixDirection ) ;
594-
595- this . directionalMatrices . push ( new DirectionalMatrix ( matrix , matrixDirection ) ) ;
596- } else {
597- this . directionalMatrices . push ( null ) ;
598- }
599- }
600- }
601-
602- Anchor . prototype . applyCumulatedMatrix = function ( aToP , exponent , distweights ) {
603- var aToPResult = V . create ( ) ;
604-
605- var aToPNorm = V . clone ( aToP ) ;
606- V . normalize ( aToPNorm , aToPNorm ) ;
607-
608- var weights = [ ] ;
609- var sum = 0 ;
610-
611- for ( var i = 0 ; i < this . directionalMatrices . length ; i ++ ) {
612- if ( this . directionalMatrices [ i ] != null ) {
613- var w = 1 ;
614-
615- // weight depending on direction from anchor to point
616- if ( V . len ( this . directionalMatrices [ i ] . matrixDirection ) > 0 && V . len ( aToPNorm ) > 0 ) {
617- w = V . dot ( this . directionalMatrices [ i ] . matrixDirection , aToPNorm ) + 1 ;
618- if ( w < 0 ) w = 0 ;
619- w = Math . pow ( w , exponent ) ;
620- }
621-
622- // weight depending on distance
623- w *= distweights [ i ] ;
624- // w *= (0.5 + 0.5 * distweights[i]);
625-
626- weights [ i ] = w ;
627- sum += weights [ i ] ;
628- }
629- }
630-
631- for ( var i = 0 ; i < this . directionalMatrices . length ; i ++ ) {
632- if ( this . directionalMatrices [ i ] != null ) {
633- var matrix = this . directionalMatrices [ i ] . matrix ;
634-
635- weights [ i ] = weights [ i ] / sum ;
636-
637- var aToPTrans = V . create ( ) ;
638- V . transformMat4 ( aToPTrans , aToP , matrix ) ;
639-
640- // offset between the delta vector and the transformed delta vector
641- var dvecOffset = V . create ( ) ;
642- V . sub ( dvecOffset , aToPTrans , aToP ) ;
643-
644- // multiply this offset by the weight of this anchor
645- V . scale ( dvecOffset , dvecOffset , weights [ i ] ) ;
646-
647- // add up all offset
648- V . add ( aToPResult , aToPResult , dvecOffset ) ;
649- }
650- }
651-
652- return aToPResult ;
653- }
654-
655-
656-
657- /*
658- * float[] calcWeights(PVector p, ArrayList<Anchor> anchors, int mode) {
659- *
660- * // calculate distances between point and all original anchors float[]
661- * dists = new float[anchors.length]; int n = dists.length;
662- *
663- * int k = -1; float minDist = 10000000;
664- *
665- * for (int i = 0; i < n; i++) { PVector otherPoint; if (mode ==
666- * MultiTransform.ORIGINS) { otherPoint =
667- * anchors[i].getOriginPosition(); } else { otherPoint =
668- * anchors[i].getTargetPosition(); }
669- *
670- * dists[i] = PVector.dist(p, otherPoint); if (dists[i] < minDist && i !=
671- * excludeIndex) { minDist = dists[i]; k = i; } }
672- *
673- * // calc attraction weights (sum of all weights must be 1) float[] weights
674- * = new float[n];
675- *
676- * if (minDist == 0) { weights[k] = 1; } else { float[] distfacs = new
677- * float[n]; float sum = 0;
678- *
679- * for (int i = 0; i < n; i++) { if (i != excludeIndex) { distfacs[i] = 1f /
680- * (pow(dists[i], 1)); sum += distfacs[i]; } }
681- *
682- * for (int i = 0; i < n; i++) { weights[i] = distfacs[i] / sum; } }
683- *
684- * return weights; }
685- */
686549}
687550
688551
@@ -814,7 +677,7 @@ THE SOFTWARE.
814677} , { } ] , 3 :[ function ( require , module , exports ) {
815678module . exports = {
816679 "name" : "StretchTransform.js" ,
817- "version" : "0.2.0 " ,
680+ "version" : "0.2.1 " ,
818681 "description" : "A javascript library to transform a plane in a rubbery way." ,
819682 "license" : "MIT" ,
820683 "main" : "index.js" ,
0 commit comments