From 890d84a1078fae1f21a56e8be3ed181650afe9e1 Mon Sep 17 00:00:00 2001 From: Pushkar Joshi Date: Wed, 18 Apr 2012 11:29:39 -0700 Subject: compute the translation to new center of bounding of the subpath --- this preserves the correct transformation applied to the subpath. This is a good snapshot of the polyline drawing in 3D (with some minor bugs). --- js/tools/PenTool.js | 30 ++++++++++++++++++++++++++++-- 1 file changed, 28 insertions(+), 2 deletions(-) (limited to 'js/tools/PenTool.js') diff --git a/js/tools/PenTool.js b/js/tools/PenTool.js index 0e3bd15c..ec63771a 100755 --- a/js/tools/PenTool.js +++ b/js/tools/PenTool.js @@ -71,6 +71,10 @@ exports.PenTool = Montage.create(ShapeTool, { // todo this might be unnecessary as we can get this from element mediator (but that may be slow) _selectedSubpathPlaneMat: { value: null, writable: true }, + //bbox of the selected subpath in local coordinates + // (used for id-ing when the local center has shifted, i.e. the bbox of the subpath has grown) + _selectedSubpathLocalCenter: {value: null, writable: true}, + //the center of the subpath center in stageworld space _selectedSubpathCanvasCenter: {value: null, writable: true}, @@ -208,6 +212,7 @@ exports.PenTool = Montage.create(ShapeTool, { this._selectedSubpath = new SubPath(); this._selectedSubpathCanvas = null; this._selectedSubpathPlaneMat = null; + this._selectedSubpathLocalCenter = null; this._isNewPath = true; if (this._entryEditMode === this.ENTRY_SELECT_PATH){ @@ -758,6 +763,7 @@ exports.PenTool = Montage.create(ShapeTool, { for (d=0;d<3;d++){ if (bboxMax[d]-bboxMin[d]>this._MAX_CANVAS_DIMENSION){ canvasTooLarge = true; + break; } } if (canvasTooLarge){ @@ -773,11 +779,26 @@ exports.PenTool = Montage.create(ShapeTool, { //convert the midpoint of this bbox to stage world space var bboxMid = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); + + //sandwich the planeMat between with the translation to the previous center of the canvas in local space and its inverse + var centerDisp = VecUtils.vecSubtract(3, bboxMid, this._selectedSubpathLocalCenter); + var tMat = Matrix.Translation([centerDisp[0], centerDisp[1],centerDisp[2]]); + var tInvMat = Matrix.Translation([-centerDisp[0], -centerDisp[1], -centerDisp[2]]); + var newMat = Matrix.I(4); + glmat4.multiply( tInvMat, this._selectedSubpathPlaneMat, newMat); + glmat4.multiply( newMat, tMat, newMat); + this._selectedSubpathPlaneMat = newMat; + ViewUtils.setMatrixForElement(this._selectedSubpathCanvas, newMat, true); + + //this._selectedSubpathCanvasCenter = ViewUtils.localToStageWorld(bboxMid, this._selectedSubpathCanvas); var localToStageWorldMat = ViewUtils.getLocalToStageWorldMatrix(this._selectedSubpathCanvas, false, false); this._selectedSubpathCanvasCenter = MathUtils.transformAndDivideHomogeneousPoint(bboxMid, localToStageWorldMat); this._selectedSubpathCanvasCenter[0]+= xAdjustment; this._selectedSubpathCanvasCenter[1]+= yAdjustment; + + + } else { //compute the bbox in stage-world space (the points are already in stage world space) this._selectedSubpath.createSamples(true); @@ -786,7 +807,7 @@ exports.PenTool = Montage.create(ShapeTool, { this._selectedSubpathCanvasCenter = VecUtils.vecInterpolate(3, bboxMin, bboxMax, 0.5); //convert the path points into local coordinates by multiplying by the inverse of the plane mat - for (i=0;i