Example #1
0
        public void RemoveJoint(IAxleJoint joint)
        {
            if (!(joint is AxleJoint))
            {
                throw new ArgumentException("Joint does not belong to this physics engine.");
            }

            var j = ((AxleJoint)joint).innerJoint;

            j.Lifetime.IsExpired = true;
        }
Example #2
0
        /// <summary>
        /// Lisää olion rakenteeseen.
        /// </summary>
        /// <param name="obj">Lisättävä olio</param>
        public void Add(IGameObject obj)
        {
            if (!(obj is PhysicsObject))
            {
                throw new NotImplementedException("Currently only PhysicsObjects can be added to a structure.");
            }

            if (!IsAddedToGame)
            {
                // Add to game and use relative coordinates
                obj.Position += this.Position;

                if (!obj.IsAddedToGame)
                {
                    Game.Instance.Add(obj);
                }
            }

            PhysicsObject physObj = (PhysicsObject)obj;

            physObj.ParentStructure          = this;
            physObj.IsVisible                = _isVisible;
            physObj.IgnoresGravity           = _ignoresGravity;
            physObj.IgnoresCollisionResponse = _ignoresCollisionResponse;
            physObj.IgnoresExplosions        = _ignoresExplosions;
            physObj.IgnoresPhysicsLogics     = _ignoresPhysicsLogics;
            physObj.CollisionIgnoreGroup     = _collisionIgnoreGroup;
            physObj.CollisionIgnorer         = _collisionIgnorer;
            physObj.Restitution              = _restitution;
            physObj.StaticFriction           = _sfriction;
            physObj.KineticFriction          = _kfriction;
            physObj.LinearDamping            = _linearDamping;
            physObj.AngularDamping           = _angularDamping;

            physObj.Collided += this.OnCollided;

            var game = PhysicsGameBase.Instance;

            foreach (var existing in objects)
            {
                IAxleJoint joint = game.Engine.CreateJoint(physObj, existing, existing.AbsolutePosition);
                joint.Softness = _softness;
                Joints.Add(joint);
                game.Add(joint);
            }

            objects.Add(physObj);
            CalculateMomentOfInertia();
        }
Example #3
0
 void OnJointAdded(IAxleJoint j)
 {
     if (!j.Object1.IsAddedToGame)
     {
         j.SetEngine(Engine);
         j.Object1.AddedToGame += j.AddToEngine;
     }
     else if (j.Object2 != null && !j.Object2.IsAddedToGame)
     {
         j.SetEngine(Engine);
         j.Object2.AddedToGame += j.AddToEngine;
     }
     else
     {
         Engine.AddJoint(j);
     }
 }
Example #4
0
        private void AddWheels()
        {
            PhysicsGameBase pg = Game.Instance as PhysicsGameBase;

            if (pg == null)
            {
                throw new InvalidOperationException("Cannot have a tank in non-physics game");
            }

            const int wheelCount = 6;

            double r    = this.Width / (2 * wheelCount);
            double left = this.X - this.Width / 2 + r;

            double[] wheelYPositions = new double[wheelCount];
            for (int i = 0; i < wheelYPositions.Length; i++)
            {
                wheelYPositions[i] = this.Y - this.Height / 2;
            }
            wheelYPositions[0] = wheelYPositions[wheelCount - 1] = this.Position.Y - (this.Height * 3 / 8);

            for (int i = 0; i < wheelCount; i++)
            {
                PhysicsObject wheel = new PhysicsObject(2 * r, 2 * r, Shape.Circle);
                wheel.Mass                = this.Mass / 20;
                wheel.Color               = Color.Gray;
                wheel.CollisionIgnorer    = this.CollisionIgnorer;
                wheel.Body.AngularDamping = 0.95f;
                wheel.KineticFriction     = 1.0;
                wheels.Add(wheel);
                pg.Add(wheel);

                Vector axlePos = new Vector(left + i * (this.Width / wheelCount), wheelYPositions[i]);
                wheel.Position = axlePos;
                IAxleJoint joint = pg.Engine.CreateJoint(this, wheel, new Vector(axlePos.X, axlePos.Y));
                joint.Softness = 0.01f;
                joints.Add(joint);
                pg.Add(joint);
            }
        }
Example #5
0
 public void RemoveJoint(IAxleJoint joint)
 {
 }
Example #6
0
 public void AddJoint(IAxleJoint joint)
 {
     throw new NotImplementedException("Joints are not implemented in SimplePhysics yet.");
 }
Example #7
0
 /// <summary>
 /// Poistaa liitoksen pelistä.
 /// </summary>
 /// <param name="j"></param>
 internal void Remove(IAxleJoint j)
 {
     Joints.Remove(j);
 }
Example #8
0
 /// <summary>
 /// Lisää liitoksen peliin.
 /// </summary>
 public void Add(IAxleJoint j)
 {
     Joints.Add(j);
 }
Example #9
0
 void OnJointRemoved(IAxleJoint j)
 {
     Engine.RemoveJoint(j);
 }