Michael Smith 9f11c39986 + Added SingleStatementObject (abstract) between OSCADObject and repetetive single-objectt transforms.
+ Shifted basic parent/child/object reference assignments to SingleStatementObject
2016-02-24 23:30:21 -08:00

60 lines
1.9 KiB
C#

using OSCADSharp.Scripting;
using OSCADSharp.Spatial;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
namespace OSCADSharp.Transforms
{
/// <summary>
/// An object with rotation applied
/// </summary>
internal class RotatedObject : SingleStatementObject
{
/// <summary>
/// The angle to rotate, in terms of X/Y/Z euler angles
/// </summary>
internal Vector3 Angle { get; set; } = new Vector3();
/// <summary>
/// Creates an object with rotation applied
/// </summary>
/// <param name="obj">The object being rotated</param>
/// <param name="angle">The angle to rotate</param>
internal RotatedObject(OSCADObject obj, Vector3 angle) : base(obj)
{
this.Angle = angle;
}
public override string ToString()
{
string rotateCommand = String.Format("rotate([{0}, {1}, {2}])",
this.Angle.X.ToString(), this.Angle.Y.ToString(), this.Angle.Z.ToString());
var formatter = new SingleBlockFormatter(rotateCommand, this.obj.ToString());
return formatter.ToString();
}
public override OSCADObject Clone()
{
return new RotatedObject(this.obj.Clone(), this.Angle)
{
Name = this.Name
};
}
public override Vector3 Position()
{
return Matrix.GetRotatedPoint(this.obj.Position(), this.Angle.X, this.Angle.Y, this.Angle.Z);
}
public override Bounds Bounds()
{
var oldBounds = obj.Bounds();
return new Bounds(Matrix.GetRotatedPoint(oldBounds.BottomLeft, this.Angle.X, this.Angle.Y, this.Angle.Z),
Matrix.GetRotatedPoint(oldBounds.TopRight, this.Angle.X, this.Angle.Y, this.Angle.Z));
}
}
}