Beispiel #1
0
        private void NextStepFixedMouseJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating fixed mouse joint. Choose Body...";
                _step++;
                break;

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

            case 2:
                Vector2 worldAnchor = position;
                _currentStateMessage          = string.Format("World anchor has been selected. Position - {0}. FIXED MOUSE JOINT CREATED.", position.ToString());
                _jointParameters.worldAnchorA = worldAnchor;
                _joint = new FixedMouseJoint(_jointParameters.bodyA, _jointParameters.worldAnchorA);
                _step  = 0;
                break;

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

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

            case 2:
                _currentStateMessage          = "Body anchor has been selected. FIXED FRICTION JOINT CREATED";
                _jointParameters.localAnchorA = CommonHelpers.CalculateLocalPoint(position, _jointParameters.bodyA);
                _joint = new FixedFrictionJoint(_jointParameters.bodyA, _jointParameters.localAnchorA);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #3
0
        private void NextStepFixedAngleJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating fixed angle joint. Choose Body...";
                _step++;
                break;

            case 1:
                Body body = CommonHelpers.FindBody(position, _world);
                if (body == null)
                {
                    _currentStateMessage = "Cant find body in this position. Choose Body...";
                    break;
                }
                _currentStateMessage   = "Body has been selected. FIXED ANGLE JOINT CREATED";
                _jointParameters.bodyA = body;
                _joint = new FixedAngleJoint(_jointParameters.bodyA);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #4
0
        private void NextStepLineJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating Line 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 BodyB...";
                _jointParameters.bodyA = bodyA;
                _step++;
                break;

            case 2:
                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 world anchor...";
                _jointParameters.bodyB = bodyB;
                _step++;
                break;

            case 3:
                Vector2 worldAnchor = position;
                _currentStateMessage          = string.Format("World anchor has been selected. Position - {0}. Detecting axis. Choose first axis point...", position.ToString());
                _jointParameters.worldAnchorA = worldAnchor;
                _step++;
                break;

            case 4:
                _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 5:
                Vector2 axis = (position - _jointParameters.axisFirst);
                axis.Normalize();
                _jointParameters.axisSecond = position;
                _currentStateMessage        = string.Format("Second axis point has been selected. Position - {0}, axis - {1}. LINE JOINT CREATED.", position.ToString(), axis.ToString());
                _joint = new LineJoint(_jointParameters.bodyA, _jointParameters.bodyB, _jointParameters.worldAnchorA, axis);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #5
0
        private void NextStepWeldJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating weld 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}. WELD JOINT CREATED.", position.ToString(), localAnchorB.ToString());
                _jointParameters.localAnchorB = localAnchorB;
                _joint = new WeldJoint(_jointParameters.bodyA, _jointParameters.bodyB, _jointParameters.localAnchorA, _jointParameters.localAnchorB);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
        public void NextStep(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _finished      = false;
                _statusMessage = "Attaching fixture to body. Choose body...";
                _step++;
                break;

            case 1:
                _foundBody = CommonHelpers.FindBody(position, _world);
                if (_foundBody == null)
                {
                    _statusMessage = "Cant find body in this position. Choose Body...";
                    break;
                }
                _statusMessage = "Body has been selected. Choose fixture position...";
                _step++;
                break;

            case 2:
                Vector2  offset             = CommonHelpers.CalculateLocalPoint(position, _foundBody);
                Vertices _tempShapeVertices = new Vertices(_initialShapeVertices);
                _tempShapeVertices.Rotate(-_foundBody.Rotation);
                _tempShapeVertices.Rotate(_prototypeBody.Rotation);
                _tempShapeVertices.Translate(ref offset);

                List <Vertices> decomposedVerts = EarclipDecomposer.ConvexPartition(_tempShapeVertices);
                _resultShapeList = new List <Shape>(decomposedVerts.Count);

                foreach (Vertices vertices in decomposedVerts)
                {
                    if (vertices.Count == 2)
                    {
                        _resultShapeList.Add(new EdgeShape(vertices[0], vertices[1]));
                    }
                    else
                    {
                        _resultShapeList.Add(new PolygonShape(vertices, _prototypeBody.Density == null ? 1f : (float)_prototypeBody.Density));
                    }
                }
                _statusMessage = "Fixture has been created.";
                _finished      = true;
                _step          = 0;
                break;
            }
        }
Beispiel #7
0
        private void NextStepFixedRevoluteJoint(Vector2 position)
        {
            switch (_step)
            {
            case 0:
                _currentStateMessage = "Creating fixed revolute joint. Choose Body...";

                _step++;
                break;

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

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

            case 3:
                _currentStateMessage          = string.Format("World anchor has been selected. Position - {0}. FIXED DISTANCE JOINT CREATED.", position.ToString());
                _jointParameters.worldAnchorA = position;
                _joint = new FixedRevoluteJoint(_jointParameters.bodyA, _jointParameters.localAnchorA, _jointParameters.worldAnchorA);
                _step  = 0;
                break;

            default:
                throw new ArgumentOutOfRangeException("Unknown join creation step");
            }
        }
Beispiel #8
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 #9
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");
            }
        }