예제 #1
0
        // Slight Hack, if both OnSeparation and OnCollision event are subscribed to
        // the OnSeparation call is either ignored or lost in the works of the
        // Farseer Physics engine. A simple solution is to use 2 fixtures, both sensors, that
        // ignore eachother in collision and subscribe to OnSeparation/OnCollision individually
        private void CreateSensors(Fixture sensorTemplate)
        {
            this.collisionFixture = sensorTemplate;
            if (!this.sensorBody.FixtureList.Contains(sensorTemplate))
            {
                this.collisionFixture = sensorTemplate.CloneOnto(this.sensorBody);
            }

            this.separationFixture = this.collisionFixture.CloneOnto(this.sensorBody);

            this.collisionFixture.OnCollision += this.OnCollision;
            this.collisionFixture.IsSensor = true;

            this.separationFixture.OnSeparation += this.OnSeparation;
            this.separationFixture.IsSensor = true;
            this.separationFixture.IgnoreCCDWith = Category.All;

            foreach (var fixture in this.sensorBody.FixtureList)
            {
                this.collisionFixture.IgnoreCollisionWith(fixture);
                this.separationFixture.IgnoreCollisionWith(fixture);
            }
        }