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; }
/// <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(); }
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); } }
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); } }
public void RemoveJoint(IAxleJoint joint) { }
public void AddJoint(IAxleJoint joint) { throw new NotImplementedException("Joints are not implemented in SimplePhysics yet."); }
/// <summary> /// Poistaa liitoksen pelistä. /// </summary> /// <param name="j"></param> internal void Remove(IAxleJoint j) { Joints.Remove(j); }
/// <summary> /// Lisää liitoksen peliin. /// </summary> public void Add(IAxleJoint j) { Joints.Add(j); }
void OnJointRemoved(IAxleJoint j) { Engine.RemoveJoint(j); }