aboutsummaryrefslogtreecommitdiff
path: root/js/helper-classes
diff options
context:
space:
mode:
Diffstat (limited to 'js/helper-classes')
-rw-r--r--js/helper-classes/RDGE/GLSubpath.js168
1 files changed, 98 insertions, 70 deletions
diff --git a/js/helper-classes/RDGE/GLSubpath.js b/js/helper-classes/RDGE/GLSubpath.js
index c4ca1b20..9b6ae917 100644
--- a/js/helper-classes/RDGE/GLSubpath.js
+++ b/js/helper-classes/RDGE/GLSubpath.js
@@ -433,17 +433,111 @@ GLSubpath.prototype.pickAnchor = function (pickX, pickY, pickZ, radius) {
433 var retCode = this.SEL_NONE; 433 var retCode = this.SEL_NONE;
434 var radSq = radius * radius; 434 var radSq = radius * radius;
435 var minDistance = Infinity; 435 var minDistance = Infinity;
436 for (var i = 0; i < numAnchors; i++) { 436 //check if the clicked location is close to the currently selected anchor position
437 var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ); 437 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){
438 var distSq = this._Anchors[this._selectedAnchorIndex].getDistanceSq(pickX, pickY, pickZ);
438 //check the anchor point 439 //check the anchor point
439 if (distSq < minDistance && distSq < radSq) { 440 if (distSq < minDistance && distSq < radSq) {
440 selAnchorIndex = i; 441 selAnchorIndex = this._selectedAnchorIndex;
441 minDistance = distSq; 442 minDistance = distSq;
443 retCode = retCode | this.SEL_ANCHOR;
442 } 444 }
443 }//for every anchor i 445 }
446 //now check if the click location is close to any anchor position
447 if (selAnchorIndex===-1) {
448 for (var i = 0; i < numAnchors; i++) {
449 var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ);
450 //check the anchor point
451 if (distSq < minDistance && distSq < radSq) {
452 selAnchorIndex = i;
453 minDistance = distSq;
454 }
455 }//for every anchor i
456 }
444 return selAnchorIndex; 457 return selAnchorIndex;
445} 458}
446 459
460
461//pick the path point closest to the specified location, return null if some anchor point (or its handles) is within radius, else return the parameter distance
462GLSubpath.prototype.pickPath = function (pickX, pickY, pickZ, radius) {
463 var numAnchors = this._Anchors.length;
464 var selAnchorIndex = -1;
465 var retCode = this.SEL_NONE;
466 var radSq = radius * radius;
467 var minDistance = Infinity;
468 //check if the clicked location is close to the currently selected anchor position
469 if (this._selectedAnchorIndex>=0 && this._selectedAnchorIndex<this._Anchors.length){
470 var distSq = this._Anchors[this._selectedAnchorIndex].getDistanceSq(pickX, pickY, pickZ);
471 //check the anchor point
472 if (distSq < minDistance && distSq < radSq) {
473 selAnchorIndex = this._selectedAnchorIndex;
474 minDistance = distSq;
475 retCode = retCode | this.SEL_ANCHOR;
476 }
477 }
478 //now check if the click location is close to any anchor position
479 if (selAnchorIndex===-1) {
480 for (var i = 0; i < numAnchors; i++) {
481 var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ);
482 //check the anchor point
483 if (distSq < minDistance && distSq < radSq) {
484 selAnchorIndex = i;
485 minDistance = distSq;
486 retCode = retCode | this.SEL_ANCHOR;
487 }
488 }//for every anchor i
489 }
490
491 //check the prev and next of the selected anchor if the above did not register a hit
492 if (this._selectedAnchorIndex>=0 && selAnchorIndex === -1) {
493 var distSq = this._Anchors[this._selectedAnchorIndex].getPrevDistanceSq(pickX, pickY, pickZ);
494 if (distSq < minDistance && distSq < radSq){
495 selAnchorIndex = this._selectedAnchorIndex;
496 minDistance = distSq;
497 retCode = retCode | this.SEL_PREV;
498 } else {
499 //check the next for this anchor point
500 distSq = this._Anchors[this._selectedAnchorIndex].getNextDistanceSq(pickX, pickY, pickZ);
501 if (distSq<minDistance && distSq<radSq){
502 selAnchorIndex = this._selectedAnchorIndex;
503 minDistance = distSq;
504 retCode = retCode | this.SEL_NEXT;
505 }
506 }
507 }
508 var retParam = null;
509 if (retCode !== this.SEL_NONE) {
510 retCode = retCode | this.SEL_PATH; //ensure that path is also selected if anything else is selected
511 this._selectedAnchorIndex = selAnchorIndex;
512 } else {
513 this._selectedAnchorIndex = -1;
514 var numSegments = this._isClosed ? numAnchors : numAnchors-1;
515 for (var i = 0; i < numSegments; i++) {
516 var nextIndex = (i+1)%numAnchors;
517 //check if the point is close to the bezier segment between anchor i and anchor nextIndex
518 var controlPoints = Vector.create([Vector.create([this._Anchors[i].getPosX(),this._Anchors[i].getPosY(),this._Anchors[i].getPosZ()]),
519 Vector.create([this._Anchors[i].getNextX(),this._Anchors[i].getNextY(),this._Anchors[i].getNextZ()]),
520 Vector.create([this._Anchors[nextIndex].getPrevX(),this._Anchors[nextIndex].getPrevY(),this._Anchors[nextIndex].getPrevZ()]),
521 Vector.create([this._Anchors[nextIndex].getPosX(),this._Anchors[nextIndex].getPosY(),this._Anchors[nextIndex].getPosZ()])]);
522 var point = Vector.create([pickX, pickY, pickZ]);
523 if (this._isWithinBoundingBox(point, controlPoints, radius)) {
524 //var intersectParam = this._checkIntersection(controlPoints, 0.0, 1.0, point, radius);
525 var intersectParam = this._checkIntersectionWithSamples(this._anchorSampleIndex[i], this._anchorSampleIndex[nextIndex], point, radius);
526 console.log("intersectParam:"+intersectParam);
527 if (intersectParam){
528 retCode = retCode | this.SEL_PATH;
529 retParam = intersectParam-i; //make the retParam go from 0 to 1
530 this._selectedAnchorIndex = i;
531 break;
532 }
533 }
534 }//for every anchor i
535 }
536 this._selectMode = retCode;
537 return retParam;
538} //GLSubpath.pickPath function
539
540
447GLSubpath.prototype.getSelectedAnchorIndex = function () { return this._selectedAnchorIndex; } 541GLSubpath.prototype.getSelectedAnchorIndex = function () { return this._selectedAnchorIndex; }
448GLSubpath.prototype.getSelectedMode = function () { return this._selectMode; } 542GLSubpath.prototype.getSelectedMode = function () { return this._selectMode; }
449 543
@@ -1019,69 +1113,3 @@ GLSubpath.prototype.collidesWithPoint = function (x, y) {
1019 return true; 1113 return true;
1020} 1114}
1021 1115
1022
1023//pick the path point closest to the specified location, return null if some anchor point (or its handles) is within radius, else return the parameter distance
1024GLSubpath.prototype.pickPath = function (pickX, pickY, pickZ, radius) {
1025 var numAnchors = this._Anchors.length;
1026 var selAnchorIndex = -1;
1027 var retCode = this.SEL_NONE;
1028 var radSq = radius * radius;
1029 var minDistance = Infinity;
1030 for (var i = 0; i < numAnchors; i++) {
1031 var distSq = this._Anchors[i].getDistanceSq(pickX, pickY, pickZ);
1032 //check the anchor point
1033 if (distSq < minDistance && distSq < radSq) {
1034 selAnchorIndex = i;
1035 minDistance = distSq;
1036 retCode = retCode | this.SEL_ANCHOR;
1037 }
1038 }//for every anchor i
1039
1040 //check the prev and next of the selected anchor if the above did not register a hit
1041 if (this._selectedAnchorIndex>=0 && selAnchorIndex === -1) {
1042 var distSq = this._Anchors[this._selectedAnchorIndex].getPrevDistanceSq(pickX, pickY, pickZ);
1043 if (distSq < minDistance && distSq < radSq){
1044 selAnchorIndex = this._selectedAnchorIndex;
1045 minDistance = distSq;
1046 retCode = retCode | this.SEL_PREV;
1047 } else {
1048 //check the next for this anchor point
1049 distSq = this._Anchors[this._selectedAnchorIndex].getNextDistanceSq(pickX, pickY, pickZ);
1050 if (distSq<minDistance && distSq<radSq){
1051 selAnchorIndex = this._selectedAnchorIndex;
1052 minDistance = distSq;
1053 retCode = retCode | this.SEL_NEXT;
1054 }
1055 }
1056 }
1057 var retParam = null;
1058 if (retCode !== this.SEL_NONE) {
1059 retCode = retCode | this.SEL_PATH; //ensure that path is also selected if anything else is selected
1060 this._selectedAnchorIndex = selAnchorIndex;
1061 } else {
1062 this._selectedAnchorIndex = -1;
1063 var numSegments = this._isClosed ? numAnchors : numAnchors-1;
1064 for (var i = 0; i < numSegments; i++) {
1065 var nextIndex = (i+1)%numAnchors;
1066 //check if the point is close to the bezier segment between anchor i and anchor nextIndex
1067 var controlPoints = Vector.create([Vector.create([this._Anchors[i].getPosX(),this._Anchors[i].getPosY(),this._Anchors[i].getPosZ()]),
1068 Vector.create([this._Anchors[i].getNextX(),this._Anchors[i].getNextY(),this._Anchors[i].getNextZ()]),
1069 Vector.create([this._Anchors[nextIndex].getPrevX(),this._Anchors[nextIndex].getPrevY(),this._Anchors[nextIndex].getPrevZ()]),
1070 Vector.create([this._Anchors[nextIndex].getPosX(),this._Anchors[nextIndex].getPosY(),this._Anchors[nextIndex].getPosZ()])]);
1071 var point = Vector.create([pickX, pickY, pickZ]);
1072 if (this._isWithinBoundingBox(point, controlPoints, radius)) {
1073 //var intersectParam = this._checkIntersection(controlPoints, 0.0, 1.0, point, radius);
1074 var intersectParam = this._checkIntersectionWithSamples(this._anchorSampleIndex[i], this._anchorSampleIndex[nextIndex], point, radius);
1075 console.log("intersectParam:"+intersectParam);
1076 if (intersectParam){
1077 retCode = retCode | this.SEL_PATH;
1078 retParam = intersectParam-i; //make the retParam go from 0 to 1
1079 this._selectedAnchorIndex = i;
1080 break;
1081 }
1082 }
1083 }//for every anchor i
1084 }
1085 this._selectMode = retCode;
1086 return retParam;
1087} //GLSubpath.pickPath function \ No newline at end of file