示例#1
0
        public Joint AddToPhysicsObject(World w, PhysicsStructure parentObject)
        {
            Joint j     = null;
            Body  body1 = null;
            Body  body2 = null;

            if (BodyId1 >= 0)
            {
                body1 = parentObject.Bodies[BodyId1];
            }

            if (BodyId2 >= 0)
            {
                body2 = parentObject.Bodies[BodyId2];
            }

            switch (this.JointType)
            {
            case JointType.Revolute:
            {
                j = JointFactory.CreateRevoluteJoint(w, body1, body2, parentObject.Position + Anchor1);
            }
            break;

            case JointType.FixedRevolute:
            {
                j = JointFactory.CreateFixedRevoluteJoint(w, body1, Anchor1, parentObject.Position + Anchor1);
            }
            break;

            case JointType.Angle:
            {
                j = JointFactory.CreateAngleJoint(w, body1, body2);
            }
            break;

            default:
                break;
            }

            if (j != null)
            {
                j.Breakpoint = BreakPoint;
                parentObject.Joints.Add(j);
            }
            return(j);
        }
示例#2
0
        public PhysicsStructure CreateStructure(World w, Vector2 position)
        {
            PhysicsStructure po = new PhysicsStructure(position);

            // Create elements
            foreach (BodySettings bs in Bodies)
            {
                po.Bodies.Add(bs.CreateBody(w, position));
            }

            // Create element links
            if (Joints != null)
            {
                foreach (JointSettings js in Joints)
                {
                    js.AddToPhysicsObject(w, po);
                }
            }

            return(po);
        }
示例#3
0
        public PhysicsStructure CreateStructure(World w, Vector2 position)
        {
            PhysicsStructure po = new PhysicsStructure(position);

            // Create elements
            foreach (BodySettings bs in Bodies)
                po.Bodies.Add(bs.CreateBody(w, position));

            // Create element links
            if (Joints != null)
            {
                foreach (JointSettings js in Joints)
                    js.AddToPhysicsObject(w, po);
            }

            return po;
        }
示例#4
0
        public Joint AddToPhysicsObject(World w, PhysicsStructure parentObject)
        {
            Joint j = null;
            Body body1 = null;
            Body body2 = null;

            if (BodyId1 >= 0)
                body1 = parentObject.Bodies[BodyId1];

            if (BodyId2 >= 0)
                body2 = parentObject.Bodies[BodyId2];

            switch (this.JointType)
            {
                case JointType.Revolute:
                    {
                        j = JointFactory.CreateRevoluteJoint(w, body1, body2, parentObject.Position + Anchor1);
                    }
                    break;
                case JointType.FixedRevolute:
                    {
                        j = JointFactory.CreateFixedRevoluteJoint(w, body1, Anchor1, parentObject.Position + Anchor1);
                    }
                    break;
                case JointType.Angle:
                    {
                        j = JointFactory.CreateAngleJoint(w, body1, body2);
                    }
                    break;
                default:
                    break;
            }

            if (j != null)
            {
                j.Breakpoint = BreakPoint;
                parentObject.Joints.Add(j);
            }
            return j;
        }
示例#5
0
        public override void Initialize(GameScreen parentScreen)
        {
            base.Initialize(parentScreen);

            if (Settings.Physics != null)
            {
                var body = BodyFactory.CreateRectangle(
                    parentScreen.Physics.World,
                    Settings.Physics.Width * Settings.Scale.X,
                    Settings.Physics.Height * Settings.Scale.Y,
                    Settings.Physics.Density,
                    ConvertUnits.ToSimUnits(Settings.Position),
                    Settings.Physics.Offset);

                body.Enabled = false;

                body.FixtureList[0].CollidesWith = (Category)Settings.Physics.CollidesWith;
                body.FixtureList[0].CollisionCategories = (Category)Settings.Physics.Category;
                body.FixtureList[0].CollisionGroup = Settings.Physics.CollisionGroup;

                if (Settings.PhysicsFixture2 != null)
                {
                    Fixture fix2 = FixtureFactory.AttachRectangle(
                        Settings.PhysicsFixture2.Width,
                        Settings.PhysicsFixture2.Height,
                        Settings.PhysicsFixture2.Density,
                        Settings.PhysicsFixture2.Offset,
                        body);

                    fix2.CollidesWith = (Category)Settings.PhysicsFixture2.CollidesWith;
                    fix2.CollisionCategories = (Category)Settings.PhysicsFixture2.Category;
                    fix2.CollisionGroup = Settings.PhysicsFixture2.CollisionGroup;
                }

                body.BodyType = BodyType.Dynamic;
                body.Inertia = Settings.Physics.RotationalInertia;

                physics = new PhysicsStructure
                {
                    Bodies = { body }
                };

                physics.Enabled = Settings.ActivateByDefault;
            }

            this.LevelScreen = (LevelScreen)parentScreen;
        }