using System; using System.Collections.Generic; using Chernobyl.Collections.Generic.Event; using Chernobyl.Event; using Chernobyl.Mathematics; using Chernobyl.Mathematics.Mechanics; using Chernobyl.Mathematics.Movement; using Chernobyl.Mathematics.Vectors; using Chernobyl.Values; namespace Chernobyl.Input.Controls.Axis { /// /// A helper class that allows for easy creation of /// classes. /// public class Axis3DControl : Axis2DControl, IAxis3DControl { /// /// Initializes a new instance of the class. /// /// The services class that contains the /// dependencies that are to be injected into this object. public Axis3DControl(IEventCollection services) : this(services, new List()) { } /// /// Initializes a new instance of the class. /// /// The services class that contains the /// dependencies that are to be injected into this object. /// The list to use to hold the children /// controls. public Axis3DControl(IEventCollection services, ICollection controlChildren) : base(services, controlChildren) { } /// /// Updates this IUpdateable object and it's children /// if the updateable feels it's necessary. /// /// The amount of time that has /// passed since this update was last called. public override void Update(TimeSpan deltaTime) { if (X.CurrentValue != X.PreviousValue || Y.CurrentValue != Y.PreviousValue || Z.CurrentValue != Z.PreviousValue) { IsUpdateNeeded = true; if (OnMove != null) OnMove(this, new EventArgs(this)); } base.Update(deltaTime); } /// /// This method is invoked during the update of the /// right before the /// is actually updated. This /// method keeps the position of this instance up to date. /// /// The value of the . /// It is stored in a so that the calculation can be /// avoided if necessary. Don't call unless /// required. protected override void PreUpdate(Values.LazyValue world) { base.PreUpdate(world); Matrix4 local = LocalMatrix; local.Row3 = new Vector4(X.CurrentValue, Y.CurrentValue, Z.CurrentValue, local.Row3.W); SetTransformation(ref local); } /// /// The Y axis of the 2 dimensions of this control. /// public virtual IAxisControl Z { get; protected set; } /// /// The (X, Y, Z) position of the mechanism. /// public Vector3 Xyz { get { return new Vector3(X.CurrentValue, Y.CurrentValue, Z.CurrentValue); } } /// /// Invoked when this control moves in either the X, Y, Z or all three /// directions. /// public new event EventHandler> OnMove; /// /// The Z axis of the 3 dimensions of this mechanism. /// IAxis IAxis3D.Z { get { return Z; } } } }