예제 #1
0
            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;
            }
        }
        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 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;
            }
        }
예제 #5
0
 public TrackedItem(IMapObject mapObject, MapObject_ChasePoint_Forces forces, bool shouldLimitRotation)
 {
     this.MapObject = mapObject;
     this.Forces = forces;
     this.ShouldLimitRotation = shouldLimitRotation;
 }
예제 #6
0
        public void Add(IMapObject item, bool shouldLimitRotation)
        {
            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
            var gradient = new[]
                {
                    Tuple.Create(0d, .04d),     // distance, %
                    Tuple.Create(1d, 1d),
                };
            forces.Add(new ChasePoint_Force(ChaseDirectionType.Attract_Direction, 500, gradient: gradient));

            // These act like a shock absorber
            forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_AlongIfVelocityAway, 50));

            gradient = new[]
                {
                    Tuple.Create(0d, 1d),
                    Tuple.Create(.75d, .2d),
                    Tuple.Create(2d, 0d),
                };
            forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_AlongIfVelocityToward, 100d, gradient: gradient));


            MapObject_ChasePoint_Forces chaseForces = new MapObject_ChasePoint_Forces(item, false);
            if (item.PhysicsBody != null)
            {
                //TODO: This could change over time.  Need to adjust it every once in a while
                chaseForces.Offset = item.PhysicsBody.CenterOfMass.ToVector();
            }

            chaseForces.Forces = forces.ToArray();

            #region ORIG

            //// Attraction Force
            //chaseForces.Forces.Add(new ChasePoint_ForcesGradient<ChasePoint_ForcesAttract>(new[]
            //        {
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesAttract>(new ChasePoint_Distance(true, 0d), new ChasePoint_ForcesAttract() { BaseAcceleration = 20d, ApplyWhenUnderSpeed = 100d }),
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesAttract>(new ChasePoint_Distance(false, 1d), new ChasePoint_ForcesAttract() { BaseAcceleration = 500d, ApplyWhenUnderSpeed = 100d }),
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesAttract>(new ChasePoint_Distance(true, double.MaxValue), new ChasePoint_ForcesAttract() { BaseAcceleration = 500d, ApplyWhenUnderSpeed = 100d })
            //        }));

            //// These act like a shock absorber
            //chaseForces.Forces.Add(new ChasePoint_ForcesDrag(ChasePoint_DirectionType.Velocity_AlongIfVelocityAway) { BaseAcceleration = 50d });

            //chaseForces.Forces.Add(new ChasePoint_ForcesGradient<ChasePoint_ForcesDrag>(new[]
            //        {
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesDrag>(new ChasePoint_Distance(true, 0d), new ChasePoint_ForcesDrag(ChasePoint_DirectionType.Velocity_AlongIfVelocityToward) { BaseAcceleration = 100d }),
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesDrag>(new ChasePoint_Distance(false, .75d), new ChasePoint_ForcesDrag(ChasePoint_DirectionType.Velocity_AlongIfVelocityToward) { BaseAcceleration = 20d }),
            //            new ChasePoint_ForcesGradientStop<ChasePoint_ForcesDrag>(new ChasePoint_Distance(false, 2d), new ChasePoint_ForcesDrag(ChasePoint_DirectionType.Velocity_AlongIfVelocityToward) { BaseAcceleration = 0d }),
            //        }));

            #endregion

            #endregion

            //if (shouldLimitRotation)
            //{
            //    item.PhysicsBody.ApplyForceAndTorque += new EventHandler<BodyApplyForceAndTorqueArgs>(PhysicsBody_ApplyForceAndTorque);
            //}

            _items.Add(new TrackedItem(item, chaseForces, shouldLimitRotation));
            //_items.Add(new TrackedItem(item, null, shouldLimitRotation));
        }
예제 #7
0
        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;
            }

            Tuple<double, double>[] gradient;

            #region Forces

            MapObject_ChasePoint_Forces chaseForces = null;

            if (_shouldApplyForces)
            {
                List<ChasePoint_Force> forces = new List<ChasePoint_Force>();

                // Attraction Force
                gradient = new[]
                {
                    Tuple.Create(0d, 0d),     // distance, %
                    Tuple.Create(.7d, .28d),
                    Tuple.Create(1d, 1d),
                };
                forces.Add(new ChasePoint_Force(ChaseDirectionType.Attract_Direction, 500, gradient: gradient));

                // This acts like a shock absorber
                gradient = new[]
                {
                    Tuple.Create(0d, .25d),
                    Tuple.Create(.75d, 1d),
                    //Tuple.Create(3d, 0d),
                };
                forces.Add(new ChasePoint_Force(ChaseDirectionType.Drag_Velocity_Along, 10));

                chaseForces = new MapObject_ChasePoint_Forces(item, false);
                chaseForces.Forces = forces.ToArray();
            }

            #endregion
            #region Torques - ORIG

            //MapObject_ChaseOrientation_Torques chaseTorques = null;

            //if (_shouldApplyTorques && shouldLimitRotation)
            //{
            //    List<ChaseOrientation_Torque> torques = new List<ChaseOrientation_Torque>();

            //    double mult = 60;

            //    // Attraction
            //    gradient = new[]
            //    {
            //        Tuple.Create(0d, 0d),     // distance, %
            //        Tuple.Create(10d, 1d),
            //    };
            //    torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Attract_Direction, .6 * mult, gradient: gradient));

            //    // Drag
            //    torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_Orth, .015 * mult));

            //    gradient = new[]
            //    {
            //        Tuple.Create(0d, 1d),
            //        Tuple.Create(1.6d, .3d),
            //        Tuple.Create(5d, 0d),
            //    };
            //    //torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_AlongIfVelocityToward, .04 * mult, gradient: gradient));
            //    torques.Add(new ChaseOrientation_Torque(ChaseDirectionType.Drag_Velocity_AlongIfVelocityAway, .04 * mult, gradient: gradient));


            //    chaseTorques = new MapObject_ChaseOrientation_Torques(item);
            //    chaseTorques.Torques = torques.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[]
                {
                    Tuple.Create(0d, 0d),     // distance, %
                    Tuple.Create(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)
                {
                    Tuple.Create(0d, 0d),     // distance, %
                    Tuple.Create(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);
                chaseTorques.Torques = torques.ToArray();
            }

            #endregion

            _items.Add(new TrackedItem(item, chaseForces, chaseTorques, graduleTo100PercentDuration, delayBeforeGradule, shouldLimitRotation));
        }