private void CreatePlayerPhysicsObjects(Vector2 gameWorldPosition) { MainFixture = FixtureFactory.CreateRectangle(Engine.Physics.World, 0.5f, 0.5f, 1); MainFixture.CollisionFilter.CollisionCategories = (Category)(Global.CollisionCategories.Player); Bodies.Add(MainFixture.Body); MainFixture.Body.Position = Engine.Physics.PositionToPhysicsWorld(gameWorldPosition); MainFixture.Body.BodyType = BodyType.Dynamic; MainFixture.Body.SleepingAllowed = false; WheelFixture = FixtureFactory.CreateCircle(Engine.Physics.World, 0.3f, 1.0f); WheelFixture.CollisionFilter.CollisionCategories = (Category)(Global.CollisionCategories.Player); Bodies.Add(WheelFixture.Body); WheelFixture.Body.Position = MainFixture.Body.Position + new Vector2(0.0f, 0.6f); WheelFixture.Body.BodyType = BodyType.Dynamic; WheelFixture.Body.SleepingAllowed = false; WheelFixture.Friction = 0.5f; playerFAJ = JointFactory.CreateFixedAngleJoint(Engine.Physics.World, MainFixture.Body); playerFAJ.BodyB = WheelFixture.Body; wheelMotorRevJoint = JointFactory.CreateRevoluteJoint(MainFixture.Body, WheelFixture.Body, Vector2.Zero); wheelMotorRevJoint.MaxMotorTorque = 10.0f; wheelMotorRevJoint.MotorEnabled = true; Engine.Physics.World.AddJoint(wheelMotorRevJoint); }
public ColEvent(EventType type, Fixture fxA, Fixture fxB, CollisionData data) { this.Type = type; this.FixtureA = fxA; this.FixtureB = fxB; this.Data = data; }
public void LoadContent(ContentManager content, World world, Vector2 position, Vector2 size) { body = BodyFactory.CreateRectangle(world, size.X, size.Y, 1f); body.FixedRotation = true; body.FixtureList[0].UserData = 9000; body.Position = ConvertUnits.ToSimUnits(position); body.BodyType = BodyType.Dynamic; CircleShape circle1 = new CircleShape(size.X / 4, 1f); CircleShape circle2 = new CircleShape(size.Y / 6, 1f); CircleShape circle3 = new CircleShape(size.Y / 6, 1f); circle1.Position = new Vector2(0, -size.Y / 3); circle2.Position = new Vector2(-1.5f * size.X / 5, -size.Y / 10); circle3.Position = new Vector2(-0.4f * size.X / 5, -size.Y / 10); head = body.CreateFixture(circle1); hands[0] = body.CreateFixture(circle2); hands[1] = body.CreateFixture(circle3); head.UserData = (int)10000; hands[0].UserData = (int)11000; hands[1].UserData = (int)11000; image.LoadContent(content, "Graphics/tezka", Color.White, position); image.ScaleToMeters(size); image.position = ConvertUnits.ToDisplayUnits(body.Position); }
// Collision handlers public bool CollisionWithEnemy(Fixture f1, Fixture f2, Contact contact) { Vector2 normal; FixedArray2<Vector2> points; contact.GetWorldManifold(out normal, out points); foreach (IGameComponent comp in this.game.Components) { GameEnemy enemy = comp as GameEnemy; if (enemy != null) { if (enemy.getFixture() == f2) { if ((Math.Abs(normal.Y) > Math.Abs(normal.X)) && (normal.Y < 0)) // The contact is coming from above { enemy.Die(); // Uncomment this line if we decide to fix the timing so we dispose after the animation this.increaseScore(10); this.Jump(); break; } else { this.Die(); } break; } } } return true; }
private void FixtureCut(Fixture f) { if (game.ragdollManager.ragdoll.OwnsFixture(f)) { StartBleedout(); } }
public void AreaBody_OnSeparation(Fixture fixa, Fixture fixb) { if (fixb.Body.BodyId == 19) { isTouchingPickUp = false; } }
public override Body CreateBody(World world) { Int32 count = 0; foreach (var key in _resource.TileDefinitionKeys) { var tileDefinition = (TerrainTileDefinitionResource)ResourceDictionary.GetResource(key); if (!String.IsNullOrEmpty(tileDefinition.CollisionHullKey)) { var vertices = new Vertices((Vector2[])this.ResourceDictionary.GetResource(tileDefinition.CollisionHullKey)); var body = new Body(world); _bodies.Add(body); body.BodyType = BodyType.Static; var location = ((ILocatable)_actor).Location; body.Position = new Vector2(((count % _resource.Columns) * _resource.TileWidth + location.X) / Settings.MetersToPixels, ((Int32)(count / _resource.Columns) * _resource.TileHeight + location.Y) / Settings.MetersToPixels); var shape = new PolygonShape(vertices, 0f); var fixture = new Fixture(body, shape, 1.0f); fixture.UserData = new CollisionData { Actor = _actor, Data = tileDefinition.CollisionData }; } count++; } return null; }
public override void OnCollisionExit(Fixture fixtureA, Fixture fixtureB) { //Is the CameraObject for the X or Y axis? if (this.height > this.width) // It is for the X axis { //Check which side the player is leaving if (fixtureB.Body.Position.X < fixtureA.Body.Position.X && fixtureB.Body.LinearVelocity.X < 0) //Player is moving to the left { if (this.unlockDirection == UnlockWhenPlayerMovesLeft) { this.UnlockCameraHorizontally(); } else { this.LockCameraHorizontally(); } } else if (fixtureB.Body.Position.X > fixtureA.Body.Position.X && fixtureB.Body.LinearVelocity.X > 0) //Player is moving to the right { if (this.unlockDirection == UnlockWhenPlayerMovesRight) { this.UnlockCameraHorizontally(); } else { this.LockCameraHorizontally(); } } } else //It is for the Y axis { } }
public CoolRibbonObject(World world, Texture2D tex) { points = new List<Vector2>(); points.Add(new Vector2(4, -1)); points.Add(new Vector2(4, 22)); points.Add(new Vector2(30, 22)); points.Add(new Vector2(30, -1)); stops = new float[4]; for(int i = 0; i < points.Count-1; i++) { stops[i] = Vector2.Distance(points[i],points[i+1]); } body = BodyFactory.CreateBody(world); body.BodyType = BodyType.Static; body.Position = new Vector2(0,0); body.UserData = this; hinges = new List<Hinge>(); AddBox(world, tex); ChainShape chain = new ChainShape(new Vertices(points)); fixture = body.CreateFixture(chain); }
bool body_OnCollision(Fixture fixtureA, Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { if (body.BodyType == BodyType.Static) return true; Fixture surface; if (fixtureA.Body == body) surface = fixtureB; else surface = fixtureA; if (surface.Body.BodyType == BodyType.Static && surface.Shape.MassData.Area > 100) { // rotate to contact normal Vector2 normal = contact.Manifold.LocalNormal; if (Vector2.Dot(normal, body.LinearVelocity) > 0) { return false; } isPendingAttach = true; pendingRotation = (float)Math.Atan2(normal.Y, normal.X); body.CollidesWith = Category.None; return false; } return true; }
private void Explode() { if (Alive) { Vector2 explosionPoint = body.Position; world.RemoveBody(body); world.ProcessChanges(); body = null; CuttingTools.Cut(world, explosionPoint + new Vector2(2, 2), explosionPoint - new Vector2(2, 2), 0.01f); //world.ProcessChanges(); CuttingTools.Cut(world, explosionPoint + new Vector2(-2, 2), explosionPoint - new Vector2(-2, 2), 0.01f); //world.ProcessChanges(); Explosion e = new Explosion(world); e.Activate(explosionPoint, 2, 10); Alive = false; pivot = null; Vector2 screenLoc = ProjectionHelper.FarseerToPixel(explosionPoint); ParticleEffectManager.explosionEffect.Trigger(screenLoc); } }
public bool onCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { Torque = -Torque; _fixtures.Last().Body.AngularVelocity = 0; return true; }
public Turret(Vector2 farseerLoc, World w, RagdollManager r, Fixture f) { DebugMaterial gray = new DebugMaterial(MaterialType.Blank) { Color = Color.DarkGray }; body = new Body(w); pivot = FixtureFactory.AttachCircle(.9f, 1, body, gray); FixtureFactory.AttachRectangle(barrelLength, .5f, 1, new Vector2(barrelLength / 2, 0), body, gray); body.Position = farseerLoc; body.BodyType = BodyType.Dynamic; //b.CollidesWith = Category.None; if (f == null) { motor = JointFactory.CreateFixedRevoluteJoint(w, body, Vector2.Zero, farseerLoc); } else { motor = new RevoluteJoint(body, f.Body, Vector2.Zero, f.Body.GetLocalPoint(farseerLoc)); w.AddJoint(motor); } motor.MotorEnabled = true; motor.MaxMotorTorque = 5000; Init(w, r); }
private SensorTest() { { Body ground = BodyFactory.CreateBody(World); { EdgeShape shape = new EdgeShape(new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); ground.CreateFixture(shape); } { CircleShape shape = new CircleShape(5.0f, 1); shape.Position = new Vector2(0.0f, 10.0f); _sensor = ground.CreateFixture(shape); _sensor.IsSensor = true; } } { CircleShape shape = new CircleShape(1.0f, 1); for (int i = 0; i < Count; ++i) { _touching[i] = false; _bodies[i] = BodyFactory.CreateBody(World); _bodies[i].BodyType = BodyType.Dynamic; _bodies[i].Position = new Vector2(-10.0f + 3.0f * i, 20.0f); _bodies[i].UserData = i; _bodies[i].CreateFixture(shape); } } }
public ProximityTrigger(Body sensorBody, Fixture sensorTemplate) { this.sensorBody = sensorBody; this.CreateSensors(sensorTemplate); this.IsEnabled = true; this.IsContinuous = false; }
public DebrisComponent(Fixture fixture, int timeToLive, float restitutionIncrement) { _fixture = fixture; _timeToLive = timeToLive; _restitutionIncrement = restitutionIncrement; _restitutionCount = 0; }
private OneSidedPlatformTest() { //Ground BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f)); // Platform { Body body = BodyFactory.CreateBody(World); body.Position = new Vector2(0.0f, 10.0f); PolygonShape shape = new PolygonShape(1); shape.SetAsBox(3.0f, 0.5f); _platform = body.CreateFixture(shape); _top = 10.0f + 0.5f; } // Actor { Body body = BodyFactory.CreateBody(World); body.BodyType = BodyType.Dynamic; body.Position = new Vector2(0.0f, 12.0f); _radius = 0.5f; CircleShape shape = new CircleShape(_radius, 20); _character = body.CreateFixture(shape); body.LinearVelocity = new Vector2(0.0f, -50.0f); } }
public virtual bool OnCollision(Fixture fixtureA, Fixture fixtureB, Contact contact) { Vector2 normal = Vector2.Zero; Contact currentContact = contact; Vector2 nextNormal = Vector2.Zero; FixedArray2<Vector2> fx; // No idea what that is, but the function wants it // Iterate through the contacts, summing the normals do { Vector2 vec = Vector2.Zero; contact.GetWorldManifold(out vec, out fx); normal += vec; currentContact = currentContact.Next; } while (currentContact != null); if (normal.Y > Y && normal.X == 0) { Pressed = true; _pressing.Add(fixtureB); } return true; }
public Ship(World world, SpawnData spawn, int id) { Ball = null; Id = id; IsThrusting = false; IsReversing = false; IsBoosting = false; IsLeftTurning = false; IsRightTurning = false; IsShooting = false; IsBlocked = false; IsBlockedFrame = false; Color = spawn.Color; var body = new Body(world); body.Rotation = FMath.Atan2(-spawn.Position.Y, -spawn.Position.X); body.Position = spawn.Position; var shape = new CircleShape(radius, 1f); body.BodyType = BodyType.Dynamic; body.FixedRotation = true; Fixture = body.CreateFixture(shape); Fixture.Restitution = restitution; var bodyGravity = new Body(world); bodyGravity.Position = spawn.Position; var shapeGravity = new CircleShape(radiusGravity, 1f); bodyGravity.FixedRotation = true; FixtureGravity = bodyGravity.CreateFixture(shapeGravity); FixtureGravity.IsSensor = true; }
public Goalie(World world, GoalieData spawn) { var body = new Body(world); var angle = spawn.End - spawn.Begin; body.Rotation = FMath.Atan2(angle.Y, angle.X); segment.A = spawn.Begin; segment.B = spawn.End; var normal = new Vector2(-angle.Y, angle.X); normal.Normalize(); delta = normal * .5f; segmentOut.A = spawn.Begin + delta; segmentOut.B = spawn.End + delta; segmentIn.A = spawn.Begin - delta; segmentIn.B = spawn.End - delta; body.Position = spawn.Begin; var verts = new Vertices(); verts.Add(new Vector2(left, bottom)); verts.Add(new Vector2(right, bottom)); verts.Add(new Vector2(right, top)); verts.Add(new Vector2(left, top)); var shape = new PolygonShape(verts, 1f); body.FixedRotation = true; body.BodyType = BodyType.Dynamic; Fixture = body.CreateFixture(shape); }
private float HandleRaycast(Fixture fixture, Vector2 point, Vector2 normal, float fraction) { if (fixture.CollisionCategories == _type.Category) return fraction; var dist = (point - Body.Position).Length(); var linksCount = (int)(Math.Floor(dist / LinksHeight) / 2); if (linksCount == 0) return fraction; // TODO: adapt this to Farseer 3.5 /*var chain = Add(K2.World.CreateChain(Body.Position, point, .005f, LinksHeight, linksCount, 1, false)); if (!chain.Bodies.Any()) return 0; chain.Bodies.ForEach(b => b.SetCollisionType(_type)); var first = chain.Bodies.First(); var last = chain.Bodies.Last(); K2.World.CreateRevoluteJoint(fixture.Body, last, new Vector2(0, LinksHeight)); K2.World.CreateRevoluteJoint(Body, chain.Bodies.First(), Vector2.Zero); //_joint = _factory.CreateDistanceJoint(first, last, new Vector2(0, LinksHeight), Vector2.Zero);*/ return 0; }
public Player(GL33Renderable renderable, Fixture physicsbody) : base(renderable, physicsbody) { LogicRunner<Events>.GetInstance().RegisterEventHandler (Events.ProjectileCollision, HandleProjectileCollision); LogicRunner<Events>.GetInstance().RegisterEventHandler (Events.FireButtonPressed, FireWeapon); LogicRunner<Events>.GetInstance().RegisterEventHandler (Events.MoveButtonPressed, Move); }
public override bool ObjectCollision(FarseerPhysics.Dynamics.Fixture f1, FarseerPhysics.Dynamics.Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact) { Object o1, o2; o1 = f1.Body.UserData; o2 = f2.Body.UserData; GoodCell goodCell; if (o2 is GoodCell) { goodCell = (GoodCell)o2; } else if (o2 is PlayerCell) { return(false); } else { return(true); } // If cell resistance is low enough, enter the cell and go towards the center if (IsNormal() && goodCell.VirusCollide(this)) { _state = VirusCellState.Assimilating; Body.IgnoreCollisionWith(goodCell.Body); _targetCell = goodCell; Strategy = new VirusAssimilateStrategy(goodCell); Body.LinearDamping = 10; } return(true); }
public Boolean collisionBullet(Fixture fixA, Fixture fixB, Contact contact) { if (!isHung) //je joins la balle a la cible avec un angle strict, et la balle au joueur avec un distance joint { Vector2 diff = bullet.FixtureObject.Body.Position - fixB.Body.Position; //ObjCercle bulletTP = new ObjCercle(diff, radius, 0.0f, worldPhysic, fixB.Body); //worldPhysic.RemoveBody(bullet.FixtureObject.Body); //bullet = bulletTP; //bullet.addDisplayer(); //juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(1, 1)/*AnchorPointJuncturePoint*/, new Vector2(1, 1)); //juncture = JointFactory.CreateDistanceJoint(worldPhysic, juncturePoint.Body, bullet.FixtureObject.Body, new Vector2(10,0)/*AnchorPointJuncturePoint*/, new Vector2(10,0)); //worldPhysic.AddJoint(juncture); //junctureHook = JointFactory. CreateRevoluteJoint(worldPhysic, fixA.Body, fixB.Body, diff); //junctureHook.MaxImpulse = 3; //junctureHook. worldPhysic.RemoveBody(bullet.FixtureObject.Body); bullet = null; //bullet.FixtureObject.Body.BodyType = BodyType.Dynamic; juncture = new FarseerPhysics.Dynamics.Joints.DistanceJoint(juncturePoint.Body, fixB.Body, AnchorPointJuncturePoint, new Vector2(diff.X, diff.Y)); worldPhysic.AddJoint(juncture); isHung = true; } return false; }
public PhysicsGameObject(Texture2D texture, World world, bool isStatic, Vector2 position, float scale, float density, float depth) { this.texture = texture; this.scale = scale; this.density = density; this.depth = depth; //loads body details objectBody = new Body(world); objectBody.Position = position; if (isStatic) objectBody.BodyType = BodyType.Static; else objectBody.IsStatic = false; this.scale = scale; this.depth = depth; //loads fixture details objectFixture = FixtureFactory.AttachRectangle( texture.Width / PIXELS_PER_METER, texture.Height / PIXELS_PER_METER, 1, Vector2.Zero, objectBody); objectFixture.Restitution = RESTITUTION; objectFixture.Friction = FRICTION; }
protected override bool OnCollision(Fixture projectile, Fixture collided, Contact contact) { if (NoCollide) return false; var collidedUnit = (collided.Body.UserData is Unit) ? (Unit)(collided.Body.UserData) : null; if (collidedUnit != null) { if (collidedUnit == Owner) { Owner.ModifyAttackCooldown(-1000f); Expire(); } else { foreach (Aura aura in Auras) { collidedUnit.AddAura(aura); } collidedUnit.Hurt(Damage); Body.LinearVelocity = Vector2.Zero; Body.IgnoreGravity = false; Body.ApplyLinearImpulse(new Vector2((Owner.Position.X - collidedUnit.Position.X)*7, -200)); Body.ApplyTorque(-2000f); Body.CollidesWith = Category.Cat1 | Category.Cat2; Body.CollisionCategories = Category.Cat5; } } return false; }
protected virtual void SetUpPhysics(World world, Vector2 position, float width, float height, float mass) { fixture = FixtureFactory.CreateRectangle(world, ConvertUnits.ToSimUnits(width), ConvertUnits.ToSimUnits(height), mass, ConvertUnits.ToSimUnits(position)); body = fixture.Body; fixture.Body.BodyType = BodyType.Dynamic; fixture.Restitution = 0.3f; fixture.Friction = 0.5f; }
public override void Create(FarseerPhysics.Dynamics.World world, float Xoffset) { base.Create(world, Xoffset); _button = FixtureFactory.CreateRectangle(_world, Dimensions.X, Dimensions.Y, 1, Position + new Vector2(Xoffset, 0)); _fixtures.Add(_button); _fixtures.Last().UserData = this; }
public virtual bool OnCollidedWith(Fixture f, UserControlledCharacter obj, Fixture f2, Contact info) { if (Engine.CameraLock) { Engine.CameraLock = false; } return false; }
public static Vector2 GetCenterLocal(Fixture fixture) { PolygonShape shape = (PolygonShape)fixture.Shape; var vertices = shape.Vertices; return new Vector2( vertices.Average(vert => vert.X), vertices.Average(vert => vert.Y)); }
void BodyObject_OnSeparation(Fixture fixtureA, Fixture fixtureB) { if(_player.BodyObject.FixtureList.Contains(fixtureA) || _player.BodyObject.FixtureList.Contains(fixtureB)) { target.Stroke = new SolidColorBrush(Colors.Transparent); _touchingPlayer = false; } }
private bool Body_onCollision(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { if (player.weapon == null) { var uiManager = Core.getGlobalManager <GameUIManager>(); if ((GameEvent.homeEvent & GameHomeEvent.initWeaponBoxOpened) == 0) { IList <Conmunication> conmunications = new List <Conmunication>(); conmunications.Add(new Conmunication("Images/headIcons/Link_Sprite", "宝箱里有武器,还是把武器带上吧")); uiManager.createConmunication(conmunications); } else { IList <Conmunication> conmunications = new List <Conmunication>(); conmunications.Add(new Conmunication("Images/headIcons/Link_Sprite", "江湖险恶还是把武器先装备上吧,摁Q选择装备进行装备")); uiManager.createConmunication(conmunications); } player.position += new Vector2(0, -5); } else { var shuchengArea = new ShuChengArea(); var transition = new FadeTransition(() => { player.detachFromScene(); player.attachToScene(shuchengArea); player.setPosition(345, 110); return(shuchengArea); }); transition.onTransitionCompleted = () => { GameSetting.isGamePause = false; }; Core.startSceneTransition(transition); GameSetting.isGamePause = true; } return(true); }
private bool Body_onCollision(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { var shuchengRoom = new ShuChengRoom(); var transition = new FadeTransition(() => { player.detachFromScene(); player.attachToScene(shuchengRoom); player.setPosition(120, 200); return(shuchengRoom); }); transition.onTransitionCompleted += () => { GameSetting.isGamePause = false; }; Core.startSceneTransition(transition); GameSetting.isGamePause = true; return(true); }
public Fixture DeepClone() { Fixture fix = Clone(Body.Clone()); return(fix); }
void Trigger_OnExit(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB) { Console.WriteLine("Exit!"); }
bool Trigger_OnEnter(FarseerPhysics.Dynamics.Fixture fixtureA, FarseerPhysics.Dynamics.Fixture fixtureB, FarseerPhysics.Dynamics.Contacts.Contact contact) { Console.WriteLine("Enter!"); return(false); }
/// <summary> /// Find TOI contacts and solve them. /// </summary> /// <param name="step">The step.</param> private void SolveTOI(ref TimeStep step) { this.Island.Reset(2 * Settings.MaxTOIContacts, Settings.MaxTOIContacts, 0, this.ContactManager); if (this._stepComplete) { for (int i = 0; i < this.BodyList.Count; i++) { this.BodyList[i].Flags &= ~BodyFlags.Island; this.BodyList[i].Sweep.Alpha0 = 0.0f; } for (int i = 0; i < this.ContactManager.ContactList.Count; i++) { Contact c = this.ContactManager.ContactList[i]; // Invalidate TOI c.Flags &= ~(ContactFlags.TOI | ContactFlags.Island); c.TOICount = 0; c.TOI = 1.0f; } } // Find TOI events and solve them. for (; ;) { // Find the first TOI. Contact minContact = null; float minAlpha = 1.0f; for (int i = 0; i < this.ContactManager.ContactList.Count; i++) { Contact c = this.ContactManager.ContactList[i]; // Is this contact disabled? if (c.Enabled == false) { continue; } // Prevent excessive sub-stepping. if (c.TOICount > Settings.MaxSubSteps) { continue; } float alpha; if ((c.Flags & ContactFlags.TOI) == ContactFlags.TOI) { // This contact has a valid cached TOI. alpha = c.TOI; } else { Fixture fA = c.FixtureA; Fixture fB = c.FixtureB; // Is there a sensor? if (fA.IsSensor || fB.IsSensor) { continue; } Body bA = fA.Body; Body bB = fB.Body; BodyType typeA = bA.BodyType; BodyType typeB = bB.BodyType; Debug.Assert(typeA == BodyType.Dynamic || typeB == BodyType.Dynamic); bool awakeA = bA.Awake && typeA != BodyType.Static; bool awakeB = bB.Awake && typeB != BodyType.Static; // Is at least one body awake? if (awakeA == false && awakeB == false) { continue; } bool collideA = (bA.IsBullet || typeA != BodyType.Dynamic) && !bA.IgnoreCCD; bool collideB = (bB.IsBullet || typeB != BodyType.Dynamic) && !bB.IgnoreCCD; // Are these two non-bullet dynamic bodies? if (collideA == false && collideB == false) { continue; } // Compute the TOI for this contact. // Put the sweeps onto the same time interval. float alpha0 = bA.Sweep.Alpha0; if (bA.Sweep.Alpha0 < bB.Sweep.Alpha0) { alpha0 = bB.Sweep.Alpha0; bA.Sweep.Advance(alpha0); } else if (bB.Sweep.Alpha0 < bA.Sweep.Alpha0) { alpha0 = bA.Sweep.Alpha0; bB.Sweep.Advance(alpha0); } Debug.Assert(alpha0 < 1.0f); // Compute the time of impact in interval [0, minTOI] this._input.ProxyA.Set(fA.Shape, c.ChildIndexA); this._input.ProxyB.Set(fB.Shape, c.ChildIndexB); this._input.SweepA = bA.Sweep; this._input.SweepB = bB.Sweep; this._input.TMax = 1.0f; TOIOutput output; TimeOfImpact.CalculateTimeOfImpact(out output, this._input); // Beta is the fraction of the remaining portion of the . float beta = output.T; if (output.State == TOIOutputState.Touching) { alpha = Math.Min(alpha0 + (1.0f - alpha0) * beta, 1.0f); } else { alpha = 1.0f; } c.TOI = alpha; c.Flags |= ContactFlags.TOI; } if (alpha < minAlpha) { // This is the minimum TOI found so far. minContact = c; minAlpha = alpha; } } if (minContact == null || 1.0f - 10.0f * Settings.Epsilon < minAlpha) { // No more TOI events. Done! this._stepComplete = true; break; } // Advance the bodies to the TOI. Fixture fA1 = minContact.FixtureA; Fixture fB1 = minContact.FixtureB; Body bA1 = fA1.Body; Body bB1 = fB1.Body; Sweep backup1 = bA1.Sweep; Sweep backup2 = bB1.Sweep; bA1.Advance(minAlpha); bB1.Advance(minAlpha); // The TOI contact likely has some new contact points. minContact.Update(this.ContactManager); minContact.Flags &= ~ContactFlags.TOI; ++minContact.TOICount; // Is the contact solid? if (minContact.Enabled == false || minContact.IsTouching() == false) { // Restore the sweeps. minContact.Enabled = false; bA1.Sweep = backup1; bB1.Sweep = backup2; bA1.SynchronizeTransform(); bB1.SynchronizeTransform(); continue; } bA1.Awake = true; bB1.Awake = true; // Build the island this.Island.Clear(); this.Island.Add(bA1); this.Island.Add(bB1); this.Island.Add(minContact); bA1.Flags |= BodyFlags.Island; bB1.Flags |= BodyFlags.Island; minContact.Flags |= ContactFlags.Island; // Get contacts on bodyA and bodyB. Body[] bodies = { bA1, bB1 }; for (int i = 0; i < 2; ++i) { Body body = bodies[i]; if (body.BodyType == BodyType.Dynamic) { // for (ContactEdge ce = body.ContactList; ce && Island.BodyCount < Settings.MaxTOIContacts; ce = ce.Next) for (ContactEdge ce = body.ContactList; ce != null; ce = ce.Next) { Contact contact = ce.Contact; // Has this contact already been added to the island? if ((contact.Flags & ContactFlags.Island) == ContactFlags.Island) { continue; } // Only add static, kinematic, or bullet bodies. Body other = ce.Other; if (other.BodyType == BodyType.Dynamic && body.IsBullet == false && other.IsBullet == false) { continue; } // Skip sensors. if (contact.FixtureA.IsSensor || contact.FixtureB.IsSensor) { continue; } // Tentatively advance the body to the TOI. Sweep backup = other.Sweep; if ((other.Flags & BodyFlags.Island) == 0) { other.Advance(minAlpha); } // Update the contact points contact.Update(this.ContactManager); // Was the contact disabled by the user? if (contact.Enabled == false) { other.Sweep = backup; other.SynchronizeTransform(); continue; } // Are there contact points? if (contact.IsTouching() == false) { other.Sweep = backup; other.SynchronizeTransform(); continue; } // Add the contact to the island contact.Flags |= ContactFlags.Island; this.Island.Add(contact); // Has the other body already been added to the island? if ((other.Flags & BodyFlags.Island) == BodyFlags.Island) { continue; } // Add the other body to the island. other.Flags |= BodyFlags.Island; if (other.BodyType != BodyType.Static) { other.Awake = true; } this.Island.Add(other); } } } TimeStep subStep; subStep.dt = (1.0f - minAlpha) * step.dt; subStep.inv_dt = 1.0f / subStep.dt; subStep.dtRatio = 1.0f; //subStep.positionIterations = 20; //subStep.velocityIterations = step.velocityIterations; //subStep.warmStarting = false; this.Island.SolveTOI(ref subStep); // Reset island flags and synchronize broad-phase proxies. for (int i = 0; i < this.Island.BodyCount; ++i) { Body body = this.Island.Bodies[i]; body.Flags &= ~BodyFlags.Island; if (body.BodyType != BodyType.Dynamic) { continue; } body.SynchronizeFixtures(); // Invalidate all contact TOIs on this displaced body. for (ContactEdge ce = body.ContactList; ce != null; ce = ce.Next) { ce.Contact.Flags &= ~(ContactFlags.TOI | ContactFlags.Island); } } // Commit fixture proxy movements to the broad-phase so that new contacts are created. // Also, some contacts can be destroyed. this.ContactManager.FindNewContacts(); if (this.EnableSubStepping) { this._stepComplete = false; break; } } }
public virtual void OnSeparation(Dyn.Fixture f1, Dyn.Fixture f2) { Log.Message("Separation happend"); }
public virtual bool OnCollision(Dyn.Fixture f1, Dyn.Fixture f2, Dyn.Contacts.Contact contact) { Log.Message("Collision happened: {0}, {1}, {2}", f1.Body.UserData, f2.Body.UserData, contact); return(true); }
/// <summary> /// Determines whether collisions are ignored between this fixture and the provided fixture. /// </summary> /// <param name="fixture">The fixture.</param> /// <returns> /// <c>true</c> if the fixture is ignored; otherwise, <c>false</c>. /// </returns> public bool IsFixtureIgnored(Fixture fixture) { return(_collisionIgnores.Contains(fixture.FixtureId)); }
public override bool ObjectCollision(FarseerPhysics.Dynamics.Fixture f1, FarseerPhysics.Dynamics.Fixture f2, FarseerPhysics.Dynamics.Contacts.Contact contact) { return(true); }