Esempio n. 1
0
        public void Load(Demo demo, PhysicsSimulator physicsSimulator)
        {
            agentBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5);
            agentBody.Position = _position;
            demo.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;
        }
Esempio n. 2
0
        public void Load(Demo demo, 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 = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                     new Vector2(borderWidth, height));
            Demo.PositionTopLeft(leftBorder, new Vector2(left, top));

            Rectangle rightBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                     new Vector2(borderWidth, height));
            Demo.PositionTopLeft(rightBorder, new Vector2(right-borderWidth, top));

            Rectangle topBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                     new Vector2(width, borderWidth));
            Demo.PositionTopLeft(topBorder, new Vector2(left, top));

            Rectangle bottomBorder = demo.AddRectangleToCanvas(null, Color.FromArgb(128, 255, 255, 255),
                                                     new Vector2(width, borderWidth));
            Demo.PositionTopLeft(bottomBorder, new Vector2(left, bottom - borderWidth));
        }
        public void Load(Demo demo, PhysicsSimulator physicsSimulator)
        {
            //use the body factory to create the physics body
            _platformBody = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, _width, _height, 1);
            demo.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;
        }
        public void Load(Demo demo, 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);
            demo.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 = demo.AddCircleToCanvas(null, Colors.White, 20);
            Demo.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);
        }
Esempio n. 5
0
        public void Load(Demo demo, PhysicsSimulator physicsSimulator)
        {
            //Load bodies
            _spiderBody = BodyFactory.Instance.CreateCircleBody(physicsSimulator, _spiderBodyRadius, 1);
            _spiderBody.Position = _position;
            _spiderBody.IsStatic = false;
            demo.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);
            demo.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);
            demo.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);
            demo.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);
            demo.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;
        }