Ejemplo n.º 1
0
        public override void initTest(bool argDeserialized)
        {
            input.transformA = new Transform();
            input.transformB = new Transform();
            {
                m_transformA = new Transform();
                m_transformA.setIdentity();
                m_transformA.p.set(0.0f, -0.2f);
                m_polygonA = new PolygonShape();
                m_polygonA.setAsBox(10.0f, 0.2f);
            }

            {
                m_positionB = new Vec2();
                m_positionB.set(12.017401f, 0.13678508f);
                m_angleB = -0.0109265f;

                m_transformB = new Transform();
                m_transformB.set(m_positionB, m_angleB);

                m_polygonB = new PolygonShape();
                m_polygonB.setAsBox(2.0f, 0.1f);
            }
            for (int i = 0; i < v.Length; i++)
            {
                v[i] = new Vec2();
            }
        }
Ejemplo n.º 2
0
        public override void initTest(bool deserialized)
        {
            {
                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                    {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices = {new Vec2(20, -1), new Vec2(40, -1), new Vec2(40, 30), new Vec2(20, 20)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }
            }

            m_world.setParticleRadius(0.35f);
            m_world.setParticleDamping(0.2f);

            {
                CircleShape shape = new CircleShape();
                shape.m_p.set(0, 30);
                shape.m_radius = 20;
                ParticleGroupDef pd = new ParticleGroupDef();
                pd.flags = ParticleType.b2_waterParticle;
                pd.shape = shape;
                m_world.createParticleGroup(pd);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                CircleShape shape = new CircleShape();
                shape.m_p.set(0, 80);
                shape.m_radius = 5;
                body.createFixture(shape, 0.5f);
            }
        }
Ejemplo n.º 3
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }

            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.6f, 0.125f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;
                fd.friction = 0.2f;

                RevoluteJointDef jd = new RevoluteJointDef();
                jd.collideConnected = false;

                float y = 25.0f;
                Body prevBody = ground;
                for (int i = 0; i < 30; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(0.5f + i, y);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(fd);

                    Vec2 anchor = new Vec2(i, y);
                    jd.initialize(prevBody, body, anchor);
                    getWorld().createJoint(jd);

                    prevBody = body;
                }
            }
        }
Ejemplo n.º 4
0
        public override void initTest(bool deserialized)
        {
            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.allowSleep = false;
                bd.position.set(0.0f, 10.0f);
                Body body = m_world.createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 10.0f, new Vec2(20.0f, 0.0f), 0.0f);
                body.createFixture(shape, 5.0f);
                shape.setAsBox(0.5f, 10.0f, new Vec2(-20.0f, 0.0f), 0.0f);
                body.createFixture(shape, 5.0f);
                shape.setAsBox(20.0f, 0.5f, new Vec2(0.0f, 10.0f), 0.0f);
                body.createFixture(shape, 5.0f);
                shape.setAsBox(20.0f, 0.5f, new Vec2(0.0f, -10.0f), 0.0f);
                body.createFixture(shape, 5.0f);

                RevoluteJointDef jd = new RevoluteJointDef();
                jd.bodyA = getGroundBody();
                jd.bodyB = body;
                jd.localAnchorA.set(0.0f, 10.0f);
                jd.localAnchorB.set(0.0f, 0.0f);
                jd.referenceAngle = 0.0f;
                jd.motorSpeed = 0.05f*MathUtils.PI;
                jd.maxMotorTorque = 1e7f;
                jd.enableMotor = true;
                m_joint = (RevoluteJoint) m_world.createJoint(jd);
            }

            m_world.setParticleRadius(0.15f);
            m_world.setParticleDamping(0.2f);

            {
                ParticleGroupDef pd = new ParticleGroupDef();
                pd.flags = 0;

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(9.0f, 9.0f, new Vec2(0.0f, 10.0f), 0.0f);

                pd.shape = shape;
                m_world.createParticleGroup(pd);
            }

            m_time = 0;
        }
Ejemplo n.º 5
0
        public override void initTest(bool deserialized)
        {
            {
                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(-40, -20), new Vec2(40, -20), new Vec2(40, 0), new Vec2(-40, 0)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[]
                        {
                            new Vec2(-40, -20), new Vec2(-20, -20), new Vec2(-20, 60),
                            new Vec2(-40, 60)
                        };
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();

                    Vec2[] vertices =
                        new Vec2[] {new Vec2(20, -20), new Vec2(40, -20), new Vec2(40, 60), new Vec2(20, 60)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(-40, 40), new Vec2(40, 40), new Vec2(40, 60), new Vec2(-40, 60)};
                    shape.set(vertices, 4);
                    getGroundBody().createFixture(shape, 0.0f);
                }
            }

            m_world.setParticleRadius(0.5f);
            m_lastGroup = null;
            m_drawing = true;
            m_groupFlags = 0;
        }
Ejemplo n.º 6
0
        public override void initTest(bool deserialized)
        {
            {
                BodyDef bd = new BodyDef();
                bd.position.set(0.0f, 0.0f);
                Body body = m_world.createBody(bd);

                EdgeShape edge = new EdgeShape();

                edge.set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.0f));
                body.createFixture(edge, 0.0f);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.0f), 0.0f);
                body.createFixture(shape, 0.0f);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(0.0f, 4.0f);

                PolygonShape box = new PolygonShape();
                box.setAsBox(2.0f, 0.1f);

                m_body = m_world.createBody(bd);
                m_body.createFixture(box, 1.0f);

                box.setAsBox(0.25f, 0.25f);

                // m_x = RandomFloat(-1.0f, 1.0f);
                m_x = -0.06530577f;
                bd.position.set(m_x, 10.0f);
                bd.bullet = true;

                m_bullet = m_world.createBody(bd);
                m_bullet.createFixture(box, 100.0f);

                m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
            }
        }
Ejemplo n.º 7
0
        public override void initTest(bool argDeserialized)
        {
            {
                BodyDef bd = new BodyDef();
                bd.position.set(0.0f, 0.0f);
                Body body = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();

                shape.set(new Vec2(-10.0f, 0.0f), new Vec2(10.0f, 0.0f));
                body.createFixture(shape, 0.0f);

                PolygonShape pshape = new PolygonShape();
                pshape.setAsBox(0.2f, 1.0f, new Vec2(0.5f, 1.0f), 0.0f);
                body.createFixture(pshape, 0.0f);
            }
            m_poly = new PolygonShape();
            m_poly.setAsBox(2.0f, 0.1f);
            m_circle = new CircleShape();
            m_circle.m_p.setZero();
            m_circle.m_radius = 0.5f;

            BodyDef bd2 = new BodyDef();
            bd2.type = BodyType.DYNAMIC;
            bd2.position.set(0.0f, 20.0f);

            m_body = getWorld().createBody(bd2);
            currFixture = m_body.createFixture(m_poly, 1.0f);

            m_angularVelocity = (float) _random.NextDouble()*100 - 50;
            m_angularVelocity = 33.468121f;
            m_body.setLinearVelocity(new Vec2(0.0f, -100.0f));
            m_body.setAngularVelocity(m_angularVelocity);

            TimeOfImpact.toiCalls = 0;
            TimeOfImpact.toiIters = 0;
            TimeOfImpact.toiMaxIters = 0;
            TimeOfImpact.toiRootIters = 0;
            TimeOfImpact.toiMaxRootIters = 0;
        }
Ejemplo n.º 8
0
        public override void initTest(bool argDeserialized)
        {
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            BodyDef bd2 = new BodyDef();
            bd2.type = BodyType.DYNAMIC;
            bd2.position.set(0.0f, 10.0f);
            m_body = getWorld().createBody(bd2);

            PolygonShape shape2 = new PolygonShape();
            shape2.setAsBox(4.0f, 4.0f, new Vec2(0.0f, 0.0f), 0.0f);
            m_fixture1 = m_body.createFixture(shape2, 10.0f);

            m_fixture2 = null;
        }
Ejemplo n.º 9
0
        public override void initTest(bool deserialized)
        {
            {
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f));
                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                getGroundBody().createFixture(fd);
            }

            // Define motorized body
            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(0.0f, 8.0f);
                Body body = getWorld().createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(2.0f, 0.5f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.friction = 0.6f;
                fd.density = 2.0f;
                body.createFixture(fd);

                MotorJointDef mjd = new MotorJointDef();
                mjd.initialize(getGroundBody(), body);
                mjd.maxForce = 1000.0f;
                mjd.maxTorque = 1000.0f;
                m_joint = (MotorJoint) m_world.createJoint(mjd);
            }

            m_go = false;
            m_time = 0.0f;
        }
Ejemplo n.º 10
0
        public override void initTest(bool deserialized)
        {
            {
                BodyDef bd = new BodyDef();
                Body ground = m_world.createBody(bd);

                ChainShape shape = new ChainShape();
                Vec2[] vertices =
                    new Vec2[] {new Vec2(-20, 0), new Vec2(20, 0), new Vec2(20, 40), new Vec2(-20, 40)};
                shape.createLoop(vertices, 4);
                ground.createFixture(shape, 0.0f);

            }

            m_world.setParticleRadius(0.15f);
            m_world.setParticleDamping(0.2f);
            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(8, 10, new Vec2(-12, 10.1f), 0);
                ParticleGroupDef pd = new ParticleGroupDef();
                pd.shape = shape;
                m_world.createParticleGroup(pd);
            }
        }
Ejemplo n.º 11
0
        public override void initTest(bool argDeserialized)
        {
            if (argDeserialized)
            {
                return;
            }

            m_offset.set(0.0f, 8.0f);
            m_motorSpeed = 2.0f;
            m_motorOn = true;
            Vec2 pivot = new Vec2(0.0f, 0.8f);

            // Ground
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-50.0f, 0.0f), new Vec2(50.0f, 0.0f));
                ground.createFixture(shape, 0.0f);

                shape.set(new Vec2(-50.0f, 0.0f), new Vec2(-50.0f, 10.0f));
                ground.createFixture(shape, 0.0f);

                shape.set(new Vec2(50.0f, 0.0f), new Vec2(50.0f, 10.0f));
                ground.createFixture(shape, 0.0f);
            }

            // Balls
            for (int i = 0; i < 40; ++i)
            {
                CircleShape shape = new CircleShape();
                shape.m_radius = 0.25f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-40.0f + 2.0f*i, 0.5f);

                Body body = getWorld().createBody(bd);
                body.createFixture(shape, 1.0f);
            }

            // Chassis
            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(2.5f, 1.0f);

                FixtureDef sd = new FixtureDef();
                sd.density = 1.0f;
                sd.shape = shape;
                sd.filter.groupIndex = -1;
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(pivot);
                bd.position.addLocal(m_offset);
                m_chassis = getWorld().createBody(bd);
                m_chassis.createFixture(sd);
            }

            {
                CircleShape shape = new CircleShape();
                shape.m_radius = 1.6f;

                FixtureDef sd = new FixtureDef();
                sd.density = 1.0f;
                sd.shape = shape;
                sd.filter.groupIndex = -1;
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(pivot);
                bd.position.addLocal(m_offset);
                m_wheel = getWorld().createBody(bd);
                m_wheel.createFixture(sd);
            }

            {
                RevoluteJointDef jd = new RevoluteJointDef();

                jd.initialize(m_wheel, m_chassis, pivot.add(m_offset));
                jd.collideConnected = false;
                jd.motorSpeed = m_motorSpeed;
                jd.maxMotorTorque = 400.0f;
                jd.enableMotor = m_motorOn;
                m_motorJoint = (RevoluteJoint) getWorld().createJoint(jd);
            }

            Vec2 wheelAnchor;

            wheelAnchor = pivot.add(new Vec2(0.0f, -0.8f));

            createLeg(-1.0f, wheelAnchor);
            createLeg(1.0f, wheelAnchor);

            m_wheel.setTransform(m_wheel.getPosition(), 120.0f*MathUtils.PI/180.0f);
            createLeg(-1.0f, wheelAnchor);
            createLeg(1.0f, wheelAnchor);

            m_wheel.setTransform(m_wheel.getPosition(), -120.0f*MathUtils.PI/180.0f);
            createLeg(-1.0f, wheelAnchor);
            createLeg(1.0f, wheelAnchor);
        }
Ejemplo n.º 12
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }

            {
                BodyDef bd = new BodyDef();
                bd.position.set(0.0f, 0.0f);
                Body body = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));

                body.createFixture(shape, 0.0f);
            }

            {
                CircleShape circle1 = new CircleShape();
                circle1.m_radius = 0.5f;
                circle1.m_p.set(-0.5f, 0.5f);

                CircleShape circle2 = new CircleShape();
                ;
                circle2.m_radius = 0.5f;
                circle2.m_p.set(0.5f, 0.5f);

                for (int i = 0; i < 10; ++i)
                {
                    float x = MathUtils.randomFloat(-0.1f, 0.1f);
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(x + 5.0f, 1.05f + 2.5f*i);
                    bd.angle = MathUtils.randomFloat(-MathUtils.PI, MathUtils.PI);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(circle1, 2.0f);
                    body.createFixture(circle2, 0.0f);
                }
            }

            {
                PolygonShape polygon1 = new PolygonShape();
                polygon1.setAsBox(0.25f, 0.5f);

                PolygonShape polygon2 = new PolygonShape();
                polygon2.setAsBox(0.25f, 0.5f, new Vec2(0.0f, -0.5f), 0.5f*MathUtils.PI);

                for (int i = 0; i < 10; ++i)
                {
                    float x = MathUtils.randomFloat(-0.1f, 0.1f);
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(x - 5.0f, 1.05f + 2.5f*i);
                    bd.angle = MathUtils.randomFloat(-MathUtils.PI, MathUtils.PI);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(polygon1, 2.0f);
                    body.createFixture(polygon2, 2.0f);
                }
            }

            {
                Transform xf1 = new Transform();
                xf1.q.set(0.3524f*MathUtils.PI);
                Rot.mulToOut(xf1.q, new Vec2(1.0f, 0.0f), ref xf1.p);

                Vec2[] vertices = new Vec2[3];

                PolygonShape triangle1 = new PolygonShape();
                vertices[0] = Transform.mul(xf1, new Vec2(-1.0f, 0.0f));
                vertices[1] = Transform.mul(xf1, new Vec2(1.0f, 0.0f));
                vertices[2] = Transform.mul(xf1, new Vec2(0.0f, 0.5f));
                triangle1.set(vertices, 3);

                Transform xf2 = new Transform();
                xf2.q.set(-0.3524f*MathUtils.PI);
                Rot.mulToOut(xf2.q, new Vec2(-1.0f, 0.0f), ref xf2.p);

                PolygonShape triangle2 = new PolygonShape();
                vertices[0] = Transform.mul(xf2, new Vec2(-1.0f, 0.0f));
                vertices[1] = Transform.mul(xf2, new Vec2(1.0f, 0.0f));
                vertices[2] = Transform.mul(xf2, new Vec2(0.0f, 0.5f));
                triangle2.set(vertices, 3);

                for (int i = 0; i < 10; ++i)
                {
                    float x = MathUtils.randomFloat(-0.1f, 0.1f);
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(x, 2.05f + 2.5f*i);
                    bd.angle = 0.0f;
                    Body body = getWorld().createBody(bd);
                    body.createFixture(triangle1, 2.0f);
                    body.createFixture(triangle2, 2.0f);
                }
            }

            {
                PolygonShape bottom = new PolygonShape();
                bottom.setAsBox(1.5f, 0.15f);

                PolygonShape left = new PolygonShape();
                left.setAsBox(0.15f, 2.7f, new Vec2(-1.45f, 2.35f), 0.2f);

                PolygonShape right = new PolygonShape();
                right.setAsBox(0.15f, 2.7f, new Vec2(1.45f, 2.35f), -0.2f);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(0.0f, 2.0f);
                Body body = getWorld().createBody(bd);
                body.createFixture(bottom, 4.0f);
                body.createFixture(left, 4.0f);
                body.createFixture(right, 4.0f);
            }
        }
Ejemplo n.º 13
0
        public override void initTest(bool argDeserialized)
        {
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(50.0f, 0.0f), new Vec2(-50.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                CircleShape circle1 = new CircleShape();
                circle1.m_radius = 1.0f;

                PolygonShape box = new PolygonShape();
                box.setAsBox(0.5f, 5.0f);

                CircleShape circle2 = new CircleShape();
                circle2.m_radius = 2.0f;

                BodyDef bd1 = new BodyDef();
                bd1.type = BodyType.STATIC;
                bd1.position.set(10.0f, 9.0f);
                Body body1 = m_world.createBody(bd1);
                body1.createFixture(circle1, 5.0f);

                BodyDef bd2 = new BodyDef();
                bd2.type = BodyType.DYNAMIC;
                bd2.position.set(10.0f, 8.0f);
                Body body2 = m_world.createBody(bd2);
                body2.createFixture(box, 5.0f);

                BodyDef bd3 = new BodyDef();
                bd3.type = BodyType.DYNAMIC;
                bd3.position.set(10.0f, 6.0f);
                Body body3 = m_world.createBody(bd3);
                body3.createFixture(circle2, 5.0f);

                RevoluteJointDef jd1 = new RevoluteJointDef();
                jd1.initialize(body2, body1, bd1.position);
                Joint joint1 = m_world.createJoint(jd1);

                RevoluteJointDef jd2 = new RevoluteJointDef();
                jd2.initialize(body2, body3, bd3.position);
                Joint joint2 = m_world.createJoint(jd2);

                GearJointDef jd4 = new GearJointDef();
                jd4.bodyA = body1;
                jd4.bodyB = body3;
                jd4.joint1 = joint1;
                jd4.joint2 = joint2;
                jd4.ratio = circle2.m_radius/circle1.m_radius;
                m_world.createJoint(jd4);
            }

            {
                CircleShape circle1 = new CircleShape();
                circle1.m_radius = 1.0f;

                CircleShape circle2 = new CircleShape();
                circle2.m_radius = 2.0f;

                PolygonShape box = new PolygonShape();
                box.setAsBox(0.5f, 5.0f);

                BodyDef bd1 = new BodyDef();
                bd1.type = BodyType.DYNAMIC;
                bd1.position.set(-3.0f, 12.0f);
                Body body1 = m_world.createBody(bd1);
                body1.createFixture(circle1, 5.0f);

                RevoluteJointDef jd1 = new RevoluteJointDef();
                jd1.bodyA = ground;
                jd1.bodyB = body1;
                ground.getLocalPointToOut(bd1.position, ref jd1.localAnchorA);
                body1.getLocalPointToOut(bd1.position, ref jd1.localAnchorB);
                jd1.referenceAngle = body1.getAngle() - ground.getAngle();
                m_joint1 = (RevoluteJoint) m_world.createJoint(jd1);

                BodyDef bd2 = new BodyDef();
                bd2.type = BodyType.DYNAMIC;
                bd2.position.set(0.0f, 12.0f);
                Body body2 = m_world.createBody(bd2);
                body2.createFixture(circle2, 5.0f);

                RevoluteJointDef jd2 = new RevoluteJointDef();
                jd2.initialize(ground, body2, bd2.position);
                m_joint2 = (RevoluteJoint) m_world.createJoint(jd2);

                BodyDef bd3 = new BodyDef();
                bd3.type = BodyType.DYNAMIC;
                bd3.position.set(2.5f, 12.0f);
                Body body3 = m_world.createBody(bd3);
                body3.createFixture(box, 5.0f);

                PrismaticJointDef jd3 = new PrismaticJointDef();
                jd3.initialize(ground, body3, bd3.position, new Vec2(0.0f, 1.0f));
                jd3.lowerTranslation = -5.0f;
                jd3.upperTranslation = 5.0f;
                jd3.enableLimit = true;

                m_joint3 = (PrismaticJoint) m_world.createJoint(jd3);

                GearJointDef jd4 = new GearJointDef();
                jd4.bodyA = body1;
                jd4.bodyB = body2;
                jd4.joint1 = m_joint1;
                jd4.joint2 = m_joint2;
                jd4.ratio = circle2.m_radius/circle1.m_radius;
                m_joint4 = (GearJoint) m_world.createJoint(jd4);

                GearJointDef jd5 = new GearJointDef();
                jd5.bodyA = body2;
                jd5.bodyB = body3;
                jd5.joint1 = m_joint2;
                jd5.joint2 = m_joint3;
                jd5.ratio = 1f/circle2.m_radius;
                m_joint5 = (GearJoint) m_world.createJoint(jd5);
            }
        }
Ejemplo n.º 14
0
        public override void initTest(bool argDeserialized)
        {
            // Ground body
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                Vec2[] vertices = new Vec2[3];
                vertices[0] = new Vec2(-0.5f, 0.0f);
                vertices[1] = new Vec2(0.5f, 0.0f);
                vertices[2] = new Vec2(0.0f, 1.5f);
                m_polygons[0] = new PolygonShape();
                m_polygons[0].set(vertices, 3);
            }

            {
                Vec2[] vertices = new Vec2[3];
                vertices[0] = new Vec2(-0.1f, 0.0f);
                vertices[1] = new Vec2(0.1f, 0.0f);
                vertices[2] = new Vec2(0.0f, 1.5f);
                m_polygons[1] = new PolygonShape();
                m_polygons[1].set(vertices, 3);
            }

            {
                float w = 1.0f;
                float b = w/(2.0f + MathUtils.sqrt(2.0f));
                float s = MathUtils.sqrt(2.0f)*b;

                Vec2[] vertices = new Vec2[8];
                vertices[0] = new Vec2(0.5f*s, 0.0f);
                vertices[1] = new Vec2(0.5f*w, b);
                vertices[2] = new Vec2(0.5f*w, b + s);
                vertices[3] = new Vec2(0.5f*s, w);
                vertices[4] = new Vec2(-0.5f*s, w);
                vertices[5] = new Vec2(-0.5f*w, b + s);
                vertices[6] = new Vec2(-0.5f*w, b);
                vertices[7] = new Vec2(-0.5f*s, 0.0f);

                m_polygons[2] = new PolygonShape();
                m_polygons[2].set(vertices, 8);
            }

            {
                m_polygons[3] = new PolygonShape();
                m_polygons[3].setAsBox(0.5f, 0.5f);
            }

            {
                m_circle = new CircleShape();
                m_circle.m_radius = 0.5f;
            }

            m_bodyIndex = 0;
        }
Ejemplo n.º 15
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            // Ground
            {

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-20.0f, 0.0f), new Vec2(20.0f, 0.0f));
                getGroundBody().createFixture(shape, 0.0f);
            }

            // Platform
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-5.0f, 5.0f);
                Body body = getWorld().createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(10.0f, 0.5f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.friction = 0.8f;
                m_platform = body.createFixture(fd);
            }

            // Boxes
            for (int i = 0; i < 5; ++i)
            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-10.0f + 2.0f*i, 7.0f);
                Body body = m_world.createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.5f);
                body.createFixture(shape, 20.0f);
            }
        }
Ejemplo n.º 16
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(2.0f, 0.5f);

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-10.0f, 10.0f);
                bd.angle = 0.5f*MathUtils.PI;
                bd.allowSleep = false;
                Body body = getWorld().createBody(bd);
                body.createFixture(shape, 5.0f);

                PrismaticJointDef pjd = new PrismaticJointDef();

                // Bouncy limit
                Vec2 axis = new Vec2(2.0f, 1.0f);
                axis.normalize();
                pjd.initialize(ground, body, new Vec2(0.0f, 0.0f), axis);

                // Non-bouncy limit
                // pjd.Initialize(ground, body, Vec2(-10.0f, 10.0f), Vec2(1.0f, 0.0f));

                pjd.motorSpeed = 10.0f;
                pjd.maxMotorForce = 10000.0f;
                pjd.enableMotor = true;
                pjd.lowerTranslation = 0.0f;
                pjd.upperTranslation = 20.0f;
                pjd.enableLimit = true;

                m_joint = (PrismaticJoint) getWorld().createJoint(pjd);
            }
        }
Ejemplo n.º 17
0
        public override void initTest(bool argDeserialized)
        {
            if (argDeserialized)
            {
                return;
            }

            {
                // Floor
                FixtureDef fd = new FixtureDef();
                PolygonShape sd = new PolygonShape();
                sd.setAsBox(50.0f, 10.0f);
                fd.shape = sd;

                BodyDef bd = new BodyDef();
                bd.position = new Vec2(0.0f, -10.0f);
                getWorld().createBody(bd).createFixture(fd);

            }

            {
                // Platforms
                for (int i = 0; i < 4; i++)
                {
                    FixtureDef fd = new FixtureDef();
                    PolygonShape sd = new PolygonShape();
                    sd.setAsBox(15.0f, 0.125f);
                    fd.shape = sd;

                    BodyDef bd = new BodyDef();
                    bd.position = new Vec2(0.0f, 5f + 5f*i);
                    getWorld().createBody(bd).createFixture(fd);
                }
            }

            {
                FixtureDef fd = new FixtureDef();
                PolygonShape sd = new PolygonShape();
                sd.setAsBox(0.125f, 2f);
                fd.shape = sd;
                fd.density = 25.0f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                float friction = .5f;
                int numPerRow = 25;

                for (int i = 0; i < 4; ++i)
                {
                    for (int j = 0; j < numPerRow; j++)
                    {
                        fd.friction = friction;
                        bd.position = new Vec2(-14.75f + j*(29.5f/(numPerRow - 1)), 7.3f + 5f*i);
                        if (i == 2 && j == 0)
                        {
                            bd.angle = -0.1f;
                            bd.position.x += .1f;
                        }
                        else if (i == 3 && j == numPerRow - 1)
                        {
                            bd.angle = .1f;
                            bd.position.x -= .1f;
                        }
                        else
                            bd.angle = 0f;
                        Body myBody = getWorld().createBody(bd);
                        myBody.createFixture(fd);
                    }
                }
            }
        }
Ejemplo n.º 18
0
        private void createLeg(float s, Vec2 wheelAnchor)
        {
            Vec2 p1 = new Vec2(5.4f*s, -6.1f);
            Vec2 p2 = new Vec2(7.2f*s, -1.2f);
            Vec2 p3 = new Vec2(4.3f*s, -1.9f);
            Vec2 p4 = new Vec2(3.1f*s, 0.8f);
            Vec2 p5 = new Vec2(6.0f*s, 1.5f);
            Vec2 p6 = new Vec2(2.5f*s, 3.7f);

            FixtureDef fd1 = new FixtureDef();
            FixtureDef fd2 = new FixtureDef();
            fd1.filter.groupIndex = -1;
            fd2.filter.groupIndex = -1;
            fd1.density = 1.0f;
            fd2.density = 1.0f;

            PolygonShape poly1 = new PolygonShape();
            PolygonShape poly2 = new PolygonShape();

            if (s > 0.0f)
            {
                Vec2[] vertices = new Vec2[3];

                vertices[0] = p1;
                vertices[1] = p2;
                vertices[2] = p3;
                poly1.set(vertices, 3);

                vertices[0] = new Vec2();
                vertices[1] = p5.sub(p4);
                vertices[2] = p6.sub(p4);
                poly2.set(vertices, 3);
            }
            else
            {
                Vec2[] vertices = new Vec2[3];

                vertices[0] = p1;
                vertices[1] = p3;
                vertices[2] = p2;
                poly1.set(vertices, 3);

                vertices[0] = new Vec2();
                vertices[1] = p6.sub(p4);
                vertices[2] = p5.sub(p4);
                poly2.set(vertices, 3);
            }

            fd1.shape = poly1;
            fd2.shape = poly2;

            BodyDef bd1 = new BodyDef(), bd2 = new BodyDef();
            bd1.type = BodyType.DYNAMIC;
            bd2.type = BodyType.DYNAMIC;
            bd1.position = m_offset;
            bd2.position = p4.add(m_offset);

            bd1.angularDamping = 10.0f;
            bd2.angularDamping = 10.0f;

            Body body1 = getWorld().createBody(bd1);
            Body body2 = getWorld().createBody(bd2);

            body1.createFixture(fd1);
            body2.createFixture(fd2);

            DistanceJointDef djd = new DistanceJointDef();

            // Using a soft distance constraint can reduce some jitter.
            // It also makes the structure seem a bit more fluid by
            // acting like a suspension system.
            djd.dampingRatio = 0.5f;
            djd.frequencyHz = 10.0f;

            djd.initialize(body1, body2, p2.add(m_offset), p5.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body1, body2, p3.add(m_offset), p4.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body1, m_wheel, p3.add(m_offset), wheelAnchor.add(m_offset));
            getWorld().createJoint(djd);

            djd.initialize(body2, m_wheel, p6.add(m_offset), wheelAnchor.add(m_offset));
            getWorld().createJoint(djd);

            RevoluteJointDef rjd = new RevoluteJointDef();

            rjd.initialize(body2, m_chassis, p4.add(m_offset));
            getWorld().createJoint(rjd);
        }
Ejemplo n.º 19
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            // Ground body
            {
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));

                FixtureDef sd = new FixtureDef();
                sd.shape = shape;
                sd.friction = 0.3f;

                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);
                ground.createFixture(sd);
            }

            // Small triangle
            Vec2[] vertices = new Vec2[3];
            vertices[0] = new Vec2(-1.0f, 0.0f);
            vertices[1] = new Vec2(1.0f, 0.0f);
            vertices[2] = new Vec2(0.0f, 2.0f);
            PolygonShape polygon = new PolygonShape();
            polygon.set(vertices, 3);

            FixtureDef triangleShapeDef = new FixtureDef();
            triangleShapeDef.shape = polygon;
            triangleShapeDef.density = 1.0f;

            triangleShapeDef.filter.groupIndex = k_smallGroup;
            triangleShapeDef.filter.categoryBits = k_triangleCategory;
            triangleShapeDef.filter.maskBits = k_triangleMask;

            BodyDef triangleBodyDef = new BodyDef();
            triangleBodyDef.type = BodyType.DYNAMIC;
            triangleBodyDef.position.set(-5.0f, 2.0f);

            Body body1 = getWorld().createBody(triangleBodyDef);
            body1.createFixture(triangleShapeDef);

            // Large triangle (recycle definitions)
            vertices[0].mulLocal(2.0f);
            vertices[1].mulLocal(2.0f);
            vertices[2].mulLocal(2.0f);
            polygon.set(vertices, 3);
            triangleShapeDef.filter.groupIndex = k_largeGroup;
            triangleBodyDef.position.set(-5.0f, 6.0f);
            triangleBodyDef.fixedRotation = true; // look at me!

            Body body2 = getWorld().createBody(triangleBodyDef);
            body2.createFixture(triangleShapeDef);

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-5.0f, 10.0f);
                Body body = getWorld().createBody(bd);

                PolygonShape p = new PolygonShape();
                p.setAsBox(0.5f, 1.0f);
                body.createFixture(p, 1.0f);

                PrismaticJointDef jd = new PrismaticJointDef();
                jd.bodyA = body2;
                jd.bodyB = body;
                jd.enableLimit = true;
                jd.localAnchorA.set(0.0f, 4.0f);
                jd.localAnchorB.setZero();
                jd.localAxisA.set(0.0f, 1.0f);
                jd.lowerTranslation = -1.0f;
                jd.upperTranslation = 1.0f;

                getWorld().createJoint(jd);
            }

            // Small box
            polygon.setAsBox(1.0f, 0.5f);
            FixtureDef boxShapeDef = new FixtureDef();
            boxShapeDef.shape = polygon;
            boxShapeDef.density = 1.0f;
            boxShapeDef.restitution = 0.1f;

            boxShapeDef.filter.groupIndex = k_smallGroup;
            boxShapeDef.filter.categoryBits = k_boxCategory;
            boxShapeDef.filter.maskBits = k_boxMask;

            BodyDef boxBodyDef = new BodyDef();
            boxBodyDef.type = BodyType.DYNAMIC;
            boxBodyDef.position.set(0.0f, 2.0f);

            Body body3 = getWorld().createBody(boxBodyDef);
            body3.createFixture(boxShapeDef);

            // Large box (recycle definitions)
            polygon.setAsBox(2.0f, 1.0f);
            boxShapeDef.filter.groupIndex = k_largeGroup;
            boxBodyDef.position.set(0.0f, 6.0f);

            Body body4 = getWorld().createBody(boxBodyDef);
            body4.createFixture(boxShapeDef);

            // Small circle
            CircleShape circle = new CircleShape();
            circle.m_radius = 1.0f;

            FixtureDef circleShapeDef = new FixtureDef();
            circleShapeDef.shape = circle;
            circleShapeDef.density = 1.0f;

            circleShapeDef.filter.groupIndex = k_smallGroup;
            circleShapeDef.filter.categoryBits = k_circleCategory;
            circleShapeDef.filter.maskBits = k_circleMask;

            BodyDef circleBodyDef = new BodyDef();
            circleBodyDef.type = BodyType.DYNAMIC;
            circleBodyDef.position.set(5.0f, 2.0f);

            Body body5 = getWorld().createBody(circleBodyDef);
            body5.createFixture(circleShapeDef);

            // Large circle
            circle.m_radius *= 2.0f;
            circleShapeDef.filter.groupIndex = k_largeGroup;
            circleBodyDef.position.set(5.0f, 6.0f);

            Body body6 = getWorld().createBody(circleBodyDef);
            body6.createFixture(circleShapeDef);
        }
Ejemplo n.º 20
0
        public override void initTest(bool deserialized)
        {
            {
                BodyDef bd = new BodyDef();
                Body ground = m_world.createBody(bd);

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(-40, -10), new Vec2(40, -10), new Vec2(40, 0), new Vec2(-40, 0)};
                    shape.set(vertices, 4);
                    ground.createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(-40, -1), new Vec2(-20, -1), new Vec2(-20, 20), new Vec2(-40, 30)};
                    shape.set(vertices, 4);
                    ground.createFixture(shape, 0.0f);
                }

                {
                    PolygonShape shape = new PolygonShape();
                    Vec2[] vertices =
                        new Vec2[] {new Vec2(20, -1), new Vec2(40, -1), new Vec2(40, 30), new Vec2(20, 20)};
                    shape.set(vertices, 4);
                    ground.createFixture(shape, 0.0f);
                }
            }

            m_world.setParticleRadius(0.2f);
            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(20, 10, new Vec2(0, 10), 0);
                ParticleGroupDef pd = new ParticleGroupDef();
                pd.flags = flags;
                pd.shape = shape;
                m_world.createParticleGroup(pd);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.KINEMATIC;
                Body body = m_world.createBody(bd);
                circle = body;
                CircleShape shape = new CircleShape();
                shape.m_p.set(0, 5);
                shape.m_radius = 1;
                body.createFixture(shape, 0.1f);
                body.setLinearVelocity(new Vec2(-6, 0.0f));
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(1, 1, new Vec2(-10, 5), 0);
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(1, 1, new Vec2(10, 5), 0.5f);
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(0, 20), new Vec2(1, 21));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(3, 20), new Vec2(4, 21));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-3, 21), new Vec2(-2, 20));
                body.createFixture(shape, 0.1f);
            }
        }
Ejemplo n.º 21
0
        public override void initTest(bool deserialized)
        {
            {
                BodyDef bd = new BodyDef();
                Body ground = m_world.createBody(bd);

                ChainShape shape = new ChainShape();
                Vec2[] vertices =
                    new Vec2[] {new Vec2(-20, 0), new Vec2(20, 0), new Vec2(20, 40), new Vec2(-20, 40)};
                shape.createLoop(vertices, 4);
                ground.createFixture(shape, 0.0f);

            }

            m_world.setParticleRadius(0.15f);
            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(20, 4, new Vec2(0, 36), 0);
                ParticleGroupDef pd = new ParticleGroupDef();
                pd.flags = ParticleType.b2_tensileParticle | ParticleType.b2_viscousParticle;
                pd.shape = shape;
                m_world.createParticleGroup(pd);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-20, 32), new Vec2(-12, 32));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-11, 32), new Vec2(20, 32));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-12, 32), new Vec2(-12, 28));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-11, 32), new Vec2(-11, 28));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-16, 24), new Vec2(8, 20));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(16, 16), new Vec2(-8, 12));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-12, 8), new Vec2(-12, 0));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-4, 8), new Vec2(-4, 0));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(4, 8), new Vec2(4, 0));
                body.createFixture(shape, 0.1f);
            }

            {
                BodyDef bd = new BodyDef();
                Body body = m_world.createBody(bd);
                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(12, 8), new Vec2(12, 0));
                body.createFixture(shape, 0.1f);
            }
        }
Ejemplo n.º 22
0
 public override Shape clone()
 {
     PolygonShape shape = new PolygonShape();
     shape.m_centroid.set(this.m_centroid);
     for (int i = 0; i < shape.m_normals.Length; i++)
     {
         shape.m_normals[i].set(m_normals[i]);
         shape.m_vertices[i].set(m_vertices[i]);
     }
     shape.setRadius(this.getRadius());
     shape.m_count = this.m_count;
     return shape;
 }
Ejemplo n.º 23
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }

            getWorld().setGravity(new Vec2(0.0f, 0.0f));

            float k_restitution = 0.4f;

            Body ground;
            {
                BodyDef bd = new BodyDef();
                bd.position.set(0.0f, 20.0f);
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();

                FixtureDef sd = new FixtureDef();
                sd.shape = shape;
                sd.density = 0.0f;
                sd.restitution = k_restitution;

                // Left vertical
                shape.set(new Vec2(-20.0f, -20.0f), new Vec2(-20.0f, 20.0f));
                ground.createFixture(sd);

                // Right vertical
                shape.set(new Vec2(20.0f, -20.0f), new Vec2(20.0f, 20.0f));
                ground.createFixture(sd);

                // Top horizontal
                shape.set(new Vec2(-20.0f, 20.0f), new Vec2(20.0f, 20.0f));
                ground.createFixture(sd);

                // Bottom horizontal
                shape.set(new Vec2(-20.0f, -20.0f), new Vec2(20.0f, -20.0f));
                ground.createFixture(sd);
            }

            {
                Transform xf1 = new Transform();
                xf1.q.set(0.3524f*MathUtils.PI);
                Rot.mulToOutUnsafe(xf1.q, new Vec2(1.0f, 0.0f), ref xf1.p);

                Vec2[] vertices = new Vec2[3];
                vertices[0] = Transform.mul(xf1, new Vec2(-1.0f, 0.0f));
                vertices[1] = Transform.mul(xf1, new Vec2(1.0f, 0.0f));
                vertices[2] = Transform.mul(xf1, new Vec2(0.0f, 0.5f));

                PolygonShape poly1 = new PolygonShape();
                poly1.set(vertices, 3);

                FixtureDef sd1 = new FixtureDef();
                sd1.shape = poly1;
                sd1.density = 4.0f;

                Transform xf2 = new Transform();
                xf2.q.set(-0.3524f*MathUtils.PI);
                Rot.mulToOut(xf2.q, new Vec2(-1.0f, 0.0f), ref xf2.p);

                vertices[0] = Transform.mul(xf2, new Vec2(-1.0f, 0.0f));
                vertices[1] = Transform.mul(xf2, new Vec2(1.0f, 0.0f));
                vertices[2] = Transform.mul(xf2, new Vec2(0.0f, 0.5f));

                PolygonShape poly2 = new PolygonShape();
                poly2.set(vertices, 3);

                FixtureDef sd2 = new FixtureDef();
                sd2.shape = poly2;
                sd2.density = 2.0f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.angularDamping = 2.0f;
                bd.linearDamping = 0.5f;

                bd.position.set(0.0f, 2.0f);
                bd.angle = MathUtils.PI;
                bd.allowSleep = false;
                m_body = getWorld().createBody(bd);
                m_body.createFixture(sd1);
                m_body.createFixture(sd2);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.5f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;
                fd.friction = 0.3f;

                for (int i = 0; i < 10; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;

                    bd.position.set(0.0f, 5.0f + 1.54f*i);
                    Body body = getWorld().createBody(bd);

                    body.createFixture(fd);

                    float gravity = 10.0f;
                    float I = body.getInertia();
                    float mass = body.getMass();

                    // For a circle: I = 0.5 * m * r * r ==> r = sqrt(2 * I / m)
                    float radius = MathUtils.sqrt(2.0f*I/mass);

                    FrictionJointDef jd = new FrictionJointDef();
                    jd.localAnchorA.setZero();
                    jd.localAnchorB.setZero();
                    jd.bodyA = ground;
                    jd.bodyB = body;
                    jd.collideConnected = true;
                    jd.maxForce = mass*gravity;
                    jd.maxTorque = mass*radius*gravity;

                    getWorld().createJoint(jd);
                }
            }
        }
Ejemplo n.º 24
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                CircleShape shape = new CircleShape();
                shape.m_radius = 0.5f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;

                RevoluteJointDef rjd = new RevoluteJointDef();

                bd.position.set(-10f, 20.0f);
                Body body = getWorld().createBody(bd);
                body.createFixture(shape, 5.0f);

                float w = 100.0f;
                body.setAngularVelocity(w);
                body.setLinearVelocity(new Vec2(-8.0f*w, 0.0f));

                rjd.initialize(ground, body, new Vec2(-10.0f, 12.0f));
                rjd.motorSpeed = -1.0f*MathUtils.PI;
                rjd.maxMotorTorque = 10000.0f;
                rjd.enableMotor = false;
                rjd.lowerAngle = -0.25f*MathUtils.PI;
                rjd.upperAngle = 0.5f*MathUtils.PI;
                rjd.enableLimit = true;
                rjd.collideConnected = true;

                m_joint = (RevoluteJoint) getWorld().createJoint(rjd);
            }

            {
                CircleShape circle_shape = new CircleShape();
                circle_shape.m_radius = 3.0f;

                BodyDef circle_bd = new BodyDef();
                circle_bd.type = BodyType.DYNAMIC;
                circle_bd.position.set(5.0f, 30.0f);

                FixtureDef fd = new FixtureDef();
                fd.density = 5.0f;
                fd.filter.maskBits = 1;
                fd.shape = circle_shape;

                Body ball = m_world.createBody(circle_bd);
                ball.createFixture(fd);

                PolygonShape polygon_shape = new PolygonShape();
                polygon_shape.setAsBox(10.0f, 0.2f, new Vec2(-10.0f, 0.0f), 0.0f);

                BodyDef polygon_bd = new BodyDef();
                polygon_bd.position.set(20.0f, 10.0f);
                polygon_bd.type = BodyType.DYNAMIC;
                polygon_bd.bullet = true;
                Body polygon_body = m_world.createBody(polygon_bd);
                polygon_body.createFixture(polygon_shape, 2.0f);

                RevoluteJointDef rjd = new RevoluteJointDef();
                rjd.initialize(ground, polygon_body, new Vec2(20.0f, 10.0f));
                rjd.lowerAngle = -0.25f*MathUtils.PI;
                rjd.upperAngle = 0.0f*MathUtils.PI;
                rjd.enableLimit = true;
                m_world.createJoint(rjd);
            }

            // Tests mass computation of a small object far from the origin
            {
                BodyDef bodyDef = new BodyDef();
                bodyDef.type = BodyType.DYNAMIC;
                Body body = m_world.createBody(bodyDef);

                PolygonShape polyShape = new PolygonShape();
                Vec2[] verts = new Vec2[3];
                verts[0] = new Vec2(17.63f, 36.31f);
                verts[1] = new Vec2(17.52f, 36.69f);
                verts[2] = new Vec2(17.19f, 36.36f);
                polyShape.set(verts, 3);

                FixtureDef polyFixtureDef = new FixtureDef();
                polyFixtureDef.shape = polyShape;
                polyFixtureDef.density = 1;

                body.createFixture(polyFixtureDef); // assertion hits inside here
            }
        }
Ejemplo n.º 25
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            Body pendulum;
            Body pendulumBase;
            Body ground;

            {
                CircleShape circleShape = new CircleShape();
                circleShape.m_radius = 1;
                Shape shape = circleShape;

                BodyDef bodyDef = new BodyDef();
                bodyDef.type = BodyType.DYNAMIC;
                bodyDef.position.set(-5, 0);
                bodyDef.allowSleep = false;
                pendulum = getWorld().createBody(bodyDef);
                pendulum.createFixture(shape, 1);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(1, 1);

                BodyDef bodyDef = new BodyDef();
                bodyDef.type = BodyType.DYNAMIC;
                bodyDef.position.set(0, 2);
                bodyDef.allowSleep = false;
                pendulumBase = getWorld().createBody(bodyDef);
                pendulumBase.createFixture(shape, 1);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(3, 1);

                BodyDef bodyDef = new BodyDef();
                bodyDef.type = BodyType.STATIC;
                ground = getWorld().createBody(bodyDef);
                ground.createFixture(shape, 0);
            }

            RevoluteJointDef jointDef = new RevoluteJointDef();

            if (switchBodiesInJoint)
                jointDef.initialize(pendulum, pendulumBase, new Vec2(0, 0));
            else
                jointDef.initialize(pendulumBase, pendulum, new Vec2(0, 0));

            getWorld().createJoint(jointDef);
        }
Ejemplo n.º 26
0
 public void makeDomino(float x, float y, bool horizontal, World world)
 {
     PolygonShape sd = new PolygonShape();
     sd.setAsBox(.5f*dwidth, .5f*dheight);
     FixtureDef fd = new FixtureDef();
     fd.shape = sd;
     fd.density = ddensity;
     BodyDef bd = new BodyDef();
     bd.type = BodyType.DYNAMIC;
     fd.friction = dfriction;
     fd.restitution = 0.65f;
     bd.position = new Vec2(x, y);
     bd.angle = horizontal ? (float) (System.Math.PI/2.0) : 0f;
     Body myBody = getWorld().createBody(bd);
     myBody.createFixture(fd);
 }
Ejemplo n.º 27
0
        public override void initTest(bool argDeserialized)
        {
            if (argDeserialized)
            {
                return;
            }
            Body ground = null;
            {
                BodyDef bd = new BodyDef();
                ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.125f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                WeldJointDef jd = new WeldJointDef();

                Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(-14.5f + 1.0f*i, 5.0f);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(fd);

                    Vec2 anchor = new Vec2(-15.0f + 1.0f*i, 5.0f);
                    jd.initialize(prevBody, body, anchor);
                    getWorld().createJoint(jd);

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(1f, 0.125f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                WeldJointDef jd = new WeldJointDef();
                jd.frequencyHz = 5f;
                jd.dampingRatio = .7f;

                Body prevBody = ground;
                for (int i = 0; i < 3; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(-14.0f + 2.0f*i, 15.0f);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(fd);

                    Vec2 anchor = new Vec2(-15.0f + 2.0f*i, 15.0f);
                    jd.initialize(prevBody, body, anchor);
                    getWorld().createJoint(jd);

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.125f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                WeldJointDef jd = new WeldJointDef();

                Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(-4.5f + 1.0f*i, 5.0f);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(fd);

                    if (i > 0)
                    {
                        Vec2 anchor = new Vec2(-5.0f + 1.0f*i, 5.0f);
                        jd.initialize(prevBody, body, anchor);
                        getWorld().createJoint(jd);
                    }

                    prevBody = body;
                }
            }

            {
                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.5f, 0.125f);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;

                WeldJointDef jd = new WeldJointDef();
                jd.frequencyHz = 8f;
                jd.dampingRatio = .7f;

                Body prevBody = ground;
                for (int i = 0; i < e_count; ++i)
                {
                    BodyDef bd = new BodyDef();
                    bd.type = BodyType.DYNAMIC;
                    bd.position.set(5.5f + 1.0f*i, 10.0f);
                    Body body = getWorld().createBody(bd);
                    body.createFixture(fd);

                    if (i > 0)
                    {
                        Vec2 anchor = new Vec2(5.0f + 1.0f*i, 10.0f);
                        jd.initialize(prevBody, body, anchor);
                        getWorld().createJoint(jd);
                    }

                    prevBody = body;
                }
            }

            for (int i = 0; i < 2; ++i)
            {
                Vec2[] vertices = new Vec2[3];
                vertices[0] = new Vec2(-0.5f, 0.0f);
                vertices[1] = new Vec2(0.5f, 0.0f);
                vertices[2] = new Vec2(0.0f, 1.5f);

                PolygonShape shape = new PolygonShape();
                shape.set(vertices, 3);

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-8.0f + 8.0f*i, 12.0f);
                Body body = getWorld().createBody(bd);
                body.createFixture(fd);
            }

            for (int i = 0; i < 2; ++i)
            {
                CircleShape shape = new CircleShape();
                shape.m_radius = 0.5f;

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 1.0f;

                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(-6.0f + 6.0f*i, 10.0f);
                Body body = getWorld().createBody(bd);
                body.createFixture(fd);
            }
        }
Ejemplo n.º 28
0
        public override void initTest(bool argDeserialized)
        {
            if (argDeserialized)
            {
                return;
            }

            {
                // Floor
                PolygonShape sd = new PolygonShape();
                sd.setAsBox(50.0f, 10.0f);

                BodyDef bd = new BodyDef();
                bd.position = new Vec2(0.0f, -10.0f);
                getWorld().createBody(bd).createFixture(sd, 0f);
            }

            {
                ddensity = 10f;
                // Make bullet
                PolygonShape sd = new PolygonShape();
                sd.setAsBox(.7f, .7f);
                FixtureDef fd = new FixtureDef();
                fd.density = 35f;
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                fd.shape = sd;
                fd.friction = 0f;
                fd.restitution = 0.85f;
                bd.bullet = true;
                // bd.addShape(sd);
                bd.position = new Vec2(30f, 50f);
                Body b = getWorld().createBody(bd);
                b.createFixture(fd);
                b.setLinearVelocity(new Vec2(-25f, -25f));
                b.setAngularVelocity(6.7f);

                fd.density = 25f;
                bd.position = new Vec2(-30, 25f);
                b = getWorld().createBody(bd);
                b.createFixture(fd);
                b.setLinearVelocity(new Vec2(35f, -10f));
                b.setAngularVelocity(-8.3f);
            }

            {
                float currX;
                // Make base
                for (int i = 0; i < baseCount; ++i)
                {
                    currX = i*1.5f*dheight - (1.5f*dheight*baseCount/2f);
                    makeDomino(currX, dheight/2.0f, false, m_world);
                    makeDomino(currX, dheight + dwidth/2.0f, true, m_world);
                }
                currX = baseCount*1.5f*dheight - (1.5f*dheight*baseCount/2f);
                // Make 'I's
                for (int j = 1; j < baseCount; ++j)
                {
                    if (j > 3)
                        ddensity *= .8f;
                    float currY = dheight*.5f + (dheight + 2f*dwidth)*.99f*j; // y at center of 'I'
                    // structure

                    for (int i = 0; i < baseCount - j; ++i)
                    {
                        currX = i*1.5f*dheight - (1.5f*dheight*(baseCount - j)/2f); // +
                        // parent.random(-.05f,
                        // .05f);
                        ddensity *= 2.5f;
                        if (i == 0)
                        {
                            makeDomino(currX - (1.25f*dheight) + .5f*dwidth, currY - dwidth, false, m_world);
                        }
                        if (i == baseCount - j - 1)
                        {
                            // if (j != 1) //djm: why is this here? it makes it off balance
                            makeDomino(currX + (1.25f*dheight) - .5f*dwidth, currY - dwidth, false, m_world);
                        }
                        ddensity /= 2.5f;
                        makeDomino(currX, currY, false, m_world);
                        makeDomino(currX, currY + .5f*(dwidth + dheight), true, m_world);
                        makeDomino(currX, currY - .5f*(dwidth + dheight), true, m_world);
                    }
                }
            }
        }
Ejemplo n.º 29
0
        public override void initTest(bool argDeserialized)
        {
            // Ground body
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.set(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
                ground.createFixture(shape, 0.0f);
            }

            // Breakable dynamic body
            {
                BodyDef bd = new BodyDef();
                bd.type = BodyType.DYNAMIC;
                bd.position.set(0.0f, 40.0f);
                bd.angle = 0.25f*MathUtils.PI;
                m_body1 = getWorld().createBody(bd);

                m_shape1 = new PolygonShape();
                m_shape1.setAsBox(0.5f, 0.5f, new Vec2(-0.5f, 0.0f), 0.0f);
                m_piece1 = m_body1.createFixture(m_shape1, 1.0f);

                m_shape2 = new PolygonShape();
                m_shape2.setAsBox(0.5f, 0.5f, new Vec2(0.5f, 0.0f), 0.0f);
                m_piece2 = m_body1.createFixture(m_shape2, 1.0f);
            }

            m_break = false;
            m_broke = false;
        }
Ejemplo n.º 30
0
        public override void initTest(bool argDeserialized)
        {
            for (int i = 0; i < m_bodies.Length; i++)
            {
                m_bodies[i] = null;
            }
            // Ground body
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                float x1 = -20.0f;
                float y1 = 2.0f*MathUtils.cos(x1/10.0f*MathUtils.PI);
                for (int i = 0; i < 80; ++i)
                {
                    float x2 = x1 + 0.5f;
                    float y2 = 2.0f*MathUtils.cos(x2/10.0f*MathUtils.PI);

                    EdgeShape shape = new EdgeShape();
                    shape.set(new Vec2(x1, y1), new Vec2(x2, y2));
                    ground.createFixture(shape, 0.0f);

                    x1 = x2;
                    y1 = y2;
                }
            }

            {
                Vec2[] vertices = new Vec2[3];
                vertices[0] = new Vec2(-0.5f, 0.0f);
                vertices[1] = new Vec2(0.5f, 0.0f);
                vertices[2] = new Vec2(0.0f, 1.5f);
                m_polygons[0] = new PolygonShape();
                m_polygons[0].set(vertices, 3);
            }

            {
                Vec2[] vertices = new Vec2[3];
                vertices[0] = new Vec2(-0.1f, 0.0f);
                vertices[1] = new Vec2(0.1f, 0.0f);
                vertices[2] = new Vec2(0.0f, 1.5f);
                m_polygons[1] = new PolygonShape();
                m_polygons[1].set(vertices, 3);
            }

            {
                float w = 1.0f;
                float b = w/(2.0f + MathUtils.sqrt(2.0f));
                float s = MathUtils.sqrt(2.0f)*b;

                Vec2[] vertices = new Vec2[8];
                vertices[0] = new Vec2(0.5f*s, 0.0f);
                vertices[1] = new Vec2(0.5f*w, b);
                vertices[2] = new Vec2(0.5f*w, b + s);
                vertices[3] = new Vec2(0.5f*s, w);
                vertices[4] = new Vec2(-0.5f*s, w);
                vertices[5] = new Vec2(-0.5f*w, b + s);
                vertices[6] = new Vec2(-0.5f*w, b);
                vertices[7] = new Vec2(-0.5f*s, 0.0f);

                m_polygons[2] = new PolygonShape();
                m_polygons[2].set(vertices, 8);
            }

            {
                m_polygons[3] = new PolygonShape();
                m_polygons[3].setAsBox(0.5f, 0.5f);
            }

            {
                m_circle = new CircleShape();
                m_circle.m_radius = 0.5f;
            }

            m_bodyIndex = 0;
            m_angle = 0.0f;
        }