Change order of operations for applay at positon

This commit is contained in:
LarsBrubaker 2018-06-30 07:00:58 -07:00
parent 51f0e3d5c6
commit e28c1c8e43
5 changed files with 15 additions and 17 deletions

View file

@ -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)

View file

@ -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;

View file

@ -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)
{

View file

@ -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,

@ -1 +1 @@
Subproject commit 7373165635f93ce5e178b8de201d8133f52765cc
Subproject commit 931858e4896e4fb9780cb3f3c872a3543781ea9d