public IController GetController()
        {
            ITransformable transf;

            string[] transformableNames = PrefabUtils.GetEntityAndComponentName(Transformable);
            if (transformableNames[0] == null)
            {
                transf = FatherEntity.SceneNodes[Transformable];
            }
            else
            {
                transf = GameWorldManager.Instance.GetEntity(transformableNames[0]).SceneNodes[transformableNames[1]];
            }

            switch (Type)
            {
            case ControllerType.BodyController:

                Body       body;
                GameEntity ent;

                string[] bodyNames = PrefabUtils.GetEntityAndComponentName(Body);
                if (bodyNames[0] == null)
                {
                    body = FatherEntity.PhysicsEntity.GetBody(Body);
                    ent  = FatherEntity;
                }
                else
                {
                    ent  = GameWorldManager.Instance.GetEntity(bodyNames[0]);
                    body = ent.PhysicsEntity.GetBody(bodyNames[1]);
                }

                BodyController bc = new BodyController(transf, body, ent);
                return(bc);

            case ControllerType.LineJointController:

                Joint joint;

                string[] jointNames = PrefabUtils.GetEntityAndComponentName(Joint);
                if (jointNames[0] == null)
                {
                    joint = FatherEntity.PhysicsEntity.GetJoint(Joint);
                }
                else
                {
                    joint = GameWorldManager.Instance.GetEntity(jointNames[0]).PhysicsEntity.GetJoint(jointNames[1]);
                }

                LineJointController ljc = new LineJointController(transf, joint.BodyA, joint.BodyB);
                return(ljc);
            }
            return(new BodyController(null, null, null));
        }
Example #2
0
        public Joint GetPhysicsJoint(Vector2 scale)
        {
            float scaleD = (scale.X + scale.Y) / 2f;
            Body  body1, body2;

            string[] bodyNames = PrefabUtils.GetEntityAndComponentName(Body1);
            if (bodyNames[0] == null)
            {
                body1 = FatherEntity.PhysicsEntity.GetBody(Body1);
            }
            else
            {
                body1 = GameWorldManager.Instance.GetEntity(bodyNames[0]).PhysicsEntity.GetBody(bodyNames[1]);
            }

            bodyNames = PrefabUtils.GetEntityAndComponentName(Body2);
            if (bodyNames[0] == null)
            {
                body2 = FatherEntity.PhysicsEntity.GetBody(Body2);
            }
            else
            {
                body2 = GameWorldManager.Instance.GetEntity(bodyNames[0]).PhysicsEntity.GetBody(bodyNames[1]);
            }

            switch (Type)
            {
            case JointType.Line:
                LineJoint joint = new LineJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, Axis);
                joint.MaxMotorTorque   = MaxMotorTorque;
                joint.MotorEnabled     = MotorEnabled;
                joint.Frequency        = Frequency;
                joint.DampingRatio     = DampingRatio;
                joint.CollideConnected = CollideConnected;

                Platform.Instance.PhysicsWorld.AddJoint(joint);
                return(joint);

            case JointType.Revolute:
                RevoluteJoint joint2 = new RevoluteJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale);
                joint2.CollideConnected = CollideConnected;
                joint2.MaxMotorTorque   = MaxMotorTorque;
                joint2.MotorEnabled     = MotorEnabled;
                Platform.Instance.PhysicsWorld.AddJoint(joint2);

                return(joint2);

            case JointType.Weld:
                WeldJoint joint3 = new WeldJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale);
                joint3.CollideConnected = CollideConnected;
                Platform.Instance.PhysicsWorld.AddJoint(joint3);
                return(joint3);

            case JointType.Slider:
                SliderJoint joint4 = new SliderJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale, UnitsConverter.ToSimUnits(MinLength) * scaleD, UnitsConverter.ToSimUnits(MaxLength) * scaleD);
                joint4.DampingRatio     = DampingRatio;
                joint4.CollideConnected = CollideConnected;
                Platform.Instance.PhysicsWorld.AddJoint(joint4);
                return(joint4);

            case JointType.Distance:
                DistanceJoint joint5 = new DistanceJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale);
                joint5.Frequency        = Frequency;
                joint5.DampingRatio     = DampingRatio;
                joint5.CollideConnected = CollideConnected;
                joint5.Length           = UnitsConverter.ToSimUnits(Length) * scaleD;
                Platform.Instance.PhysicsWorld.AddJoint(joint5);
                return(joint5);

            case JointType.Prismatic:
                PrismaticJoint joint6 = new PrismaticJoint(body1, body2, UnitsConverter.ToSimUnits(Anchor) * scale, UnitsConverter.ToSimUnits(Anchor2) * scale, Axis);
                joint6.CollideConnected = CollideConnected;
                joint6.UpperLimit       = UnitsConverter.ToSimUnits(UpperLimit) * scaleD;
                joint6.LowerLimit       = UnitsConverter.ToSimUnits(LowerLimit) * scaleD;
                joint6.LimitEnabled     = LimitEnabled;
                joint6.MotorEnabled     = MotorEnabled;
                joint6.MaxMotorForce    = MaxMotorForce * scaleD;
                joint6.MotorSpeed       = MotorSpeed * scaleD;

                Platform.Instance.PhysicsWorld.AddJoint(joint6);
                return(joint6);

            default:
                return(null);
            }
        }