using System; using System.Collections.Generic; using Chernobyl.DesignPatterns.Extension; using Chernobyl.Event; using Chernobyl.Mathematics.Vectors; using Chernobyl.Measures; namespace Chernobyl.Mathematics.Movement { /// /// A class whose implementation is defined by another /// instance. This class allows for easier creation of /// types that need to use other /// implementations or for classes that need to dynamically alter their /// implementation at runtime. This is an implementation of the decorator /// pattern (http://en.wikipedia.org/wiki/Decorator_pattern). /// public abstract class TransformDecorator : ITransform { /// /// Translates the transform in the X axis by a specified amount. /// /// The amount to translate in the X. public void TranslateX(float x) { DecoratedTransform.TranslateX(x); } /// /// Translates the transform in the Y axis by a specified amount. /// /// The amount to translate in the Y. public void TranslateY(float y) { DecoratedTransform.TranslateY(y); } /// /// Translates the transform in the Z axis by a specified amount. /// /// The amount to translate in the Z. public void TranslateZ(float z) { DecoratedTransform.TranslateZ(z); } /// /// Translates the transform in the X and Y axis by a specified amount. /// This method is useful for transforms that exist in 2D world. /// /// The amount to translate in the X. /// The amount to translate in the Y. public void Translate(float x, float y) { DecoratedTransform.Translate(x, y); } /// /// Translates the transform in the X and Y axis by a specified amount. /// This method is useful for transforms that exist in 2D world. /// /// The amount to translate in the X and Y axis. public void Translate(Vector2 amount) { DecoratedTransform.Translate(amount); } /// /// Translates the transform in the X axis, Y axis /// and Z axis by specified amounts. /// /// The amount to translate in the X. /// The amount to translate in the Y. /// The amount to translate in the Z. public void Translate(float x, float y, float z) { DecoratedTransform.Translate(x, y, z); } /// /// Translates the transform in the X axis, Y axis and Z axis by /// specified amounts. /// /// The amount to translate the transform in each /// of the three axis where Vector3.X is the X axis translation amount, /// Vector3.Y is the Y axis translation amount, and Vector3.Z is the /// Z axis translation amount. public void Translate(Vector3 amount) { DecoratedTransform.Translate(amount); } /// /// Rotates this transform around a vector by a specified amount. /// /// The vector to rotate around. /// The amount to rotate around the vector. public void Rotate(Vector3 vectorToRotateAround, Radian radian) { DecoratedTransform.Rotate(vectorToRotateAround, radian); } /// /// Rotates this transform about the X axis a specified amount. /// /// The amount to rotate by. public void Pitch(Radian amount) { DecoratedTransform.Pitch(amount); } /// /// Rotates this transform about the Y axis a specified amount. /// /// The amount to rotate by. public void Yaw(Radian amount) { DecoratedTransform.Yaw(amount); } /// /// Rotates this transform about the Z axis a specified amount. /// /// The amount to rotate by. public void Roll(Radian amount) { DecoratedTransform.Roll(amount); } /// /// Scales the transform along the X axis. /// /// The amount to scale in the X axis. public void ScaleX(float amount) { DecoratedTransform.ScaleX(amount); } /// /// Scales the transform in the Y axis. /// /// The amount to scale in the Y axis. public void ScaleY(float amount) { DecoratedTransform.ScaleY(amount); } /// /// Scales the transform in the Z axis. /// /// The amount to scale in the Z axis. public void ScaleZ(float amount) { DecoratedTransform.ScaleZ(amount); } /// /// Scales the transform uniformly over the X, Y, and Z axis. /// /// The amount to scale in all axis. public void Scale(float amount) { DecoratedTransform.Scale(amount); } /// /// Scales the transform in the X and Y axis. This is useful if the /// transform exists in a 2D world. /// /// The amount to scale in the X axis. /// The amount to scale in the Y axis. public void Scale(float x, float y) { DecoratedTransform.Scale(x, y); } /// /// Scales the transform in the X and Y axis. This is useful if the /// transform exists in a 2D world. /// /// The amount to scale in the X and Y axis. public void Scale(Vector2 amount) { DecoratedTransform.Scale(amount); } /// /// Scales the transform uniformly over the X, Y, and Z axis. /// /// The amount to scale in the X axis. /// The amount to scale in the Y axis. /// The amount to scale in the Z axis. public void Scale(float x, float y, float z) { DecoratedTransform.Scale(x, y, z); } /// /// Scales the transform uniformly over the X, Y, and Z axis. /// /// The amount to scale in each axis where /// Vector3.X is the amount to scale in the X axis, Vector3.Y is the /// amount to scale in the Y axis, Vector3.Z is the amount to scale in /// the Z axis. public void Scale(Vector3 amount) { DecoratedTransform.Scale(amount); } /// /// Sets the internal local transformation to the matrix passed in. /// /// The matrix to set the internal local /// transformation to. public void SetTransformation(ref Matrix4 matrix) { DecoratedTransform.SetTransformation(ref matrix); } /// public void Dispose() => Transform.SeparateParentChild(TransformParent, this); /// /// An event that is raised when the transform has been "dirtied" or /// when the position, orientation, and/or scale of the transform has /// been changed either due to an ancestor being changed or due to the /// transform itself being changed. This event will only be raised once /// when the transform is changed, subsequent changes to the transform /// or it's ancestors will not cause the event to be raised. If the /// transform is cleaned (typically done when the /// is accessed) and then dirtied again, the event will be raised. This /// event will be fired before children transforms are notified of the /// change to the transform or it's ancestors (usually through the /// child's flag). /// public event EventHandler TransformDirtied { add { DecoratedTransform.TransformDirtied += value; } remove { DecoratedTransform.TransformDirtied -= value; } } /// /// The parent to this transform. This property will /// be null if this is the root of the hierarchy. /// public virtual ITransform TransformParent { get { return DecoratedTransform.TransformParent; } set { DecoratedTransform.TransformParent = value; } } /// /// The children of this transform who's /// position, orientation, scale, etc., are /// effected or offset by this transform. /// public virtual IList TransformChildren { get { return DecoratedTransform.TransformChildren; } } /// /// This transforms position in the world. This property returns the /// World position (i.e. the position from ) but /// sets the Local position (i.e. the position from . /// public Vector3 Position { get { return DecoratedTransform.Position; } set { DecoratedTransform.Position = value; } } /// /// The up vector of this transform in the world, which is also the +Y /// vector or . /// public Vector3 Up { get { return DecoratedTransform.Up; } } /// /// The vector that points straight ahead (in the world) for this /// transform, which is also the -Z vector or negative /// . /// public Vector3 Forward { get { return DecoratedTransform.Forward; } } /// /// The vector that points to this transform's right in the world, which /// is also the +X vector or . /// public Vector3 Right { get { return DecoratedTransform.Right; } } /// /// The amount of scale in the world X axis of the transform. /// public float XScale { get { return DecoratedTransform.XScale; } } /// /// The amount of scale in the world Y axis of the transform. /// public float YScale { get { return DecoratedTransform.YScale; } } /// /// The amount of scale in the world Z axis of the transform. /// public float ZScale { get { return DecoratedTransform.ZScale; } } /// /// Gets/sets this transforms local matrix. The local matrix /// is the matrix that has been "untouched" by the parents, /// grandparents, etc., of this transform. In other words, /// it is not relative to any other transform. /// public virtual Matrix4 LocalMatrix { get { return DecoratedTransform.LocalMatrix; } } /// /// Gets/sets this transform's world matrix. The world matrix /// is the position and orientation relative to the parent of /// this transform. /// public virtual Matrix4 WorldMatrix { get { return DecoratedTransform.WorldMatrix; } } /// /// True if an update to this transform's world matrix is /// needed, false if otherwise. A transform will need to be /// updated if it's local matrix or an ancestors local matrix /// is updated. /// public bool IsUpdateNeeded { get { return DecoratedTransform.IsUpdateNeeded; } set { DecoratedTransform.IsUpdateNeeded = value; } } /// /// The instance being extended. Setting on instance on this property /// will cause that instance to be extended. If a previous instance was /// already being extended, then this extension will detach itself from /// that instance (stop extending it) and attach itself to the new /// instance (begin extending it). If null is set on this property then /// the previous instance will being extended will no longer be extended /// (if applicable). Note to implementors: it is highly recommended you /// store the extended instance in either a /// or a /// to allow the extended instance to /// be properly garbage collected. /// public virtual ITransform Extended { get { return DecoratedTransform.Extended; } set { DecoratedTransform.Extended = value; } } /// /// An event that is raised right after the instance being extended has /// changed (or whenever the property has been /// changed). /// public event EventHandler> ExtendedChanged { add { DecoratedTransform.ExtendedChanged += value; } remove { DecoratedTransform.ExtendedChanged -= value; } } /// /// Overrides . /// public string Name { get { return DecoratedTransform.Name; } set { DecoratedTransform.Name = value; } } /// /// The list of or /// instances that have /// attached themselves to this instance. /// /// The extensions of this instance. public IList Extensions { get { return DecoratedTransform.Extensions; } } /// /// The that provides this /// s capabilities. /// protected abstract ITransform DecoratedTransform { get; } } }