Beispiel #1
0
        private void NextStepPrismaticJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating prismatic joint. Choose BodyA...";
                _step++;
                break;

            case 1:
                Body bodyA = CommonHelpers.FindBody(position, _world);
                if (bodyA == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyA...";
                    break;
                }
                _currentStateMessage   = "BodyA has been selected. Choose LocalAnchorA...";
                _jointParameters.bodyA = bodyA;
                _step++;
                break;

            case 2:
                Vector2 localAnchorA = CommonHelpers.CalculateLocalPoint(position, _jointParameters.bodyA);
                _currentStateMessage          = string.Format("AnchorA has been selected. Position - {0}, local position - {1}. Choose BodyB...", position.ToString(), localAnchorA.ToString());
                _jointParameters.localAnchorA = localAnchorA;
                _step++;
                break;

            case 3:
                Body bodyB = CommonHelpers.FindBody(position, _world);
                if (bodyB == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyB...";
                    break;
                }
                _currentStateMessage   = "BodyB has been selected. Choose LocalAnchorB...";
                _jointParameters.bodyB = bodyB;
                _step++;
                break;

            case 4:
                Vector2 localAnchorB = CommonHelpers.CalculateLocalPoint(position, _jointParameters.bodyB);
                _currentStateMessage          = string.Format("AnchorB has been selected. Position - {0}, local position - {1}. Detecting axis. Select first axis point...", position.ToString(), localAnchorB.ToString());
                _jointParameters.localAnchorB = localAnchorB;
                _step++;
                break;

            case 5:
                _currentStateMessage       = string.Format("First axis point has been selected. Position - {0}. Detecting axis. Select second axis point...", position.ToString());
                _jointParameters.axisFirst = position;
                _step++;
                break;

            case 6:
                Vector2 axis = (position - _jointParameters.axisFirst);
                axis.Normalize();
                _jointParameters.axisSecond = position;
                _currentStateMessage        = string.Format("Second axis point has been selected. Position - {0}, axis - {1}. PRISMATIC JOINT CREATED.", position.ToString(), axis.ToString());
                _joint = new PrismaticJoint(_jointParameters.bodyA, _jointParameters.bodyB, _jointParameters.localAnchorA, _jointParameters.localAnchorB, axis);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #2
0
        private void NextStepPulleyJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating pulley joint. Choose BodyA...";
                _step++;
                break;

            case 1:
                Body bodyA = CommonHelpers.FindBody(position, _world);
                if (bodyA == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyA...";
                    break;
                }
                _currentStateMessage   = "BodyA has been selected. Choose LocalAnchorA...";
                _jointParameters.bodyA = bodyA;
                _step++;
                break;

            case 2:
                Vector2 localAnchorA = CommonHelpers.CalculateLocalPoint(position, _jointParameters.bodyA);
                _currentStateMessage          = string.Format("LocalAnchorA has been selected. Position - {0}, local position - {1}. Choose GroundAnchorA...", position.ToString(), localAnchorA.ToString());
                _jointParameters.localAnchorA = localAnchorA;
                _step++;
                break;

            case 3:
                Vector2 groundAnchorA = position;
                _currentStateMessage          = string.Format("GroundAnchorA has been selected. Position - {0}. Choose BodyB...", position.ToString());
                _jointParameters.worldAnchorA = groundAnchorA;
                _step++;
                break;

            case 4:
                Body bodyB = CommonHelpers.FindBody(position, _world);
                if (bodyB == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyB...";
                    break;
                }
                _currentStateMessage   = "BodyB has been selected. Choose LocalAnchorB...";
                _jointParameters.bodyB = bodyB;
                _step++;
                break;

            case 5:
                Vector2 localAnchorB = CommonHelpers.CalculateLocalPoint(position, _jointParameters.bodyB);
                _currentStateMessage          = string.Format("LocalAnchorB has been selected. Position - {0}, local position - {1}. Choose GroundAnchorB.", position.ToString(), localAnchorB.ToString());
                _jointParameters.localAnchorB = localAnchorB;
                _step++;
                break;

            case 6:
                Vector2 groundAnchorB = position;
                _currentStateMessage          = string.Format("GroundAnchorB has been selected. Position - {0}. PULLEY JOINT CREATED.", position.ToString());
                _jointParameters.worldAnchorB = groundAnchorB;
                _joint = new PulleyJoint(_jointParameters.bodyA, _jointParameters.bodyB, _jointParameters.worldAnchorA, _jointParameters.worldAnchorB, _jointParameters.localAnchorA, _jointParameters.localAnchorB, 1f);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #3
0
        private void NextStepGearJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating Gear joint. Choose BodyA with one revolute or prismatic joint...";
                _step++;
                break;

            case 1:
                Body bodyA = CommonHelpers.FindBody(position, _world);
                if (bodyA == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyA...";
                    break;
                }
                {
                    if (bodyA.JointList == null)
                    {
                        _currentStateMessage = "This body doesnt contain joints. Choose BodyA with one revolute or prismatic joint...";
                        break;
                    }
                    JointEdge iterator    = bodyA.JointList;
                    int       validJoints = 0;
                    do
                    {
                        JointType type = iterator.Joint.JointType;
                        if (type == JointType.Revolute ||
                            type == JointType.Prismatic ||
                            type == JointType.FixedRevolute ||
                            type == JointType.FixedPrismatic)
                        {
                            _jointParameters.jointA = iterator.Joint;
                            validJoints++;
                        }
                    } while ((iterator = iterator.Next) != null);
                    if (validJoints > 1)
                    {
                        _currentStateMessage = "This body contains more than one valid joints. Choose BodyA with one revolute or prismatic joint...";
                        break;
                    }
                }
                _currentStateMessage = "BodyA with valid joint has been selected. Choose BodyB with revolute or prismatic joint...";
                _step++;
                break;

            case 2:
                Body bodyB = CommonHelpers.FindBody(position, _world);
                if (bodyB == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose BodyB...";
                    break;
                }
                {
                    JointEdge iterator    = bodyB.JointList;
                    int       validJoints = 0;
                    do
                    {
                        JointType type = iterator.Joint.JointType;
                        if (type == JointType.Revolute ||
                            type == JointType.Prismatic ||
                            type == JointType.FixedRevolute ||
                            type == JointType.FixedPrismatic)
                        {
                            _jointParameters.jointB = iterator.Joint;
                            validJoints++;
                        }
                    } while ((iterator = iterator.Next) != null);
                    if (validJoints > 1)
                    {
                        _currentStateMessage = "This body contains more than one valid joints. Choose BodyB with one revolute or prismatic joint...";
                        break;
                    }
                }
                _currentStateMessage = "BodyB wiht valid has been selected. GEAR JOINT CREATED";
                _joint = new GearJoint(_jointParameters.jointA, _jointParameters.jointB, 1f);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }