Beispiel #1
0
 public AngleJoint CreateAngleJoint(Body body1, Body body2, float softness, float biasFactor)
 {
     AngleJoint angleJoint = new AngleJoint(body1, body2);
     angleJoint.Softness = softness;
     angleJoint.BiasFactor = biasFactor;
     return angleJoint;
 }
Beispiel #2
0
        public void Load(SimulatorView view, PhysicsSimulator physicsSimulator)
        {
            //Load bodies
            _spiderBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _spiderBodyRadius, 1);
            _spiderBody.Position = _position;
            _spiderBody.IsStatic = false;
            view.AddCircleToCanvas(_spiderBody, _spiderBodyRadius);
            _leftUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                         _upperLegSize.Y,
                                                                         1);
            _leftUpperLegBody.Position = _spiderBody.Position - new Vector2(_spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X/2, 0);
            view.AddRectangleToCanvas(_leftUpperLegBody, Colors.White, new Vector2(_upperLegSize.X, _upperLegSize.Y));

            _leftLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                         _lowerLegSize.Y,
                                                                         1);
            _leftLowerLegBody.Position = _spiderBody.Position - new Vector2(_spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X, 0) - new Vector2(_lowerLegSize.X/2, 0);
            view.AddRectangleToCanvas(_leftLowerLegBody, Colors.Red, new Vector2(_lowerLegSize.X, _lowerLegSize.Y));

            _rightUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                          _upperLegSize.Y, 1);
            _rightUpperLegBody.Position = _spiderBody.Position + new Vector2(_spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X/2, 0);
            view.AddRectangleToCanvas(_rightUpperLegBody, Colors.White, new Vector2(_upperLegSize.X, _upperLegSize.Y));

            _rightLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                          _lowerLegSize.Y, 1);
            _rightLowerLegBody.Position = _spiderBody.Position + new Vector2(_spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X, 0) + new Vector2(_lowerLegSize.X/2, 0);
            view.AddRectangleToCanvas(_rightLowerLegBody, Colors.Red, new Vector2(_lowerLegSize.X, _lowerLegSize.Y));

            //load geometries
            _spiderGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _spiderBody, _spiderBodyRadius, 14);
            _leftUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftUpperLegBody,
                                                                         _upperLegSize.X, _upperLegSize.Y);
            _leftLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftLowerLegBody,
                                                                         _lowerLegSize.X, _lowerLegSize.Y);
            _rightUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightUpperLegBody,
                                                                          _upperLegSize.X, _upperLegSize.Y);
            _rightLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightLowerLegBody,
                                                                          _lowerLegSize.X, _lowerLegSize.Y);
            _spiderGeom.CollisionGroup = _collisionGroup;
            _leftUpperLegGeom.CollisionGroup = _collisionGroup;
            _leftLowerLegGeom.CollisionGroup = _collisionGroup;
            _rightUpperLegGeom.CollisionGroup = _collisionGroup;
            _rightLowerLegGeom.CollisionGroup = _collisionGroup;

            //load joints
            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody,
                                                      _leftUpperLegBody,
                                                      _spiderBody.Position -
                                                      new Vector2(_spiderBodyRadius, 0));
            _leftShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody,
                                                                             _leftUpperLegBody);
            _leftShoulderAngleJoint.TargetAngle = -.4f;
            _leftShoulderAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _spiderBody,
                                                      _rightUpperLegBody,
                                                      _spiderBody.Position +
                                                      new Vector2(_spiderBodyRadius, 0));
            _rightShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _spiderBody,
                                                                              _rightUpperLegBody);
            _rightShoulderAngleJoint.TargetAngle = .4f;
            _leftShoulderAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _leftUpperLegBody,
                                                      _leftLowerLegBody,
                                                      _spiderBody.Position -
                                                      new Vector2(_spiderBodyRadius, 0) -
                                                      new Vector2(_upperLegSize.X, 0));
            _leftKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _leftUpperLegBody,
                                                                         _leftLowerLegBody);
            _leftKneeAngleJoint.TargetAngle = -_kneeTargetAngle;
            _leftKneeAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _rightUpperLegBody,
                                                      _rightLowerLegBody,
                                                      _spiderBody.Position +
                                                      new Vector2(_spiderBodyRadius, 0) +
                                                      new Vector2(_upperLegSize.X, 0));
            _rightKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _rightUpperLegBody,
                                                                          _rightLowerLegBody);
            _rightKneeAngleJoint.TargetAngle = _kneeTargetAngle;
            _rightKneeAngleJoint.MaxImpulse = 300;
        }
Beispiel #3
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _spiderTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, spiderBodyRadius, Color.White,
                                                               Color.Black);
            _spiderOrigin = new Vector2(_spiderTexture.Width/2f, _spiderTexture.Height/2f);

            _upperLegTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, (int) _upperLegSize.X,
                                                                    (int) _upperLegSize.Y, Color.White, Color.Black);
            _upperLegOrigin = new Vector2(_upperLegTexture.Width/2f, _upperLegTexture.Height/2f);

            _lowerLegTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, (int) _lowerLegSize.X,
                                                                    (int) _lowerLegSize.Y, Color.Red, Color.Black);
            _lowerLegOrigin = new Vector2(_lowerLegTexture.Width/2f, _lowerLegTexture.Height/2f);

            //Load bodies
            Body = BodyFactory.Instance.CreateCircleBody(physicsSimulator, spiderBodyRadius, 1);
            Body.Position = _position;
            Body.IsStatic = false;

            _leftUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                         _upperLegSize.Y,
                                                                         1);
            _leftUpperLegBody.Position = Body.Position - new Vector2(spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X/2, 0);

            _leftLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                         _lowerLegSize.Y,
                                                                         1);
            _leftLowerLegBody.Position = Body.Position - new Vector2(spiderBodyRadius, 0) -
                                         new Vector2(_upperLegSize.X, 0) - new Vector2(_lowerLegSize.X/2, 0);

            _rightUpperLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _upperLegSize.X,
                                                                          _upperLegSize.Y, 1);
            _rightUpperLegBody.Position = Body.Position + new Vector2(spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X/2, 0);

            _rightLowerLegBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _lowerLegSize.X,
                                                                          _lowerLegSize.Y, 1);
            _rightLowerLegBody.Position = Body.Position + new Vector2(spiderBodyRadius, 0) +
                                          new Vector2(_upperLegSize.X, 0) + new Vector2(_lowerLegSize.X/2, 0);

            //load geometries
            _spiderGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, Body, spiderBodyRadius, 14);
            _leftUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftUpperLegBody,
                                                                         _upperLegSize.X, _upperLegSize.Y);
            _leftLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _leftLowerLegBody,
                                                                         _lowerLegSize.X, _lowerLegSize.Y);
            _rightUpperLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightUpperLegBody,
                                                                          _upperLegSize.X, _upperLegSize.Y);
            _rightLowerLegGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rightLowerLegBody,
                                                                          _lowerLegSize.X, _lowerLegSize.Y);
            _spiderGeom.CollisionGroup = CollisionGroup;
            _leftUpperLegGeom.CollisionGroup = CollisionGroup;
            _leftLowerLegGeom.CollisionGroup = CollisionGroup;
            _rightUpperLegGeom.CollisionGroup = CollisionGroup;
            _rightLowerLegGeom.CollisionGroup = CollisionGroup;

            //load joints
            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, Body,
                                                      _leftUpperLegBody,
                                                      Body.Position -
                                                      new Vector2(spiderBodyRadius, 0));
            _leftShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, Body,
                                                                             _leftUpperLegBody);
            _leftShoulderAngleJoint.TargetAngle = -.4f;
            _leftShoulderAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, Body,
                                                      _rightUpperLegBody,
                                                      Body.Position +
                                                      new Vector2(spiderBodyRadius, 0));
            _rightShoulderAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, Body,
                                                                              _rightUpperLegBody);
            _rightShoulderAngleJoint.TargetAngle = .4f;
            _leftShoulderAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _leftUpperLegBody,
                                                      _leftLowerLegBody,
                                                      Body.Position -
                                                      new Vector2(spiderBodyRadius, 0) -
                                                      new Vector2(_upperLegSize.X, 0));
            _leftKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _leftUpperLegBody,
                                                                         _leftLowerLegBody);
            _leftKneeAngleJoint.TargetAngle = -_kneeTargetAngle;
            _leftKneeAngleJoint.MaxImpulse = 300;

            JointFactory.Instance.CreateRevoluteJoint(physicsSimulator, _rightUpperLegBody,
                                                      _rightLowerLegBody,
                                                      Body.Position +
                                                      new Vector2(spiderBodyRadius, 0) +
                                                      new Vector2(_upperLegSize.X, 0));
            _rightKneeAngleJoint = JointFactory.Instance.CreateAngleJoint(physicsSimulator, _rightUpperLegBody,
                                                                          _rightLowerLegBody);
            _rightKneeAngleJoint.TargetAngle = _kneeTargetAngle;
            _rightKneeAngleJoint.MaxImpulse = 300;
        }
 public AngleJoint CreateAngleJoint(Body body1, Body body2)
 {
     AngleJoint angleJoint = new AngleJoint(body1, body2);
     return angleJoint;
 }