private void CreateHandFixture(Hand hand) { Vector2 handPos = new Vector2(hand.Position.X, hand.Position.Y); Body handBody = BodyFactory.CreateCircle(world, handSize, 1f, handPos / MeterInPixels); handBody.BodyType = BodyType.Dynamic; // Check what hands should be colliding with if (handCollisionsEnabled) { handBody.OnCollision += HandCollisionCheckDelegate; } else { handBody.OnCollision += HandCollisionFalseDelegate; } FixedMouseJoint handJoint = new FixedMouseJoint(handBody, handBody.Position); handJoint.MaxForce = 10000f; world.AddJoint(handJoint); WorldEntity handEntity = new WorldEntity(handBody, handJoint, WorldEntity.EntityType.Hand); handBodies.Add(hand, handEntity); entities.Add(handBody, handEntity); }
private void RemoveHandFixture(Hand hand) { WorldEntity bodyEntity = handBodies[hand]; world.RemoveJoint(bodyEntity.Joint); world.RemoveBody(bodyEntity.Body); handBodies.Remove(hand); entities.Remove(bodyEntity.Body); }
public void UpdateHandPositions(Hand[] hands) { // Go through the hands array looking for new hands, if we find any, register them foreach (Hand hand in hands) { if (!handBodies.ContainsKey(hand)) { this.CreateHandFixture(hand); } } // Deregister any hands which aren't there any more List<Hand> _removals = new List<Hand>(handBodies.Keys.Except(hands)); foreach (Hand hand in _removals) { this.RemoveHandFixture(hand); } // Move joint parts foreach (KeyValuePair<Hand, WorldEntity> handBody in handBodies) { handBody.Value.Joint.WorldAnchorB = new Vector2(handBody.Key.Position.X, handBody.Key.Position.Y) / MeterInPixels; } }