Migrate ApplyAtCenter to IObject3D extension method

- Rename to ApplyAtBoundCenter
- Change to return void and apply to instance
This commit is contained in:
John Lewin 2018-02-01 12:24:56 -08:00
parent 68348dfc78
commit 3331748239
6 changed files with 34 additions and 26 deletions

View file

@ -287,22 +287,5 @@ namespace MatterHackers.MatterControl
return meshGroup.GetAxisAlignedBoundingBox(transform);
}
public static Matrix4X4 ApplyAtCenter(IObject3D object3DToApplayTo, Matrix4X4 transformToApply)
{
return ApplyAtCenter(object3DToApplayTo.GetAxisAlignedBoundingBox(Matrix4X4.Identity), object3DToApplayTo.Matrix, transformToApply);
}
public static Matrix4X4 ApplyAtCenter(AxisAlignedBoundingBox boundsToApplyTo, Matrix4X4 currentTransform, Matrix4X4 transformToApply)
{
return ApplyAtPosition(currentTransform, transformToApply, boundsToApplyTo.Center);
}
public static Matrix4X4 ApplyAtPosition(Matrix4X4 currentTransform, Matrix4X4 transformToApply, Vector3 postionToApplyAt)
{
currentTransform *= Matrix4X4.CreateTranslation(-postionToApplyAt);
currentTransform *= transformToApply;
currentTransform *= Matrix4X4.CreateTranslation(postionToApplyAt);
return currentTransform;
}
}
}

View file

@ -36,6 +36,7 @@ using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.DataConverters3D.UndoCommands;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.PolygonMesh;
using MatterHackers.VectorMath;
@ -255,10 +256,10 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
return;
}
Face faceToLayFlat = null;
PolygonMesh.Face faceToLayFlat = null;
double lowestAngleOfAnyFace = double.MaxValue;
// Check all the faces that are connected to the lowest point to find out which one to lay flat.
foreach (Face face in lowestVertex.ConnectedFaces())
foreach (var face in lowestVertex.ConnectedFaces())
{
double biggestAngleToFaceVertex = double.MinValue;
foreach (IVertex faceVertex in face.Vertices())
@ -303,7 +304,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
Matrix4X4 partLevelMatrix = Matrix4X4.CreateRotation(rotation);
// rotate it
objectToLayFlatGroup.Matrix = PlatingHelper.ApplyAtCenter(objectToLayFlatGroup, partLevelMatrix);
objectToLayFlatGroup.ApplyAtBoundsCenter(partLevelMatrix);
scene.Invalidate();
}

View file

@ -31,6 +31,7 @@ using System.Collections.Generic;
using MatterHackers.Agg;
using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.MeshVisualizer;
using MatterHackers.VectorMath;
using static MatterHackers.MatterControl.PrinterCommunication.PrinterConnection;
@ -102,15 +103,15 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
switch (axis)
{
case Axis.Z:
item.Matrix = PlatingHelper.ApplyAtCenter(item, Matrix4X4.CreateScale(1, 1, -1));
item.ApplyAtBoundsCenter(Matrix4X4.CreateScale(1, 1, -1));
break;
case Axis.X:
item.Matrix = PlatingHelper.ApplyAtCenter(item, Matrix4X4.CreateScale(-1, 1, 1));
item.ApplyAtBoundsCenter(Matrix4X4.CreateScale(-1, 1, 1));
break;
case Axis.Y:
item.Matrix = PlatingHelper.ApplyAtCenter(item, Matrix4X4.CreateScale(1, -1, 1));
item.ApplyAtBoundsCenter(Matrix4X4.CreateScale(1, -1, 1));
break;
}

View file

@ -30,6 +30,7 @@ using MatterHackers.Agg.UI;
using MatterHackers.DataConverters3D;
using MatterHackers.Localizations;
using MatterHackers.MatterControl.CustomWidgets;
using MatterHackers.MatterControl.DesignTools.Operations;
using MatterHackers.VectorMath;
namespace MatterHackers.MatterControl.PartPreviewWindow
@ -238,7 +239,7 @@ namespace MatterHackers.MatterControl.PartPreviewWindow
newScale[axis] = scaleIn;
Matrix4X4 totalScale = Matrix4X4.CreateScale(newScale);
selectedItem.Matrix = PlatingHelper.ApplyAtCenter(selectedItem, totalScale);
selectedItem.ApplyAtBoundsCenter(totalScale);
// keep the bottom where it was
AxisAlignedBoundingBox scaledBounds = selectedItem.GetAxisAlignedBoundingBox(Matrix4X4.Identity);