private void ClearChasePanels() { if (_object_LinearVelocity != null) { _object_LinearVelocity.Dispose(); _object_LinearVelocity = null; } if (_object_LinearForce != null) { _object_LinearForce.Dispose(); _object_LinearForce = null; } if (_object_OrientationVelocity != null) { _object_OrientationVelocity.Dispose(); _object_OrientationVelocity = null; } if (_object_OrientationForce != null) { _object_OrientationForce.Dispose(); _object_OrientationForce = null; } }
public TrackedItem(IMapObject mapObject, MapObject_ChasePoint_Forces translate, MapObject_ChaseOrientation_Torques rotate, double?graduleTo100PercentDuration, double?delayBeforeGradule, bool didOriginalLimitRotation) { this.MapObject = mapObject; this.Translate = translate; this.Rotate = rotate; this.GraduleTo100PercentDuration = graduleTo100PercentDuration; this.DelayBeforeGradule = delayBeforeGradule; this.ElapsedTime = 0d; this.DidOriginalLimitRotation = didOriginalLimitRotation; }
private void UpdateChasePanel() { try { lblError.Text = ""; ClearChasePanels(); ChaseType chaseType; if (Enum.TryParse(cboChaseType.SelectedValue.ToString().Replace(" ", "_"), out chaseType)) { switch (chaseType) { case ChaseType.Linear_Velocity: if (_panel_LinearVelocity != null) { _object_LinearVelocity = _panel_LinearVelocity.GetChaseObject(_bodyBall); } break; case ChaseType.Linear_Force: if (_panel_LinearForce != null) { _object_LinearForce = _panel_LinearForce.GetChaseObject_Linear(_bodyBall); } break; case ChaseType.Orientation_Velocity: if (_panel_OrientationVelocity != null) { _object_OrientationVelocity = _panel_OrientationVelocity.GetChaseObject(_bodyBall); } break; case ChaseType.Orientation_Torque: if (_panel_OrientationForce != null) { _object_OrientationForce = _panel_OrientationForce.GetChaseObject_Orientation(_bodyBall); } break; default: throw new ApplicationException("Unknown ChaseType: " + chaseType.ToString()); } } } catch (Exception ex) { lblError.Text = ex.Message; } }
public MapObject_ChasePoint_Forces GetChaseObject_Linear(IMapObject item) { if (!_isLinear) { throw new InvalidOperationException("This method can only be called when the control represents linear"); } MapObject_ChasePoint_Forces retVal = new MapObject_ChasePoint_Forces(item, false); //TODO: May want to expose these. I think they're unnecessary, and the result of overdesign //retVal.MaxAcceleration = //retVal.MaxForce = List <ChasePoint_Force> forces = new List <ChasePoint_Force>(); foreach (UIElement entry in pnlForces.Children) { ChasePoint_Force chaseObject = null; if (entry is ForceEntry) { chaseObject = ((ForceEntry)entry).GetChaseObject_Linear(); } else { throw new ApplicationException("Unknown type of entry: " + entry.ToString()); } //NOTE: Doing a null check, because if they uncheck enabled, it will come back null if (chaseObject != null) { forces.Add(chaseObject); } } if (forces.Count > 0) { retVal.Forces = forces.ToArray(); return(retVal); } else { // Don't bother returning something that will fail on update return(null); } }
public void Add(IMapObject item, bool shouldLockOrientation, Vector3D?orientationRotateAxis = null, Vector3D?orientationModelUp = null) { if (_items.Any(o => o.MapObject.Equals(item))) { // It's already added return; } #region forces List <ChasePoint_Force> forces = new List <ChasePoint_Force>(); // Attraction Force GradientEntry[] gradient = new[] { new GradientEntry(0d, .04d), // distance, % new GradientEntry(1d, 1d), }; forces.Add(new ChasePoint_Force(ChaseDirectionType.Attract_Direction, 500d, gradient: gradient)); // These act like a shock absorber forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_AlongIfVelocityAway, 50d)); gradient = new[] { new GradientEntry(0d, 1d), new GradientEntry(.75d, .2d), new GradientEntry(2d, 0d), }; forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_AlongIfVelocityToward, 100d, gradient: gradient)); MapObject_ChasePoint_Forces chaseForces = new MapObject_ChasePoint_Forces(item, false) { Forces = forces.ToArray() }; #endregion #region torques MapObject_ChaseOrientation_Torques chaseTorques = null; List <ChaseOrientation_Torque> torques = new List <ChaseOrientation_Torque>(); double mult = 6; // Attraction gradient = new[] { new GradientEntry(0d, 0d), // distance, % new GradientEntry(10d, 1d), }; torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Attract_Direction, .4 * mult, gradient: gradient)); // Drag gradient = new[] // this gradient is needed, because there needs to be no drag along the desired axis (otherwise, this drag will fight with the user's desire to rotate the ship) { new GradientEntry(0d, 0d), // distance, % new GradientEntry(5d, 1d), }; torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_Orth, .0739 * mult, gradient: gradient)); torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_AlongIfVelocityAway, .0408 * mult)); chaseTorques = new MapObject_ChaseOrientation_Torques(item) { Torques = torques.ToArray() }; #endregion _items.Add(new TrackedItem(item, chaseForces, chaseTorques)); }
public TrackedItem(IMapObject mapObject, MapObject_ChasePoint_Forces translate, MapObject_ChaseOrientation_Torques rotate) { MapObject = mapObject; Translate = translate; Rotate = rotate; }
public void Add(IMapObject item, bool shouldLimitRotation, double?graduleTo100PercentDuration = null, double?delayBeforeGradule = null) { if (_items.Any(o => o.MapObject.Equals(item))) { // It's already added return; } GradientEntry[] gradient; #region forces MapObject_ChasePoint_Forces chaseForces = null; if (_shouldApplyForces) { List <ChasePoint_Force> forces = new List <ChasePoint_Force>(); // Attraction Force gradient = new[] { new GradientEntry(0d, 0d), // distance, % new GradientEntry(.7d, .28d), new GradientEntry(1d, 1d), }; forces.Add(new ChasePoint_Force(ChaseDirectionType.Attract_Direction, 500, gradient: gradient)); // This acts like a shock absorber gradient = new[] { new GradientEntry(0d, .25d), new GradientEntry(.75d, 1d), //new GradientEntry(3d, 0d), }; forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_Along, 10)); chaseForces = new MapObject_ChasePoint_Forces(item, false) { Forces = forces.ToArray() }; } #endregion #region torques MapObject_ChaseOrientation_Torques chaseTorques = null; if (_shouldApplyTorques && shouldLimitRotation) { List <ChaseOrientation_Torque> torques = new List <ChaseOrientation_Torque>(); double mult = 300; //600; // Attraction gradient = new[] { new GradientEntry(0d, 0d), // distance, % new GradientEntry(10d, 1d), }; torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Attract_Direction, .4 * mult, gradient: gradient)); // Drag gradient = new[] // this gradient is needed, because there needs to be no drag along the desired axis (otherwise, this drag will fight with the user's desire to rotate the ship) { new GradientEntry(0d, 0d), // distance, % new GradientEntry(5d, 1d), }; torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_Orth, .0739 * mult, gradient: gradient)); torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_AlongIfVelocityAway, .0408 * mult)); chaseTorques = new MapObject_ChaseOrientation_Torques(item) { Torques = torques.ToArray() }; } #endregion _items.Add(new TrackedItem(item, chaseForces, chaseTorques, graduleTo100PercentDuration, delayBeforeGradule, shouldLimitRotation)); }