Exemplo n.º 1
0
        public override void LoadContent()
        {
            //load texture that will represent the physics body
            _polygonTexture = ScreenManager.ContentManager.Load <Texture2D>("Content/Texture");

            //Create an array to hold the data from the texture
            uint[] data = new uint[_polygonTexture.Width * _polygonTexture.Height];

            //Transfer the texture data to the array
            _polygonTexture.GetData(data);

            //Calculate the vertices from the array
            Vertices verts = Vertices.CreatePolygon(data, _polygonTexture.Width, _polygonTexture.Height);

            //Make sure that the origin of the texture is the centroid (real center of geometry)
            _polygonOrigin = verts.GetCentroid();

            //Use the body factory to create the physics body
            _polygonBody          = BodyFactory.Instance.CreatePolygonBody(PhysicsSimulator, verts, 5);
            _polygonBody.Position = new Vector2(500, 400);

            GeomFactory.Instance.CreatePolygonGeom(PhysicsSimulator, _polygonBody, verts, 0);

            _circleTexture       = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 35, Color.Gold, Color.Black);
            _circleOrigin        = new Vector2(_circleTexture.Width / 2f, _circleTexture.Height / 2f);
            _circleBody          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 35, 1);
            _circleBody.Position = new Vector2(300, 400);

            GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _circleBody, 35, 20);

            base.LoadContent();
        }
Exemplo n.º 2
0
        public override void LoadContent()
        {
            if (_contentManager == null)
            {
                _contentManager = new ContentManager(ScreenManager.Game.Services);
            }
            _lineBrush.Load(ScreenManager.GraphicsDevice);

            _rectangleTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 128, 128, Color.Gold,
                                                                     Color.Black);
            _rectangleOrigin = new Vector2(_rectangleTexture.Width / 2f, _rectangleTexture.Height / 2f);

            _circleTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 64, Color.White,
                                                               Color.Black);
            _circleOrigin = new Vector2(_circleTexture.Width / 2f, _circleTexture.Height / 2f);

            _rectangleBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 128, 128, 1);
            _rectangleBody.Position = new Vector2(256, 384);
            _rectangleGeom          = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _rectangleBody, 128, 128);

            _circleBody          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 64, 1); //fix
            _circleBody.Position = new Vector2(725, 384);
            _circleGeom          = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _circleBody, 64, 20);

            base.LoadContent();
        }
Exemplo n.º 3
0
        public void LoadAgent()
        {
            _agentTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 16, Color.Gold, Color.Black);
            _agentOrigin  = new Vector2(_agentTexture.Width / 2f, _agentTexture.Height / 2f);

            _agentCrossBeamTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 16, 120,
                                                                          Color.DarkGray, Color.Black);
            _agentCrossBeamOrigin = new Vector2(_agentCrossBeamTexture.Width / 2f, _agentCrossBeamTexture.Height / 2f);

            _agentBody          = BodyFactory.Instance.CreateRectangleBody(PhysicsSimulator, 80, 80, 5);
            _agentBody.Position = new Vector2(ScreenManager.ScreenCenter.X, 110);

            _agentGeom    = new Geom[7];
            _agentGeom[0] = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _agentBody, 16, 10,
                                                                  new Vector2(-40, -40), 0);
            _agentGeom[0].RestitutionCoefficient = .2f;
            _agentGeom[0].FrictionCoefficient    = .2f;
            _agentGeom[0].CollisionGroup         = 1;
            _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, 130, Vector2.Zero,
                                                                     MathHelper.PiOver4);
            _agentGeom[5].CollisionGroup = 1;
            _agentGeom[6] = GeomFactory.Instance.CreateRectangleGeom(PhysicsSimulator, _agentBody, 16, 130, Vector2.Zero,
                                                                     -MathHelper.PiOver4);
            _agentGeom[6].CollisionGroup = 1;
        }
Exemplo n.º 4
0
        public override void LoadContent()
        {
            _chainTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 20, 10, Color.White,
                                                                 Color.Black);

            _obstaclesTexture = DrawingHelper.CreateRectangleTexture(ScreenManager.GraphicsDevice, 40, 40, Color.Brown,
                                                                     Color.Black);

            _wheelTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 45, 2, Color.White, Color.Black);

            _chainOrigin     = new Vector2(_chainTexture.Width / 2f, _chainTexture.Height / 2f);
            _wheelOrigin     = new Vector2(_wheelTexture.Width / 2f, _wheelTexture.Height / 2f);
            _obstaclesOrigin = new Vector2(_obstaclesTexture.Width / 2f, _obstaclesTexture.Height / 2f);
            Vector2 center = new Vector2(400, 500);

            _controlPoints = new Vertices();
            _controlPoints.Add(new Vector2(-15, -50) + center);
            _controlPoints.Add(new Vector2(-50, -50) + center);
            _controlPoints.Add(new Vector2(-100, -25) + center);
            _controlPoints.Add(new Vector2(-100, 25) + center);
            _controlPoints.Add(new Vector2(-50, 50) + center);
            _controlPoints.Add(new Vector2(50, 50) + center);
            _controlPoints.Add(new Vector2(100, 25) + center);
            _controlPoints.Add(new Vector2(100, -25) + center);
            _controlPoints.Add(new Vector2(50, -50) + center);
            _controlPoints.Add(new Vector2(-10, -50) + center);

            _track = ComplexFactory.Instance.CreateTrack(PhysicsSimulator, _controlPoints, 20.0f, 10.0f, 3.0f, true, 2, LinkType.RevoluteJoint);

            foreach (Geom g in _track.Geoms)
            {
                g.FrictionCoefficient = 1.0f;
            }

            _wheel1          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel1.Position = new Vector2(-50, 0) + center;
            _wheel2          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 45, 30);
            _wheel2.Position = new Vector2(50, 0) + center;

            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel1, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;
            _wheelg = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _wheel2, 45, 36);
            _wheelg.FrictionCoefficient = 1.0f;

            _spring             = SpringFactory.Instance.CreateLinearSpring(PhysicsSimulator, _wheel1, new Vector2(), _wheel2, new Vector2(), 5200, 3050);
            _spring.RestLength += 20;

            _obstacles  = new GenericList <Body>();
            _obstaclesg = new GenericList <Geom>();

            base.LoadContent();
        }
Exemplo n.º 5
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _agentTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, 16, Color.Gold, Color.Black);
            _agentOrigin  = new Vector2(_agentTexture.Width / 2f, _agentTexture.Height / 2f);

            _agentCrossBeamTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, 16, 120, Color.DarkGray,
                                                                          Color.Black);
            _agentCrossBeamOrigin = new Vector2(_agentCrossBeamTexture.Width / 2f, _agentCrossBeamTexture.Height / 2f);

            _agentBody          = BodyFactory.Instance.CreateRectangleBody(physicsSimulator, 80, 80, 5);
            _agentBody.Position = _position;

            _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.º 6
0
        /// <summary>
        /// LoadContent will be called once per game and is the place to load
        /// all of your content.
        /// </summary>
        protected override void LoadContent()
        {
            spriteFont = Content.Load <SpriteFont>("Font");

            squareTex   = Content.Load <Texture2D>("square");
            botTex      = Content.Load <Texture2D>("magabot_cm");
            gridTex     = Content.Load <Texture2D>("grid");
            obstacleTex = DrawingHelper.CreateCircleTexture(GraphicsDevice, 10, Color.Purple, Color.Black);

            bot      = new TextureSprite(botTex);
            botFrame = new Transform2();
            renderer.SubscribeTexture(botFrame, bot);

            obstacles      = new TextureSprite[proximity.Count];
            obstacleFrames = new Transform2[proximity.Count];
            for (int i = 0; i < obstacles.Length; i++)
            {
                obstacles[i]      = new TextureSprite(obstacleTex);
                obstacleFrames[i] = new Transform2();
                renderer.SubscribeTexture(obstacleFrames[i], obstacles[i]);
            }
            // TODO: use this.Content to load your game content here
        }
Exemplo n.º 7
0
        public void LoadPlatforms()
        {
            //_platform1
            int     width    = Convert.ToInt32(ScreenManager.ScreenWidth * platform1WidthRatio);
            int     height   = Convert.ToInt32(ScreenManager.ScreenHeight * platform1HeightRatio);
            Vector2 position = new Vector2(-5 + width / 2f, 5 + ScreenManager.ScreenHeight - height / 2f);

            _platform1 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100);
            _platform1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _angularSpringLever1                  = new AngularSpringLever();
            _angularSpringLever1.AttachPoint      = 0;
            _angularSpringLever1.RectangleWidth   = 200;
            _angularSpringLever1.RectangleHeight  = 20;
            _angularSpringLever1.SpringConstant   = 1000000;
            _angularSpringLever1.DampningConstant = 5000;
            _angularSpringLever1.CollisionGroup   = 100;
            Vector2 springPosition = position + new Vector2(width / 2f, -height / 2f) +
                                     new Vector2(-_angularSpringLever1.RectangleHeight - 5, .4f * height);

            _angularSpringLever1.Position = springPosition;
            _angularSpringLever1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            //platform 2
            width    = Convert.ToInt32(ScreenManager.ScreenWidth * platform2WidthRatio);
            height   = Convert.ToInt32(ScreenManager.ScreenHeight * platform2HeightRatio);
            position = new Vector2(ScreenManager.ScreenCenter.X, 5 + ScreenManager.ScreenHeight - height / 2f);

            _platform2 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100);
            _platform2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _angularSpringLever2                  = new AngularSpringLever();
            _angularSpringLever2.AttachPoint      = 2;
            _angularSpringLever2.RectangleWidth   = 200;
            _angularSpringLever2.RectangleHeight  = 20;
            _angularSpringLever2.SpringConstant   = 1000000;
            _angularSpringLever2.DampningConstant = 5000;
            _angularSpringLever2.CollisionGroup   = 100;
            springPosition = position + new Vector2(-width / 2f, -height / 2f) +
                             new Vector2(_angularSpringLever2.RectangleHeight + 5, .2f * height);
            _angularSpringLever2.Position = springPosition;
            _angularSpringLever2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _angularSpringLever3                  = new AngularSpringLever();
            _angularSpringLever3.AttachPoint      = 0;
            _angularSpringLever3.RectangleWidth   = 150;
            _angularSpringLever3.RectangleHeight  = 20;
            _angularSpringLever3.SpringConstant   = 10000000;
            _angularSpringLever3.DampningConstant = 1000;
            _angularSpringLever3.CollisionGroup   = 100;
            springPosition = position + new Vector2(width / 2f, -height / 2f) +
                             new Vector2(-_angularSpringLever3.RectangleHeight - 5, .1f * height);
            _angularSpringLever3.Position = springPosition;
            _angularSpringLever3.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _springRectangleRope1                  = new SpringRectangleRope();
            _springRectangleRope1.Position         = springPosition + new Vector2(_angularSpringLever3.RectangleWidth - 5, 25);
            _springRectangleRope1.RectangleCount   = 20;
            _springRectangleRope1.RectangleWidth   = 15;
            _springRectangleRope1.RectangleHeight  = 15;
            _springRectangleRope1.RectangleMass    = .5f;
            _springRectangleRope1.SpringLength     = 15;
            _springRectangleRope1.SpringConstant   = 400;
            _springRectangleRope1.DampningConstant = 3f;
            _springRectangleRope1.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);
            ControllerFactory.Instance.CreateLinearSpring(PhysicsSimulator, _angularSpringLever3.Body,
                                                          new Vector2(
                                                              _angularSpringLever3.RectangleWidth / 2f, 0),
                                                          _springRectangleRope1.FirstBody, Vector2.Zero,
                                                          400, 3);

            //platform 3
            width      = Convert.ToInt32(ScreenManager.ScreenWidth * platform3WidthRatio);
            height     = Convert.ToInt32(ScreenManager.ScreenHeight * platform3HeightRatio);
            position   = new Vector2(ScreenManager.ScreenWidth + 5 - width / 2f, 5 + ScreenManager.ScreenHeight - height / 2f);
            _platform3 = new RectanglePlatform(width, height, position, Color.White, Color.Black, 100);
            _platform3.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _hangingTexture = DrawingHelper.CreateCircleTexture(ScreenManager.GraphicsDevice, 40, Color.White,
                                                                Color.Black);
            _hangingBody          = BodyFactory.Instance.CreateCircleBody(PhysicsSimulator, 40, 1);
            _hangingBody.Position = new Vector2(position.X - 200, 200);
            _hangingGeom          = GeomFactory.Instance.CreateCircleGeom(PhysicsSimulator, _hangingBody, 40, 20);
            ControllerFactory.Instance.CreateFixedLinearSpring(PhysicsSimulator, _hangingBody,
                                                               new Vector2(0, -35),
                                                               new Vector2(position.X - 200, 100),
                                                               2, .1f);

            _angularSpringLever4                  = new AngularSpringLever();
            _angularSpringLever4.AttachPoint      = 2;
            _angularSpringLever4.RectangleWidth   = 200;
            _angularSpringLever4.RectangleHeight  = 20;
            _angularSpringLever4.SpringConstant   = 1000000;
            _angularSpringLever4.DampningConstant = 1000;
            _angularSpringLever4.CollisionGroup   = 100;
            springPosition = position + new Vector2(-width / 2f, -height / 2f) +
                             new Vector2(_angularSpringLever4.RectangleHeight + 5, .7f * height);
            _angularSpringLever4.Position = springPosition;
            _angularSpringLever4.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            height = (int)(ScreenManager.ScreenHeight * .05f);
            _floor = new RectanglePlatform(ScreenManager.ScreenWidth + 10, height,
                                           new Vector2(ScreenManager.ScreenCenter.X,
                                                       ScreenManager.ScreenHeight + 5 - height / 2), Color.White,
                                           Color.Black, 0);
            _floor.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);

            _springRectangleRope2                  = new SpringRectangleRope();
            _springRectangleRope2.Position         = new Vector2(ScreenManager.ScreenCenter.X, 100);
            _springRectangleRope2.RectangleCount   = 20;
            _springRectangleRope2.RectangleWidth   = 10;
            _springRectangleRope2.RectangleHeight  = 10;
            _springRectangleRope2.RectangleMass    = .2f;
            _springRectangleRope2.SpringLength     = 10;
            _springRectangleRope2.SpringConstant   = 200;
            _springRectangleRope2.DampningConstant = 4f;
            _springRectangleRope2.CollisionGroup   = 1; //same as _agent collision group
            _springRectangleRope2.Load(ScreenManager.GraphicsDevice, PhysicsSimulator);
            ControllerFactory.Instance.CreateLinearSpring(PhysicsSimulator, _agent.Body, Vector2.Zero,
                                                          _springRectangleRope2.FirstBody, Vector2.Zero,
                                                          200, 4f);
        }
Exemplo n.º 8
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
            _spiderBody          = BodyFactory.Instance.CreateCircleBody(physicsSimulator, spiderBodyRadius, 1);
            _spiderBody.Position = _position;
            _spiderBody.IsStatic = false;

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

            _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);

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

            _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);

            //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.º 9
0
        public void Load(GraphicsDevice graphicsDevice, PhysicsSimulator physicsSimulator)
        {
            _rectangleTexture = DrawingHelper.CreateRectangleTexture(graphicsDevice, _rectangleWidth, _rectangleHeight,
                                                                     Color.White, Color.Black);
            int radius;

            if (_attachPoint == 0 | _attachPoint == 2)
            {
                radius = _rectangleHeight;
            }
            else
            {
                radius = _rectangleWidth;
            }
            _circleTexture = DrawingHelper.CreateCircleTexture(graphicsDevice, radius, Color.White, Color.Black);

            //body is created as rectangle so that it has the moment of inertia closer to the final shape of the object.
            _angleSpringleverBody = BodyFactory.Instance.CreateBody(physicsSimulator, 1,
                                                                    BodyFactory.MOIForRectangle(_rectangleWidth,
                                                                                                _rectangleHeight, 1f));

            _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;

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

            _revoluteJoint = JointFactory.Instance.CreateFixedRevoluteJoint(physicsSimulator, _angleSpringleverBody,
                                                                            _position);
            physicsSimulator.Add(_revoluteJoint);
            ControllerFactory.Instance.CreateFixedAngleSpring(physicsSimulator, _angleSpringleverBody,
                                                              _springConstant, _dampningConstant);
        }