Exemplo n.º 1
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            agentBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5);
            agentBody.Position = _position;
            physicsCanvas.AddAgentToCanvas(agentBody);
            agentGeom    = new Geom[7];
            agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, agentBody, 16, 10,
                                                                 new Vector2(-40, -40), 0);
            agentGeom[0].RestitutionCoefficient = .4f;
            agentGeom[0].FrictionCoefficient    = .2f;
            agentGeom[0].CollisionGroup         = 1;
            agentGeom[0].CollisionCategories    = collisionCategory;
            agentGeom[0].CollidesWith           = collidesWith;
            agentGeom[1] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
                                                           new Vector2(-40, 40), 0);
            agentGeom[2] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
                                                           new Vector2(40, -40), 0);
            agentGeom[3] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
                                                           new Vector2(40, 40), 0);
            agentGeom[4] = GeomFactory.Instance.CreateGeom(physicsSimulator, agentBody, agentGeom[0],
                                                           new Vector2(0, 0),
                                                           0);

            agentGeom[5] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, agentBody, 16, 120, Vector2.Zero,
                                                                    MathHelper.PiOver4);
            agentGeom[5].CollisionGroup      = 1;
            agentGeom[5].CollisionCategories = collisionCategory;
            agentGeom[5].CollidesWith        = collidesWith;

            agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, agentBody, 16, 120, Vector2.Zero,
                                                                    -MathHelper.PiOver4);
            agentGeom[6].CollisionGroup      = 1;
            agentGeom[6].CollisionCategories = collisionCategory;
            agentGeom[6].CollidesWith        = collidesWith;
        }
Exemplo n.º 2
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            //use the body factory to create the physics body
            borderBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, width, height, 1);
            borderBody.IsStatic = true;
            borderBody.Position = position;
            LoadBorderGeom(physicsSimulator);
            float left   = (position.X - width / 2f);
            float top    = (position.Y - height / 2f);
            float right  = (position.X + width / 2f);
            float bottom = (position.Y + height / 2f);

            Rectangle leftBorder = physicsCanvas.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                                      new Vector2(borderWidth, height));

            PhysicsCanvas.PositionTopLeft(leftBorder, new Vector2(left, top));

            Rectangle rightBorder = physicsCanvas.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                                       new Vector2(borderWidth, height));

            PhysicsCanvas.PositionTopLeft(rightBorder, new Vector2(right - borderWidth, top));

            Rectangle topBorder = physicsCanvas.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                                     new Vector2(width, borderWidth));

            PhysicsCanvas.PositionTopLeft(topBorder, new Vector2(left, top));

            Rectangle bottomBorder = physicsCanvas.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                                        new Vector2(width, borderWidth));

            PhysicsCanvas.PositionTopLeft(bottomBorder, new Vector2(left, bottom - borderWidth));
        }
Exemplo n.º 3
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            //use the body factory to create the physics body
            _platformBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1);
            physicsCanvas.AddRectangleToCanvas(_platformBody, Colors.White, new Vector2(_width, _height));
            _platformBody.IsStatic = true;
            _platformBody.Position = _position;

            _platformGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _platformBody, _width, _height);
            _platformGeom.CollisionGroup      = 100;
            _platformGeom.CollisionGroup      = _collisionGroup;
            _platformGeom.FrictionCoefficient = 1;
        }
Exemplo n.º 4
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            _linearSpring     = new LinearSpring[_rectangleCount - 1];
            _rectangleBody    = new Body[_rectangleCount];
            _rectangleBody[0] = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                         _rectangleHeight, _rectangleMass);
            _rectangleBody[0].Position = _position;
            physicsCanvas.AddRectangleToCanvas(_rectangleBody[0], Colors.White, new Vector2(_rectangleWidth, _rectangleHeight));
            for (int i = 1; i < _rectangleBody.Length; i++)
            {
                _rectangleBody[i] = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                             _rectangleHeight, _rectangleMass);
                _rectangleBody[i].Position = _rectangleBody[i - 1].Position + new Vector2(0, _springLength);
                physicsCanvas.AddRectangleToCanvas(_rectangleBody[i], Colors.White,
                                                   new Vector2(_rectangleWidth, _rectangleHeight));
            }

            _rectangleGeom    = new Geom[_rectangleCount];
            _rectangleGeom[0] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody[0],
                                                                         _rectangleWidth, _rectangleHeight);
            _rectangleGeom[0].CollisionGroup = _collisionGroup;
            for (int j = 1; j < _rectangleGeom.Length; j++)
            {
                _rectangleGeom[j] = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _rectangleBody[j],
                                                                             _rectangleWidth, _rectangleHeight);
                _rectangleGeom[j].CollisionGroup = _collisionGroup;
            }

            for (int k = 0; k < _linearSpring.Length; k++)
            {
                _linearSpring[k] = SpringFactory.Instance.CreateLinearSpring(physicsSimulator, _rectangleBody[k],
                                                                             Vector2.Zero, _rectangleBody[k + 1],
                                                                             Vector2.Zero, _springConstant,
                                                                             _dampningConstant);
            }
        }
Exemplo n.º 5
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            int radius;

            if (_attachPoint == 0 | _attachPoint == 2)
            {
                radius = _rectangleHeight;
            }
            else
            {
                radius = _rectangleWidth;
            }

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            _angleSpringleverBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _rectangleWidth,
                                                                             _rectangleHeight, 1f);
            physicsCanvas.AddRectangleToCanvas(_angleSpringleverBody, Colors.White,
                                               new Vector2(_rectangleWidth, _rectangleHeight));

            _rectangleGeom = GeomFactory.Instance.CreateRectangleGeom(physicsSimulator, _angleSpringleverBody,
                                                                      _rectangleWidth, _rectangleHeight);
            _rectangleGeom.FrictionCoefficient = .5f;
            _rectangleGeom.CollisionGroup      = _collisionGroup;

            Vector2 offset = Vector2.Zero;

            switch (_attachPoint)
            {
            case 0:
            {
                offset = new Vector2(-_rectangleWidth / 2f, 0);         //offset to rectangle to left
                break;
            }

            case 1:
            {
                offset = new Vector2(0, -_rectangleHeight / 2f);         //offset to rectangle to top
                break;
            }

            case 2:
            {
                offset = new Vector2(_rectangleWidth / 2f, 0);         //offset to rectangle to right
                break;
            }

            case 3:
            {
                offset = new Vector2(0, _rectangleHeight / 2f);         //offset to rectangle to bottom
                break;
            }
            }

            _angleSpringleverBody.Position = _position - offset;
            Ellipse circle = physicsCanvas.AddCircleToCanvas(null, Colors.White, 20);

            PhysicsCanvas.CenterAround(circle, _position);
            _circleGeom = GeomFactory.Instance.CreateCircleGeom(physicsSimulator, _angleSpringleverBody, radius, 20,
                                                                offset, 0);
            _circleGeom.FrictionCoefficient = .5f;
            _circleGeom.CollisionGroup      = _collisionGroup;

            JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody,
                                                           _position);
            SpringFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody,
                                                          _springConstant, _dampningConstant);
        }
Exemplo n.º 6
0
        public void Load(PhysicsCanvas physicsCanvas, PhysicsSimulator physicsSimulator)
        {
            //Load bodies
            _spiderBody          = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _spiderBodyRadius, 1);
            _spiderBody.Position = _position;
            _spiderBody.IsStatic = false;
            physicsCanvas.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);
            physicsCanvas.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);
            physicsCanvas.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);
            physicsCanvas.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);
            physicsCanvas.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;
        }
Exemplo n.º 7
0
 public void Update()
 {
     PhysicsCanvas.CenterAround(visual, body.Position);
     PhysicsCanvas.SetRotation(visual, Body.Rotation);
 }