Package org.jbox2d.collision.shapes

Examples of org.jbox2d.collision.shapes.ChainShape


  private final EdgeShape edge = new EdgeShape();

  @Override
  public void evaluate (Manifold manifold, Transform xfA, Transform xfB) {
    ChainShape chain = (ChainShape)m_fixtureA.getShape();
    chain.getChildEdge(edge, m_indexA);
    pool.getCollision().collideEdgeAndPolygon(manifold, edge, xfA, (PolygonShape)m_fixtureB.getShape(), xfB);
  }
View Full Code Here


        for (int i = 0; i < m_count; i++) {
          m_vertices[i].set(poly.m_vertices[i]);
        }
        break;
      case CHAIN:
        final ChainShape chain = (ChainShape)shape;
        assert (0 <= index && index < chain.m_count);

        m_buffer[0] = chain.m_vertices[index];
        if (index + 1 < chain.m_count) {
          m_buffer[1] = chain.m_vertices[index + 1];
View Full Code Here

      m_debugDraw.drawSegment(v1, v2, color);
    }
      break;

    case CHAIN: {
      ChainShape chain = (ChainShape)fixture.getShape();
      int count = chain.m_count;
      Vec2[] vertices = chain.m_vertices;

      Transform.mulToOutUnsafe(xf, vertices[0], v1);
      for (int i = 1; i < count; ++i) {
View Full Code Here

      m_debugDraw.drawSegment(v1, v2, color);
    }
      break;

    case CHAIN: {
      ChainShape chain = (ChainShape)fixture.getShape();
      int count = chain.m_count;
      Vec2[] vertices = chain.m_vertices;

      Transform.mulToOutUnsafe(xf, vertices[0], v1);
      for (int i = 1; i < count; ++i) {
View Full Code Here

        builder.setV3(vecToPb(e.m_vertex3));
        builder.setHas0(e.m_hasVertex0);
        builder.setHas3(e.m_hasVertex3);
        break;
      case CHAIN:
        ChainShape h = (ChainShape) argShape;
        builder.setType(PbShapeType.CHAIN);
        for (int i = 0; i < h.m_count; i++) {
          builder.addPoints(vecToPb(h.m_vertices[i]));
        }
        builder.setPrev(vecToPb(h.m_prevVertex));
View Full Code Here

      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);
View Full Code Here

        edge.m_hasVertex0 = s.getHas0();
        edge.m_hasVertex3 = s.getHas3();
        shape = edge;
        break;
      case CHAIN: {
        ChainShape chain = new ChainShape();
        chain.m_count = s.getPointsCount();
        chain.m_vertices = new Vec2[chain.m_count];
        for (int i = 0; i < chain.m_count; i++) {
          chain.m_vertices[i] = new Vec2(pbToVec(s.getPoints(i)));
        }
View Full Code Here

  public void initTest(boolean 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);
    }
  }
View Full Code Here

  public void initTest(boolean deserialized) {
    {
      BodyDef bd = new BodyDef();
      Body ground = m_world.createBody(bd);

      ChainShape shape = new ChainShape();
      final 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);
    }
  }
View Full Code Here

TOP

Related Classes of org.jbox2d.collision.shapes.ChainShape

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.