A revolute joint rains to bodies to share a common point while they are free to rotate about the point. The relative rotation about the shared point is the joint angle. You can limit the relative rotation with a joint limit that specifies a lower and upper angle. You can use a motor to drive the relative rotation about the shared point. A maximum motor torque is provided so that infinite forces are not generated.
Inheritance: Joint
コード例 #1
0
ファイル: JointFactory.cs プロジェクト: HaKDMoDz/Zazumo
 /// <summary>
 /// Creates the fixed revolute joint.
 /// </summary>
 /// <param name="world">The world.</param>
 /// <param name="body">The body.</param>
 /// <param name="bodyAnchor">The body anchor.</param>
 /// <param name="worldAnchor">The world anchor.</param>
 /// <returns></returns>
 public static FixedRevoluteJoint CreateFixedRevoluteJoint(World world, Body body, Vector2 bodyAnchor,
                                                           Vector2 worldAnchor)
 {
     FixedRevoluteJoint fixedRevoluteJoint = new FixedRevoluteJoint(body, bodyAnchor, worldAnchor);
     world.AddJoint(fixedRevoluteJoint);
     return fixedRevoluteJoint;
 }
コード例 #2
0
ファイル: NailTool.cs プロジェクト: guozanhua/KinectRagdoll
        public override void HandleInput()
        {


            InputHelper input = game.inputManager.inputHelper;

            if (input.IsNewButtonPress(MouseButtons.LeftButton))
            {
                Vector2 position = ProjectionHelper.PixelToFarseer(input.MousePosition);



                List<Fixture> list = game.farseerManager.world.TestPointAll(position);

                if (list.Count > 0)
                {
                    FixedRevoluteJoint j = new FixedRevoluteJoint(list[0].Body, list[0].Body.GetLocalPoint(position), position);

                    game.farseerManager.world.AddJoint(j);

                    FormManager.Property.setSelectedObject(j);
                }
            }
            
        }
コード例 #3
0
 public RotatingPlatform(Game game, World world, string image, Vector2 position, float angle, float density)
     : base(game, world,image, position, angle, density, BodyType.Dynamic)
 {
     joint = JointFactory.CreateFixedRevoluteJoint(World, Body, Vector2.Zero, Body.WorldCenter);
     //joint.MotorSpeed = 5;
     //joint.MotorEnabled = true;
     //joint.MotorTorque = 50;
     //joint.MaxMotorTorque = 100;
 }
コード例 #4
0
ファイル: RevoluteTest.cs プロジェクト: danzel/FarseerPhysics
        private RevoluteTest()
        {
            //Ground
            var ground = BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                //The big fixed wheel
                CircleShape shape = new CircleShape(5.0f, 5);

                Body body = BodyFactory.CreateBody(World);
                body.Position = new Vector2(-10.0f, 15.0f);
                body.BodyType = BodyType.Dynamic;

                body.CreateFixture(shape);

                _fixedJoint = new FixedRevoluteJoint(body, Vector2.Zero, body.Position);
                _fixedJoint.MotorSpeed = 0.25f * Settings.Pi;
                _fixedJoint.MaxMotorTorque = 5000.0f;
                _fixedJoint.MotorEnabled = true;
                World.AddJoint(_fixedJoint);

                // The small gear attached to the big one
                Body body1 = BodyFactory.CreateGear(World, 1.5f, 10, 0.1f, 1, 1);
                body1.Position = new Vector2(-10.0f, 12.0f);
                body1.BodyType = BodyType.Dynamic;

                _joint = new RevoluteJoint(body, body1, body.GetLocalPoint(body1.Position),
                                           Vector2.Zero);
                _joint.MotorSpeed = 1.0f * Settings.Pi;
                _joint.MaxMotorTorque = 5000.0f;
                _joint.MotorEnabled = true;
                _joint.CollideConnected = false;

                World.AddJoint(_joint);

                CircleShape circle_shape = new CircleShape(3.0f, 5);
                var circleBody = BodyFactory.CreateBody(World);
                circleBody.Position = new Vector2(5.0f, 30.0f);
                circleBody.BodyType = BodyType.Dynamic;
                circleBody.CreateFixture(circle_shape);
                PolygonShape polygonShape = new PolygonShape(2.0f);
                polygonShape.SetAsBox(10.0f, 0.2f, new Vector2(-10.0f, 0.0f), 0.0f);
                var polygon_body = BodyFactory.CreateBody(World);
                polygon_body.Position = new Vector2(20.0f, 10.0f);
                polygon_body.BodyType = BodyType.Dynamic;
                polygon_body.IsBullet = true;
                polygon_body.CreateFixture(polygonShape);
                RevoluteJoint rjd = new RevoluteJoint(ground, polygon_body, new Vector2(20.0f, 10.0f));
                rjd.LowerLimit = -0.25f * Settings.Pi;
                rjd.UpperLimit = 0.0f;
                rjd.LimitEnabled = true;
                World.AddJoint(rjd);
            }
        }
コード例 #5
0
ファイル: BigWheel.cs プロジェクト: dreasgrech/FPE3Sandbox
        public BigWheel(Game game, World world, Vector2 position)
        {
            var texture = new TexturedGameEntity(game, position, 0, "Images/bigWheel", 1);
            var body = BodyFactory.CreateCircle(world, ConvertUnits.ToSimUnits(texture.Width/2), 1f);
            body.BodyType = BodyType.Dynamic;
            wheel = new TexturedPhysicsEntity(game, world, Category.Cat31, texture, body, new Vector2(texture.Width/2f, texture.Height/2f));

            revJoint = JointFactory.CreateFixedRevoluteJoint(world, wheel.Body, Vector2.Zero, ConvertUnits.ToSimUnits(wheel.Position));
            revJoint.MotorEnabled = true;
            revJoint.MotorSpeed = 3000;
            /*revJoint.MaxMotorTorque = 3000;
            revJoint.LimitEnabled = true;
            revJoint.UpperLimit = 3000;*/
        }
コード例 #6
0
ファイル: GearsTest.cs プロジェクト: danzel/FarseerPhysics
        private GearsTest()
        {
            {
                // First circle
                CircleShape circle1 = new CircleShape(1.0f, 5);
                Body body1 = BodyFactory.CreateBody(World);
                body1.BodyType = BodyType.Dynamic;
                body1.Position = new Vector2(-3.0f, 12.0f);
                body1.CreateFixture(circle1);

                // Second circle
                CircleShape circle2 = new CircleShape(2.0f, 5);
                Body body2 = BodyFactory.CreateBody(World);
                body2.BodyType = BodyType.Dynamic;
                body2.Position = new Vector2(0.0f, 12.0f);
                body2.CreateFixture(circle2);

                // Rectangle
                Vertices box = PolygonTools.CreateRectangle(0.5f, 5.0f);
                PolygonShape polygonBox = new PolygonShape(box, 5);
                Body body3 = BodyFactory.CreateBody(World);
                body3.BodyType = BodyType.Dynamic;
                body3.Position = new Vector2(2.5f, 12.0f);
                body3.CreateFixture(polygonBox);

                // Fix first circle
                _joint1 = new FixedRevoluteJoint(body1, Vector2.Zero, body1.Position);
                World.AddJoint(_joint1);

                // Fix second circle
                _joint2 = new FixedRevoluteJoint(body2, Vector2.Zero, body2.Position);
                World.AddJoint(_joint2);

                // Fix rectangle
                _joint3 = new FixedPrismaticJoint(body3, body3.Position, new Vector2(0.0f, 1.0f));
                _joint3.LowerLimit = -5.0f;
                _joint3.UpperLimit = 5.0f;
                _joint3.LimitEnabled = true;
                World.AddJoint(_joint3);

                // Attach first and second circle together with a gear joint
                _joint4 = new GearJoint(_joint1, _joint2, circle2.Radius / circle1.Radius);
                World.AddJoint(_joint4);

                // Attach second and rectangle together with a gear joint
                _joint5 = new GearJoint(_joint2, _joint3, -1.0f / circle2.Radius);
                World.AddJoint(_joint5);
            }
        }
コード例 #7
0
        private ChainTest()
        {
            //Ground
            FixtureFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            //Chain start / end
            Path path = new Path();
            path.Add(new Vector2(0, 25));
            path.Add(new Vector2(40, 25));

            //A single chainlink
            PolygonShape shape = new PolygonShape(PolygonTools.CreateRectangle(0.125f, 0.6f), 20);

            //Use PathFactory to create all the chainlinks based on the chainlink created before.
            List<Body> chainLinks = PathManager.EvenlyDistributeShapesAlongPath(World, path, shape, BodyType.Dynamic, 30);

            foreach (Body chainLink in chainLinks)
            {
                foreach (Fixture f in chainLink.FixtureList)
                {
                    f.Friction = 0.2f;
                }
            }

            //Fix the first chainlink to the world
            FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(chainLinks[0], Vector2.Zero, chainLinks[0].Position);
            World.AddJoint(fixedJoint);

            //Attach all the chainlinks together with a revolute joint
            List<RevoluteJoint> joints = PathManager.AttachBodiesWithRevoluteJoint(World, chainLinks,
                                                                                   new Vector2(0, -0.6f),
                                                                                   new Vector2(0, 0.6f),
                                                                                   false, false);

            //The chain is breakable
            for (int i = 0; i < joints.Count; i++)
            {
                RevoluteJoint r = joints[i];
                r.Breakpoint = 10000f;
            }
        }
コード例 #8
0
ファイル: JointForm.cs プロジェクト: guozanhua/KinectRagdoll
        public override Object PlacePhysicsObject(Microsoft.Xna.Framework.Vector2 position, FarseerPhysics.Dynamics.World world)
        {
            List<Fixture> list = world.TestPointAll(position);


            if (pin.Checked && list.Count > 0)
            {
                FixedRevoluteJoint j = new FixedRevoluteJoint(list[0].Body, list[0].Body.GetLocalPoint(position), position);
                if (motorEnabled.Checked)
                {
                    j.MotorEnabled = true;
                    float speed;
                    float maxTorque;
                    if (float.TryParse(motorSpeed.Text, out speed)) j.MotorSpeed = speed;
                    if (float.TryParse(motorTorque.Text, out maxTorque)) j.MaxMotorTorque = maxTorque;
                }

                world.AddJoint(j);
                return j;
            }
            
            if (list.Count > 1)
            {
                RevoluteJoint j = new RevoluteJoint(list[0].Body, list[1].Body, list[0].Body.GetLocalPoint(position), list[1].Body.GetLocalPoint(position));
                if (motorEnabled.Checked)
                {
                    j.MotorEnabled = true;
                    float speed;
                    float maxTorque;
                    if (float.TryParse(motorSpeed.Text, out speed)) j.MotorSpeed = speed;
                    if (float.TryParse(motorTorque.Text, out maxTorque)) j.MaxMotorTorque = maxTorque;
                }
                world.AddJoint(j);
                return j;
            }

            return base.PlacePhysicsObject(position, world);
        }
コード例 #9
0
        private RevoluteTest()
        {
            //Ground
            FixtureFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                //The big fixed wheel
                CircleShape shape = new CircleShape(5.0f, 5);

                Body body = BodyFactory.CreateBody(World);
                body.Position = new Vector2(0.0f, 15.0f);
                body.BodyType = BodyType.Dynamic;

                body.CreateFixture(shape);

                _fixedJoint = new FixedRevoluteJoint(body, Vector2.Zero, body.Position);
                _fixedJoint.MotorSpeed = 0.25f*Settings.Pi;
                _fixedJoint.MaxMotorTorque = 5000.0f;
                _fixedJoint.MotorEnabled = true;
                World.AddJoint(_fixedJoint);

                // The small gear attached to the big one
                List<Fixture> fixtures = FixtureFactory.CreateGear(World, 1.5f, 10, 0.1f, 1, 1);
                fixtures[0].Body.Position = new Vector2(0.0f, 12.0f);
                fixtures[0].Body.BodyType = BodyType.Dynamic;

                _joint = new RevoluteJoint(body, fixtures[0].Body, body.GetLocalPoint(fixtures[0].Body.Position),
                                           Vector2.Zero);
                _joint.MotorSpeed = 1.0f*Settings.Pi;
                _joint.MaxMotorTorque = 5000.0f;
                _joint.MotorEnabled = true;
                _joint.CollideConnected = false;

                World.AddJoint(_joint);
            }
        }
コード例 #10
0
        public static Joint CopyJoint(Joint joint, Body bodyA, Body bodyB, World world)
        {
            Joint newJoint = null;

            switch (joint.JointType)
            {
                case JointType.Angle:
                    newJoint = JointFactory.CreateAngleJoint(world, bodyA, bodyB);
                    break;
                case JointType.Distance:
                    newJoint = new DistanceJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter);
                    break;
                case JointType.FixedAngle:
                    newJoint = new FixedAngleJoint(bodyA);
                    break;
                case JointType.FixedDistance:
                    newJoint = new FixedDistanceJoint(bodyA, bodyA.WorldCenter, Vector2.Zero);
                    break;
                case JointType.FixedFriction:
                    newJoint = new FixedFrictionJoint(bodyA, bodyA.WorldCenter);
                    break;
                case JointType.FixedPrismatic:
                    var fpJoint = joint as FixedPrismaticJoint;
                    var fpAxis = fpJoint.LocalXAxis1;
                    newJoint = new FixedPrismaticJoint(bodyA, bodyA.WorldCenter, fpAxis);
                    break;
                case JointType.FixedRevolute:
                    newJoint = new FixedRevoluteJoint(bodyA, bodyA.WorldCenter, Vector2.Zero);
                    break;
                case JointType.Friction:
                    newJoint = new FrictionJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter);
                    break;
                case JointType.Line:
                    var lineJoint = joint as LineJoint;
                    var axis = lineJoint.LocalXAxis;
                    newJoint = new LineJoint(bodyA, bodyB, bodyA.WorldCenter, axis);
                    break;
                case JointType.Prismatic:
                    var pJoint = joint as PrismaticJoint;
                    var pAxis = pJoint.LocalXAxis1;
                    newJoint = new PrismaticJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter, pAxis);
                    ((PrismaticJoint)newJoint).LimitEnabled = pJoint.LimitEnabled;
                    ((PrismaticJoint)newJoint).MotorEnabled = pJoint.MotorEnabled;
                    ((PrismaticJoint)newJoint).MaxMotorForce = pJoint.MaxMotorForce;
                    ((PrismaticJoint)newJoint).MotorSpeed = pJoint.MotorSpeed;
                    ((PrismaticJoint)newJoint).LowerLimit = pJoint.LowerLimit;
                    ((PrismaticJoint)newJoint).UpperLimit = pJoint.UpperLimit;
                    ((PrismaticJoint)newJoint).ReferenceAngle = pJoint.ReferenceAngle;
                    ((PrismaticJoint)newJoint).LocalXAxis1 = pJoint.LocalXAxis1;
                    break;
                case JointType.Pulley:
                    var pulleyJoint = joint as PulleyJoint;
                    var ratio = pulleyJoint.Ratio;
                    newJoint = new PulleyJoint(bodyA, bodyB, Vector2.Zero, Vector2.Zero, bodyA.WorldCenter, bodyB.WorldCenter, ratio);
                    break;
                case JointType.Revolute:
                    newJoint = new RevoluteJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter);
                    break;
                case JointType.Slider:
                    var sliderJoint = joint as SliderJoint;
                    var minLength = sliderJoint.MinLength;
                    var maxLength = sliderJoint.MaxLength;
                    newJoint = new SliderJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter, minLength, maxLength);
                    break;
                case JointType.Weld:
                    newJoint = new WeldJoint(bodyA, bodyB, bodyA.WorldCenter, bodyB.WorldCenter);
                    break;
            }

            var data = new FarseerJointUserData();
            data.BodyAName = ((FarseerJointUserData) joint.UserData).BodyAName;
            data.BodyBName = ((FarseerJointUserData) joint.UserData).BodyBName;

            joint.UserData = data;

            return newJoint;
        }
コード例 #11
0
ファイル: GearJoint.cs プロジェクト: jwmcglynn/float
        /// <summary>
        /// Requires two existing revolute or prismatic joints (any combination will work).
        /// The provided joints must attach a dynamic body to a static body.
        /// </summary>
        /// <param name="jointA">The first joint.</param>
        /// <param name="jointB">The second joint.</param>
        /// <param name="ratio">The ratio.</param>
        public GearJoint(Joint jointA, Joint jointB, float ratio)
            : base(jointA.BodyA, jointA.BodyB)
        {
            JointType = JointType.Gear;
            JointA    = jointA;
            JointB    = jointB;
            Ratio     = ratio;

            JointType type1 = jointA.JointType;
            JointType type2 = jointB.JointType;

            // Make sure its the right kind of joint
            Debug.Assert(type1 == JointType.Revolute ||
                         type1 == JointType.Prismatic ||
                         type1 == JointType.FixedRevolute ||
                         type1 == JointType.FixedPrismatic);
            Debug.Assert(type2 == JointType.Revolute ||
                         type2 == JointType.Prismatic ||
                         type2 == JointType.FixedRevolute ||
                         type2 == JointType.FixedPrismatic);

            // In the case of a prismatic and revolute joint, the first body must be static.
            if (type1 == JointType.Revolute || type1 == JointType.Prismatic)
            {
                Debug.Assert(jointA.BodyA.Type == BodyType.Static);
            }
            if (type2 == JointType.Revolute || type2 == JointType.Prismatic)
            {
                Debug.Assert(jointB.BodyA.Type == BodyType.Static);
            }

            float coordinate1 = 0.0f, coordinate2 = 0.0f;

            switch (type1)
            {
            case JointType.Revolute:
                BodyA        = jointA.BodyB;
                _revolute1   = (RevoluteJoint)jointA;
                LocalAnchor1 = _revolute1.LocalAnchorB;
                coordinate1  = _revolute1.JointAngle;
                break;

            case JointType.Prismatic:
                BodyA        = jointA.BodyB;
                _prismatic1  = (PrismaticJoint)jointA;
                LocalAnchor1 = _prismatic1.LocalAnchorB;
                coordinate1  = _prismatic1.JointTranslation;
                break;

            case JointType.FixedRevolute:
                BodyA           = jointA.BodyA;
                _fixedRevolute1 = (FixedRevoluteJoint)jointA;
                LocalAnchor1    = _fixedRevolute1.LocalAnchorA;
                coordinate1     = _fixedRevolute1.JointAngle;
                break;

            case JointType.FixedPrismatic:
                BodyA            = jointA.BodyA;
                _fixedPrismatic1 = (FixedPrismaticJoint)jointA;
                LocalAnchor1     = _fixedPrismatic1.LocalAnchorA;
                coordinate1      = _fixedPrismatic1.JointTranslation;
                break;
            }

            switch (type2)
            {
            case JointType.Revolute:
                BodyB        = jointB.BodyB;
                _revolute2   = (RevoluteJoint)jointB;
                LocalAnchor2 = _revolute2.LocalAnchorB;
                coordinate2  = _revolute2.JointAngle;
                break;

            case JointType.Prismatic:
                BodyB        = jointB.BodyB;
                _prismatic2  = (PrismaticJoint)jointB;
                LocalAnchor2 = _prismatic2.LocalAnchorB;
                coordinate2  = _prismatic2.JointTranslation;
                break;

            case JointType.FixedRevolute:
                BodyB           = jointB.BodyA;
                _fixedRevolute2 = (FixedRevoluteJoint)jointB;
                LocalAnchor2    = _fixedRevolute2.LocalAnchorA;
                coordinate2     = _fixedRevolute2.JointAngle;
                break;

            case JointType.FixedPrismatic:
                BodyB            = jointB.BodyA;
                _fixedPrismatic2 = (FixedPrismaticJoint)jointB;
                LocalAnchor2     = _fixedPrismatic2.LocalAnchorA;
                coordinate2      = _fixedPrismatic2.JointTranslation;
                break;
            }

            _ant = coordinate1 + Ratio * coordinate2;
        }
コード例 #12
0
ファイル: GearJoint.cs プロジェクト: Karunp/cocos2d-xna
        /// <summary>
        /// Requires two existing revolute or prismatic joints (any combination will work).
        /// The provided joints must attach a dynamic body to a static body.
        /// </summary>
        /// <param name="jointA">The first joint.</param>
        /// <param name="jointB">The second joint.</param>
        /// <param name="ratio">The ratio.</param>
        public GearJoint(Joint jointA, Joint jointB, float ratio)
            : base(jointA.BodyA, jointA.BodyB)
        {
            JointType = JointType.Gear;
            JointA = jointA;
            JointB = jointB;
            Ratio = ratio;

            JointType type1 = jointA.JointType;
            JointType type2 = jointB.JointType;

            // Make sure its the right kind of joint
            Debug.Assert(type1 == JointType.Revolute ||
                         type1 == JointType.Prismatic ||
                         type1 == JointType.FixedRevolute ||
                         type1 == JointType.FixedPrismatic);
            Debug.Assert(type2 == JointType.Revolute ||
                         type2 == JointType.Prismatic ||
                         type2 == JointType.FixedRevolute ||
                         type2 == JointType.FixedPrismatic);

            // In the case of a prismatic and revolute joint, the first body must be static.
            if (type1 == JointType.Revolute || type1 == JointType.Prismatic)
                Debug.Assert(jointA.BodyA.BodyType == BodyType.Static);
            if (type2 == JointType.Revolute || type2 == JointType.Prismatic)
                Debug.Assert(jointB.BodyA.BodyType == BodyType.Static);

            float coordinate1 = 0.0f, coordinate2 = 0.0f;

            switch (type1)
            {
                case JointType.Revolute:
                    BodyA = jointA.BodyB;
                    _revolute1 = (RevoluteJoint)jointA;
                    LocalAnchor1 = _revolute1.LocalAnchorB;
                    coordinate1 = _revolute1.JointAngle;
                    break;
                case JointType.Prismatic:
                    BodyA = jointA.BodyB;
                    _prismatic1 = (PrismaticJoint)jointA;
                    LocalAnchor1 = _prismatic1.LocalAnchorB;
                    coordinate1 = _prismatic1.JointTranslation;
                    break;
                case JointType.FixedRevolute:
                    BodyA = jointA.BodyA;
                    _fixedRevolute1 = (FixedRevoluteJoint)jointA;
                    LocalAnchor1 = _fixedRevolute1.LocalAnchorA;
                    coordinate1 = _fixedRevolute1.JointAngle;
                    break;
                case JointType.FixedPrismatic:
                    BodyA = jointA.BodyA;
                    _fixedPrismatic1 = (FixedPrismaticJoint)jointA;
                    LocalAnchor1 = _fixedPrismatic1.LocalAnchorA;
                    coordinate1 = _fixedPrismatic1.JointTranslation;
                    break;
            }

            switch (type2)
            {
                case JointType.Revolute:
                    BodyB = jointB.BodyB;
                    _revolute2 = (RevoluteJoint)jointB;
                    LocalAnchor2 = _revolute2.LocalAnchorB;
                    coordinate2 = _revolute2.JointAngle;
                    break;
                case JointType.Prismatic:
                    BodyB = jointB.BodyB;
                    _prismatic2 = (PrismaticJoint)jointB;
                    LocalAnchor2 = _prismatic2.LocalAnchorB;
                    coordinate2 = _prismatic2.JointTranslation;
                    break;
                case JointType.FixedRevolute:
                    BodyB = jointB.BodyA;
                    _fixedRevolute2 = (FixedRevoluteJoint)jointB;
                    LocalAnchor2 = _fixedRevolute2.LocalAnchorA;
                    coordinate2 = _fixedRevolute2.JointAngle;
                    break;
                case JointType.FixedPrismatic:
                    BodyB = jointB.BodyA;
                    _fixedPrismatic2 = (FixedPrismaticJoint)jointB;
                    LocalAnchor2 = _fixedPrismatic2.LocalAnchorA;
                    coordinate2 = _fixedPrismatic2.JointTranslation;
                    break;
            }

            _ant = coordinate1 + Ratio * coordinate2;
        }
コード例 #13
0
ファイル: GameplayScreen.cs プロジェクト: hvp/Squareosity
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                gameFont = content.Load<SpriteFont>("gamefont");
                Song = content.Load<Song>("Audio/Soundtrack/Mr_Spastic_-_b3ta_B1t3r");
                if (MediaPlayer.State != MediaState.Paused)
                {

                    MediaPlayer.Volume = 0.75f;
                    MediaPlayer.Play(Song);
                    MediaPlayer.IsRepeating = true;

                }
                else
                {
                    MediaPlayer.Resume();
                }

                bloom = new BloomComponent(ScreenManager.Game);

                for (int k = 0; k < ScreenManager.Game.Components.Count; ++k)
                {
                    if(ScreenManager.Game.Components[k].Equals(bloom))
                    {
                        ScreenManager.Game.Components.RemoveAt(k);
                    }

                }
               //
                 ScreenManager.Game.Components.Add(bloom);
                playerBody = new PlayerBody(content.Load<Texture2D>("redPlayer"), world,content);
                cam2D = new Cam2d(ScreenManager.GraphicsDevice);
               reticle = content.Load<Texture2D>("redReticle");
                // neon whip wheel
                {
                    // instantiate the cirlce body
                    circleBody = BodyFactory.CreateCircle(world, 20.0f / 64, 1f, new Vector2(1000f / 64f, 1000f / 64f));
                    circleBody.BodyType = BodyType.Static;
                    circleBody.CollisionCategories = Category.Cat2;
                    circleBody.BodyId = 11;
                    circleTex = content.Load<Texture2D>("orangeCircle");

                    // fix the circle to the world

                    FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(circleBody, Vector2.Zero, circleBody.Position);
                    world.AddJoint(fixedJoint);

                    // create the whips
                    Whips.Add(new Whip(content.Load<Texture2D>("orangeChianLinkSmall"), new Vector2(1000, 1000), new Vector2(1350, 1000f), world));
                    Whips.Add(new Whip(content.Load<Texture2D>("orangeChianLinkSmall"), new Vector2(1000, 1000), new Vector2(650, 1000), world));
                    //    Whips.Add(new Whip(content.Load<Texture2D>("orangeChianLinkSmall"), new Vector2(1000, 1000), new Vector2(1000, 1350), world));

                    for (int k = 0; k < Whips.Count; k++)
                    {

                        world.AddJoint(new FixedRevoluteJoint(Whips[k].chainLinks[k], Vector2.Zero, circleBody.Position));
                    }

                }

                // add badies
                {
                    Badies.Add(new Bady(content.Load<Texture2D>("Badies/orangeBady"), new Vector2(-1, -2), 15, true, 180f, content, world));
                    Badies.Add(new Bady(content.Load<Texture2D>("Badies/pinkBady"), new Vector2(-3, 0.5f), 8, false, 90f, content, world));
                }

                // add some squares and some walls
                {
                    int space = 0;

                    for (int i = 0; i < 10; i++)
                    {
                        Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space - 5, 0), true, world));
                        Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space - 5, 600), true, world));

                        Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space, 100), world));
                        Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space + 50, 200), world));

                        Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space, 300), world));
                        Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space + 50, 400), world));

                        Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space, 500), world));

                        if (i <= 5)
                        {
                            //vertical walls
                            Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(-50, space + 50), false, world));
                            Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(1050, space + 50), false, world));
                        }

                        space += 100;

                    }
                    Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space , 100), world));

                    Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space, 300), world));

                    Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(space , 500), world));

                    // extra wall
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space + 5, 0), true, world));
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space - 10, 0), true, world));

                    // Ninja gate
                    {
                        ninjaGate = new Shape(content.Load<Texture2D>("NinjaWeapons/blueNinjaWheel"),new Vector2((space - 5), 600f),false,false,world);
                        Shapes.Add(ninjaGate);
                        Shapes[0].shapeBody.AngularVelocity = 10f;
                      //  Shapes.Add(new Shape(content.Load<Texture2D>("NinjaWeapons/blueNinjaWheel"),new Vector2((space - 5), 600f),false,world));
                        world.AddJoint(new FixedRevoluteJoint(Shapes[0].shapeBody, Vector2.Zero, Shapes[0].shapeBody.Position));

                    }

                }

                //add collectables
                {
                    Collectables.Add(new Collectable(content.Load<Texture2D>("redStar"), new Vector2(0, 25), world));
                    Collectables.Add(new Collectable(content.Load<Texture2D>("redStar"), new Vector2(900, 25), world));
                    Collectables.Add(new Collectable(content.Load<Texture2D>("redStar"), new Vector2(900, 625), world));
                }

                // set cam track

                cam2D.TrackingBody = playerBody.playerBody;
                cam2D.EnableTracking = true;

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();
            }
        }
コード例 #14
0
ファイル: level3Screen.cs プロジェクト: kyung01/Squareosity
        /// <summary>
        /// Load graphics content for the game.
        /// </summary>
        public override void Activate(bool instancePreserved)
        {
            if (!instancePreserved)
            {
                if (content == null)
                    content = new ContentManager(ScreenManager.Game.Services, "Content");

                gameFont = content.Load<SpriteFont>("gamefont");

                bloom = new BloomComponent(ScreenManager.Game);
                ScreenManager.Game.Components.Add(bloom);

                cam2D = new Cam2d(ScreenManager.GraphicsDevice);
                reticle = content.Load<Texture2D>("redReticle");
                /// player
                playerBody = new PlayerBody(content.Load<Texture2D>("redPlayer"), world, content);
                playerBody.setPostion = new Vector2(900, 100);

                Squares.Add(new Square(content.Load<Texture2D>("Squares/greenSquare"), new Vector2(-28, 200 ), world));
                //spinning wheel.
                {
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(-5, 250), false, world));

                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(-5, 350), false, world));

                    // filler
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(205, 360), false, world));

                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(205, 250), false, world));
                    // filler
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(205, 240), false, world));

                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(205, 350), false, world));

                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(160, 190), true, world));

                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(160, 410), true, world));

                    spinningWheel = new Shape(content.Load<Texture2D>("Shapes/orangeSpinningWheel"), new Vector2(100, 300), true,false, world);

                    FixedRevoluteJoint fixedJoint = new FixedRevoluteJoint(spinningWheel.shapeBody, Vector2.Zero, spinningWheel.shapeBody.Position);
                    world.AddJoint(fixedJoint);
                }

                int space = 0;

                int k = 260;
                for (; k < 1000; k += 100)
                {
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(k, 190), true, world));
                }

                Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(k - 65, 190), true, world));

                for (int i = 0; i < 11; i++)
                {
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space - 5, 0), true, world));
                    Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(space - 5, 600), true, world));

                    if (i <= 5)
                    {
                        //vertical walls
                        Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(-50, space + 50), false, world));
                        Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(1050, space + 50), false, world));
                    }

                    space += 100;
                }

                Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(1050, 45), false, world));
                Walls.Add(new Wall(content.Load<Texture2D>("Walls/blueWallMedium"), new Vector2(1050, 555), false, world));

                // set cam track

                cam2D.TrackingBody = playerBody.playerBody;
                cam2D.EnableTracking = true;

                // once the load has finished, we use ResetElapsedTime to tell the game's
                // timing mechanism that we have just finished a very long frame, and that
                // it should not try to catch up.
                ScreenManager.Game.ResetElapsedTime();
            }

            base.Activate(instancePreserved);
        }
コード例 #15
0
        public void addSpinningDeath()
        {

            Body b = new Body(world);
            Fixture rec = FixtureFactory.AttachRectangle(20, 2, 1, Vector2.Zero, b);
            b.Position = new Vector2(10, 0);
            
            rec.Body.BodyType = BodyType.Dynamic;
            FarseerTextures.ApplyTexture(rec, FarseerTextures.TextureType.Normal);

            FixedRevoluteJoint joint = new FixedRevoluteJoint(rec.Body, Vector2.Zero, new Vector2(20, 0));
            joint.MotorEnabled = true;
            joint.MotorSpeed = 6;
            joint.MaxMotorTorque = 10000;
            joint.MotorTorque = 10000;
            world.AddJoint(joint);
        }
コード例 #16
0
ファイル: Obstacle.cs プロジェクト: zfogg/Bounce
        private void initializeJoints()
        {
            fRevoluteJoint = JointFactory.CreateFixedRevoluteJoint(scene.World, Body, Body.LocalCenter, Body.Position);
            fRevoluteJoint.MaxMotorTorque = 20f;
            fRevoluteJoint.MotorSpeed = 0f;
            fRevoluteJoint.MotorTorque = 10f;
            fRevoluteJoint.MotorEnabled = false;

            fAngleJoint = JointFactory.CreateFixedAngleJoint(scene.World, Body);
            fAngleJoint.TargetAngle = 0f;
            fAngleJoint.MaxImpulse = 5f;
            fAngleJoint.BiasFactor = 2f;
            fAngleJoint.Softness = .72f;
        }
コード例 #17
0
ファイル: DominosTest.cs プロジェクト: danzel/FarseerPhysics
        private DominosTest()
        {
            //Ground
            BodyFactory.CreateEdge(World, new Vector2(-40.0f, 0.0f), new Vector2(40.0f, 0.0f));

            {
                Vertices box = PolygonTools.CreateRectangle(6.0f, 0.25f);
                PolygonShape shape = new PolygonShape(box, 0);

                Body ground = BodyFactory.CreateBody(World);
                ground.Position = new Vector2(-1.5f, 10.0f);

                ground.CreateFixture(shape);
            }

            {
                Vertices box = PolygonTools.CreateRectangle(0.1f, 1.0f);
                PolygonShape shape = new PolygonShape(box, 20);

                for (int i = 0; i < 10; ++i)
                {
                    Body body = BodyFactory.CreateBody(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(-6.0f + 1.0f * i, 11.25f);

                    Fixture fixture = body.CreateFixture(shape);
                    fixture.Friction = 0.1f;
                }
            }

            {
                Vertices box = PolygonTools.CreateRectangle(7.0f, 0.25f, Vector2.Zero, 0.3f);
                PolygonShape shape = new PolygonShape(box, 0);

                Body ground = BodyFactory.CreateBody(World);
                ground.Position = new Vector2(1.0f, 6.0f);

                ground.CreateFixture(shape);
            }

            Body b2;
            {
                Vertices box = PolygonTools.CreateRectangle(0.25f, 1.5f);
                PolygonShape shape = new PolygonShape(box, 0);

                b2 = BodyFactory.CreateBody(World);
                b2.Position = new Vector2(-7.0f, 4.0f);

                b2.CreateFixture(shape);
            }

            Body b3;
            {
                Vertices box = PolygonTools.CreateRectangle(6.0f, 0.125f);
                PolygonShape shape = new PolygonShape(box, 10);

                b3 = BodyFactory.CreateBody(World);
                b3.BodyType = BodyType.Dynamic;
                b3.Position = new Vector2(-0.9f, 1.0f);
                b3.Rotation = -0.15f;

                b3.CreateFixture(shape);
            }

            Vector2 anchor = new Vector2(-2.0f, 1.0f);
            FixedRevoluteJoint jd = new FixedRevoluteJoint(b3, b3.GetLocalPoint(anchor), anchor);
            jd.CollideConnected = true;
            World.AddJoint(jd);

            Body b4;
            {
                Vertices box = PolygonTools.CreateRectangle(0.25f, 0.25f);
                PolygonShape shape = new PolygonShape(box, 10);

                b4 = BodyFactory.CreateBody(World);
                b4.BodyType = BodyType.Dynamic;
                b4.Position = new Vector2(-10.0f, 15.0f);

                b4.CreateFixture(shape);
            }

            anchor = new Vector2(-7.0f, 15.0f);
            FixedRevoluteJoint jd2 = new FixedRevoluteJoint(b4, b4.GetLocalPoint(anchor), anchor);
            World.AddJoint(jd2);

            Body b5;
            {
                b5 = BodyFactory.CreateBody(World);
                b5.BodyType = BodyType.Dynamic;
                b5.Position = new Vector2(6.5f, 3.0f);

                Vertices vertices = PolygonTools.CreateRectangle(1.0f, 0.1f, new Vector2(0.0f, -0.9f), 0.0f);
                PolygonShape shape = new PolygonShape(vertices, 10);

                Fixture fix = b5.CreateFixture(shape);
                fix.Friction = 0.1f;

                vertices = PolygonTools.CreateRectangle(0.1f, 1.0f, new Vector2(-0.9f, 0.0f), 0.0f);

                shape.Set(vertices);
                fix = b5.CreateFixture(shape);
                fix.Friction = 0.1f;

                vertices = PolygonTools.CreateRectangle(0.1f, 1.0f, new Vector2(0.9f, 0.0f), 0.0f);

                shape.Set(vertices);
                fix = b5.CreateFixture(shape);
                fix.Friction = 0.1f;
            }

            anchor = new Vector2(6.0f, 2.0f);
            FixedRevoluteJoint jd3 = new FixedRevoluteJoint(b5, b5.GetLocalPoint(anchor), anchor);
            World.AddJoint(jd3);

            Body b6;
            {
                Vertices box = PolygonTools.CreateRectangle(1.0f, 0.1f);
                PolygonShape shape = new PolygonShape(box, 30);

                b6 = BodyFactory.CreateBody(World);
                b6.BodyType = BodyType.Dynamic;
                b6.Position = new Vector2(6.5f, 4.1f);

                b6.CreateFixture(shape);
            }

            anchor = new Vector2(1.0f, -0.1f);
            RevoluteJoint jd4 = new RevoluteJoint(b5, b6, b5.GetLocalPoint(b6.GetWorldPoint(anchor)), anchor);
            jd4.CollideConnected = true;
            World.AddJoint(jd4);

            Body b7;
            {
                Vertices box = PolygonTools.CreateRectangle(0.1f, 1.0f);
                PolygonShape shape = new PolygonShape(box, 10);

                b7 = BodyFactory.CreateBody(World);
                b7.BodyType = BodyType.Dynamic;
                b7.Position = new Vector2(7.4f, 1.0f);

                b7.CreateFixture(shape);
            }

            DistanceJoint djd = new DistanceJoint(b3, b7, new Vector2(6.0f, 0.0f), new Vector2(0.0f, -1.0f));
            Vector2 d = djd.BodyB.GetWorldPoint(djd.LocalAnchorB) - djd.BodyA.GetWorldPoint(djd.LocalAnchorA);
            djd.Length = d.Length();
            World.AddJoint(djd);

            {
                const float radius = 0.2f;

                CircleShape shape = new CircleShape(radius, 10);

                for (int i = 0; i < 4; ++i)
                {
                    Body body = BodyFactory.CreateBody(World);
                    body.BodyType = BodyType.Dynamic;
                    body.Position = new Vector2(5.9f + 2.0f * radius * i, 2.4f);

                    Fixture fix = body.CreateFixture(shape);
                    fix.OnCollision += BallCollision;
                }
            }
        }
コード例 #18
0
        protected override void SetupPhysics(World world)
        {
            #if !EDITOR
            Vector2 simPosition = ConvertUnits.ToSimUnits(this._position);

            if (_useShape)
            {
                float simHeight = ConvertUnits.ToSimUnits(this._height);
                float simWidth = ConvertUnits.ToSimUnits(this._width);
                this.Body = new Body(world);
                this.Body.Position = simPosition;

                this._origin = new Vector2(this._texture.Width, this._texture.Height) * 0.5f;

                switch (_shapeType)
                {
                    case ObjectShape.Quadrilateral:
                        {
                            Fixture fixture = FixtureFactory.AttachRectangle(simWidth, simHeight, _mass, Vector2.Zero, Body);
                            break;
                        }
                    case ObjectShape.Circle:
                        {
                            Fixture fixture = FixtureFactory.AttachCircle(simWidth * 0.5f, _mass, this.Body);
                            break;
                        }
                }

                this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, Vector2.Zero, simPosition);
            }
            else
            {
                bool useCentroid = false;

                if (_rotatesWithLevel)
                {
                    useCentroid = true;
                }

                TexVertOutput input = SpinAssist.TexToVert(world, _texture, _mass, false);

                this._origin = Vector2.Zero;
                this.Body = input.Body;

                this.Body.Position = simPosition;
                if (useCentroid)
                {
                    this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, this.Body.LocalCenter, simPosition);
                }
                else
                {
                    this._revoluteJoint = JointFactory.CreateFixedRevoluteJoint(world, Body, this.Body.LocalCenter, simPosition);
                }

                this._revoluteJoint.MaxMotorTorque = float.MaxValue;
                this._revoluteJoint.MotorEnabled = true;

                if (!_rotatesWithLevel)
                {
                    this.Body.BodyType = BodyType.Dynamic;
                }
                else
                {
                    this.Body.BodyType = BodyType.Dynamic;
                    this.Body.Rotation = this._rotation;
                    float newSpeed = 1 / _motorSpeed;
                    this._motorSpeed = newSpeed;
                }

                if (this._motorEnabled)
                {
                    this._revoluteJoint.MotorSpeed = _motorSpeed;
                }
                else
                {
                    this._revoluteJoint.MotorSpeed = 0.0f;
                }
            }
            this.Body.CollidesWith = Category.All & ~Category.Cat20;
            this.Body.CollisionCategories = Category.Cat20;

            this.Body.Friction = 3.0f;

            this.Body.UserData = _materialType;
            #endif
        }