/*
* Copyright (c) 2006-2012 Erin Catto http://www.box2d.org
*
* This software is provided 'as-is', without any express or implied
* warranty.  In no event will the authors be held liable for any damages
* arising from the use of this software.
* Permission is granted to anyone to use this software for any purpose,
* including commercial applications, and to alter it and redistribute it
* freely, subject to the following restrictions:
* 1. The origin of this software must not be misrepresented; you must not
* claim that you wrote the original software. If you use this software
* in a product, an acknowledgment in the product documentation would be
* appreciated but is not required.
* 2. Altered source versions must be plainly marked as such, and must not be
* misrepresented as being the original software.
* 3. This notice may not be removed or altered from any source distribution.
*/
System.register(["Box2D", "Testbed"], function (exports_1, context_1) {
    "use strict";
    var box2d, testbed, SliderCrank;
    var __moduleName = context_1 && context_1.id;
    return {
        setters: [
            function (box2d_1) {
                box2d = box2d_1;
            },
            function (testbed_1) {
                testbed = testbed_1;
            }
        ],
        execute: function () {
            SliderCrank = class SliderCrank extends testbed.Test {
                constructor() {
                    super();
                    let ground = null;
                    {
                        const bd = new box2d.b2BodyDef();
                        ground = this.m_world.CreateBody(bd);
                        const shape = new box2d.b2EdgeShape();
                        shape.Set(new box2d.b2Vec2(-40.0, 0.0), new box2d.b2Vec2(40.0, 0.0));
                        ground.CreateFixture(shape, 0.0);
                    }
                    {
                        let prevBody = ground;
                        // Define crank.
                        {
                            const shape = new box2d.b2PolygonShape();
                            shape.SetAsBox(0.5, 2.0);
                            const bd = new box2d.b2BodyDef();
                            bd.type = box2d.b2BodyType.b2_dynamicBody;
                            bd.position.Set(0.0, 7.0);
                            const body = this.m_world.CreateBody(bd);
                            body.CreateFixture(shape, 2.0);
                            const rjd = new box2d.b2RevoluteJointDef();
                            rjd.Initialize(prevBody, body, new box2d.b2Vec2(0.0, 5.0));
                            rjd.motorSpeed = 1.0 * box2d.b2_pi;
                            rjd.maxMotorTorque = 10000.0;
                            rjd.enableMotor = true;
                            this.m_joint1 = this.m_world.CreateJoint(rjd);
                            prevBody = body;
                        }
                        // Define follower.
                        {
                            const shape = new box2d.b2PolygonShape();
                            shape.SetAsBox(0.5, 4.0);
                            const bd = new box2d.b2BodyDef();
                            bd.type = box2d.b2BodyType.b2_dynamicBody;
                            bd.position.Set(0.0, 13.0);
                            const body = this.m_world.CreateBody(bd);
                            body.CreateFixture(shape, 2.0);
                            const rjd = new box2d.b2RevoluteJointDef();
                            rjd.Initialize(prevBody, body, new box2d.b2Vec2(0.0, 9.0));
                            rjd.enableMotor = false;
                            this.m_world.CreateJoint(rjd);
                            prevBody = body;
                        }
                        // Define piston
                        {
                            const shape = new box2d.b2PolygonShape();
                            shape.SetAsBox(1.5, 1.5);
                            const bd = new box2d.b2BodyDef();
                            bd.type = box2d.b2BodyType.b2_dynamicBody;
                            bd.fixedRotation = true;
                            bd.position.Set(0.0, 17.0);
                            const body = this.m_world.CreateBody(bd);
                            body.CreateFixture(shape, 2.0);
                            const rjd = new box2d.b2RevoluteJointDef();
                            rjd.Initialize(prevBody, body, new box2d.b2Vec2(0.0, 17.0));
                            this.m_world.CreateJoint(rjd);
                            const pjd = new box2d.b2PrismaticJointDef();
                            pjd.Initialize(ground, body, new box2d.b2Vec2(0.0, 17.0), new box2d.b2Vec2(0.0, 1.0));
                            pjd.maxMotorForce = 1000.0;
                            pjd.enableMotor = true;
                            this.m_joint2 = this.m_world.CreateJoint(pjd);
                        }
                        // Create a payload
                        {
                            const shape = new box2d.b2PolygonShape();
                            shape.SetAsBox(1.5, 1.5);
                            const bd = new box2d.b2BodyDef();
                            bd.type = box2d.b2BodyType.b2_dynamicBody;
                            bd.position.Set(0.0, 23.0);
                            const body = this.m_world.CreateBody(bd);
                            body.CreateFixture(shape, 2.0);
                        }
                    }
                }
                Keyboard(key) {
                    switch (key) {
                        case "f":
                            this.m_joint2.EnableMotor(!this.m_joint2.IsMotorEnabled());
                            this.m_joint2.GetBodyB().SetAwake(true);
                            break;
                        case "m":
                            this.m_joint1.EnableMotor(!this.m_joint1.IsMotorEnabled());
                            this.m_joint1.GetBodyB().SetAwake(true);
                            break;
                    }
                }
                Step(settings) {
                    super.Step(settings);
                    testbed.g_debugDraw.DrawString(5, this.m_textLine, "Keys: (f) toggle friction, (m) toggle motor");
                    this.m_textLine += testbed.DRAW_STRING_NEW_LINE;
                    const torque = this.m_joint1.GetMotorTorque(settings.hz);
                    testbed.g_debugDraw.DrawString(5, this.m_textLine, `Motor Torque = ${torque.toFixed(0)}`);
                    this.m_textLine += testbed.DRAW_STRING_NEW_LINE;
                }
                static Create() {
                    return new SliderCrank();
                }
            };
            exports_1("SliderCrank", SliderCrank);
            SliderCrank.e_count = 30;
        }
    };
});
//# sourceMappingURL=data:application/json;base64, 