Ejemplo n.º 1
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");
            }
        }
Ejemplo n.º 2
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;
            }
        }
Ejemplo n.º 4
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");
            }
        }
Ejemplo n.º 5
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");
            }
        }