예제 #1
0
 public override Shape clone()
 {
     ChainShape clone = new ChainShape();
     clone.createChain(m_vertices, m_count);
     clone.m_prevVertex.set(m_prevVertex);
     clone.m_nextVertex.set(m_nextVertex);
     clone.m_hasPrevVertex = m_hasPrevVertex;
     clone.m_hasNextVertex = m_hasNextVertex;
     return clone;
 }
예제 #2
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);
            }
        }
예제 #3
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);
            }
        }
예제 #4
0
        public override void initTest(bool deserialized)
        {
            if (deserialized)
            {
                return;
            }
            // Ground body
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

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

            // Collinear edges
            // This shows the problematic case where a box shape can hit
            // an internal vertex.
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                EdgeShape shape = new EdgeShape();
                shape.m_radius = 0.0f;
                shape.set(new Vec2(-8.0f, 1.0f), new Vec2(-6.0f, 1.0f));
                ground.createFixture(shape, 0.0f);
                shape.set(new Vec2(-6.0f, 1.0f), new Vec2(-4.0f, 1.0f));
                ground.createFixture(shape, 0.0f);
                shape.set(new Vec2(-4.0f, 1.0f), new Vec2(-2.0f, 1.0f));
                ground.createFixture(shape, 0.0f);
            }

            // Chain shape
            {
                BodyDef bd = new BodyDef();
                bd.angle = 0.25f*MathUtils.PI;
                Body ground = getWorld().createBody(bd);

                Vec2[] vs = new Vec2[4];
                vs[0] = new Vec2(5.0f, 7.0f);
                vs[1] = new Vec2(6.0f, 8.0f);
                vs[2] = new Vec2(7.0f, 8.0f);
                vs[3] = new Vec2(8.0f, 7.0f);
                ChainShape shape = new ChainShape();
                shape.createChain(vs, 4);
                ground.createFixture(shape, 0.0f);
            }

            // Square tiles. This shows that adjacency shapes may
            // have non-smooth collision. There is no solution
            // to this problem.
            {
                BodyDef bd = new BodyDef();
                Body ground = getWorld().createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(1.0f, 1.0f, new Vec2(4.0f, 3.0f), 0.0f);
                ground.createFixture(shape, 0.0f);
                shape.setAsBox(1.0f, 1.0f, new Vec2(6.0f, 3.0f), 0.0f);
                ground.createFixture(shape, 0.0f);
                shape.setAsBox(1.0f, 1.0f, new Vec2(8.0f, 3.0f), 0.0f);
                ground.createFixture(shape, 0.0f);
            }

            // Square made from an edge loop. Collision should be smooth.
            {
                BodyDef bd = new BodyDef();
                Body ground = m_world.createBody(bd);

                Vec2[] vs = new Vec2[4];
                vs[0] = new Vec2(-1.0f, 3.0f);
                vs[1] = new Vec2(1.0f, 3.0f);
                vs[2] = new Vec2(1.0f, 5.0f);
                vs[3] = new Vec2(-1.0f, 5.0f);
                ChainShape shape = new ChainShape();
                shape.createLoop(vs, 4);
                ground.createFixture(shape, 0.0f);
            }

            // Edge loop. Collision should be smooth.
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-10.0f, 4.0f);
                Body ground = getWorld().createBody(bd);

                Vec2[] vs = new Vec2[10];
                vs[0] = new Vec2(0.0f, 0.0f);
                vs[1] = new Vec2(6.0f, 0.0f);
                vs[2] = new Vec2(6.0f, 2.0f);
                vs[3] = new Vec2(4.0f, 1.0f);
                vs[4] = new Vec2(2.0f, 2.0f);
                vs[5] = new Vec2(0.0f, 2.0f);
                vs[6] = new Vec2(-2.0f, 2.0f);
                vs[7] = new Vec2(-4.0f, 3.0f);
                vs[8] = new Vec2(-6.0f, 2.0f);
                vs[9] = new Vec2(-6.0f, 0.0f);
                ChainShape shape = new ChainShape();
                shape.createLoop(vs, 10);
                ground.createFixture(shape, 0.0f);
            }

            // Square character 1
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-3.0f, 8.0f);
                bd.type = BodyType.DYNAMIC;
                bd.fixedRotation = true;
                bd.allowSleep = false;

                Body body = getWorld().createBody(bd);

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

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

            // Square character 2
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-5.0f, 5.0f);
                bd.type = BodyType.DYNAMIC;
                bd.fixedRotation = true;
                bd.allowSleep = false;

                Body body = getWorld().createBody(bd);

                PolygonShape shape = new PolygonShape();
                shape.setAsBox(0.25f, 0.25f);

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

            // Hexagon character
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-5.0f, 8.0f);
                bd.type = BodyType.DYNAMIC;
                bd.fixedRotation = true;
                bd.allowSleep = false;

                Body body = getWorld().createBody(bd);

                float angle = 0.0f;
                float delta = MathUtils.PI/3.0f;
                Vec2[] vertices = new Vec2[6];
                for (int i = 0; i < 6; ++i)
                {
                    vertices[i] = new Vec2(0.5f*MathUtils.cos(angle), 0.5f*MathUtils.sin(angle));
                    angle += delta;
                }

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

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

            // Circle character
            {
                BodyDef bd = new BodyDef();
                bd.position.set(3.0f, 5.0f);
                bd.type = BodyType.DYNAMIC;
                bd.fixedRotation = true;
                bd.allowSleep = false;

                Body body = getWorld().createBody(bd);

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

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

            // Circle character
            {
                BodyDef bd = new BodyDef();
                bd.position.set(-7.0f, 6.0f);
                bd.type = BodyType.DYNAMIC;
                bd.allowSleep = false;

                m_character = getWorld().createBody(bd);

                CircleShape shape = new CircleShape();
                shape.m_radius = 0.25f;

                FixtureDef fd = new FixtureDef();
                fd.shape = shape;
                fd.density = 20.0f;
                fd.friction = 1;
                m_character.createFixture(fd);
            }
        }