From e28c1c8e43b473249b10d32ff672e612ba7f80ff Mon Sep 17 00:00:00 2001 From: LarsBrubaker Date: Sat, 30 Jun 2018 07:00:58 -0700 Subject: [PATCH] Change order of operations for applay at positon --- DesignTools/Operations/FitToBoundsObject3D.cs | 2 +- DesignTools/Operations/Object3DExtensions.cs | 9 +++++++-- DesignTools/Operations/RotateObject3D.cs | 15 ++++----------- PartPreviewWindow/View3D/MeshViewerWidget.cs | 4 ++-- Submodules/agg-sharp | 2 +- 5 files changed, 15 insertions(+), 17 deletions(-) diff --git a/DesignTools/Operations/FitToBoundsObject3D.cs b/DesignTools/Operations/FitToBoundsObject3D.cs index 5979f9051..b187eaf20 100644 --- a/DesignTools/Operations/FitToBoundsObject3D.cs +++ b/DesignTools/Operations/FitToBoundsObject3D.cs @@ -234,7 +234,7 @@ namespace MatterHackers.MatterControl.DesignTools.Operations break; } - ScaleItem.Matrix = Object3DExtensions.ApplyAtPosition(ScaleItem.Matrix, Matrix4X4.CreateScale(scale), aabb.Center); + ScaleItem.Matrix = Object3DExtensions.ApplyAtPosition(ScaleItem.Matrix, aabb.Center, Matrix4X4.CreateScale(scale)); } public void DrawEditor(object sender, DrawEventArgs e) diff --git a/DesignTools/Operations/Object3DExtensions.cs b/DesignTools/Operations/Object3DExtensions.cs index da04cb201..4a2aa4428 100644 --- a/DesignTools/Operations/Object3DExtensions.cs +++ b/DesignTools/Operations/Object3DExtensions.cs @@ -305,10 +305,15 @@ namespace MatterHackers.MatterControl.DesignTools.Operations public static Matrix4X4 ApplyAtCenter(this Matrix4X4 currentTransform, AxisAlignedBoundingBox boundsToApplyTo, Matrix4X4 transformToApply) { - return ApplyAtPosition(currentTransform, transformToApply, boundsToApplyTo.Center); + return ApplyAtPosition(currentTransform, boundsToApplyTo.Center, transformToApply); } - public static Matrix4X4 ApplyAtPosition(this Matrix4X4 currentTransform, Matrix4X4 transformToApply, Vector3 positionToApplyAt) + public static Matrix4X4 ApplyAtPosition(this IObject3D item, Vector3 positionToApplyAt, Matrix4X4 transformToApply) + { + return item.Matrix.ApplyAtPosition(positionToApplyAt, transformToApply); + } + + public static Matrix4X4 ApplyAtPosition(this Matrix4X4 currentTransform, Vector3 positionToApplyAt, Matrix4X4 transformToApply) { currentTransform *= Matrix4X4.CreateTranslation(-positionToApplyAt); currentTransform *= transformToApply; diff --git a/DesignTools/Operations/RotateObject3D.cs b/DesignTools/Operations/RotateObject3D.cs index e8ec285d0..6770ed390 100644 --- a/DesignTools/Operations/RotateObject3D.cs +++ b/DesignTools/Operations/RotateObject3D.cs @@ -38,9 +38,6 @@ namespace MatterHackers.MatterControl.DesignTools.Operations { public class RotateObject3D : Object3D { - // we do want this to persist - Vector3 lastRotationDegrees = Vector3.Zero; - [DisplayName("X")] [Description("Rotate about the X axis")] public double RotationXDegrees { get; set; } @@ -80,16 +77,12 @@ namespace MatterHackers.MatterControl.DesignTools.Operations var startingAabb = this.GetAxisAlignedBoundingBox(); // remove whatever rotation has been applied (they go in reverse order) - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(-lastRotationDegrees.Z))); - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationY(MathHelper.DegreesToRadians(-lastRotationDegrees.Y))); - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationX(MathHelper.DegreesToRadians(-lastRotationDegrees.X))); + Matrix = Matrix4X4.Identity; // add the current rotation - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationX(MathHelper.DegreesToRadians(RotationXDegrees))); - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationY(MathHelper.DegreesToRadians(RotationYDegrees))); - Matrix = this.ApplyAtBoundsCenter(Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(RotationZDegrees))); - - lastRotationDegrees = new Vector3(RotationXDegrees, RotationYDegrees, RotationZDegrees); + Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationX(MathHelper.DegreesToRadians(RotationXDegrees))); + Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationY(MathHelper.DegreesToRadians(RotationYDegrees))); + Matrix = this.ApplyAtPosition(startingAabb.Center, Matrix4X4.CreateRotationZ(MathHelper.DegreesToRadians(RotationZDegrees))); if (startingAabb.ZSize > 0) { diff --git a/PartPreviewWindow/View3D/MeshViewerWidget.cs b/PartPreviewWindow/View3D/MeshViewerWidget.cs index d46db6404..a6d33c189 100644 --- a/PartPreviewWindow/View3D/MeshViewerWidget.cs +++ b/PartPreviewWindow/View3D/MeshViewerWidget.cs @@ -644,10 +644,10 @@ namespace MatterHackers.MeshVisualizer var wantMm = pixelsWant * distBetweenPixelsWorldSpace; - var scaleMatrix = worldMatrix.ApplyAtPosition(Matrix4X4.CreateScale( + var scaleMatrix = worldMatrix.ApplyAtPosition(worldCenter, Matrix4X4.CreateScale( wantMm.X / worldBounds.XSize, wantMm.Y / worldBounds.YSize, - wantMm.Z / worldBounds.ZSize), worldCenter); + wantMm.Z / worldBounds.ZSize)); GLHelper.Render(item.Mesh, selectionColor, diff --git a/Submodules/agg-sharp b/Submodules/agg-sharp index 737316563..931858e48 160000 --- a/Submodules/agg-sharp +++ b/Submodules/agg-sharp @@ -1 +1 @@ -Subproject commit 7373165635f93ce5e178b8de201d8133f52765cc +Subproject commit 931858e4896e4fb9780cb3f3c872a3543781ea9d