org.jbox2d.collision.shapes.Shape Java Examples

The following examples show how to use org.jbox2d.collision.shapes.Shape. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: PbSerializer.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public SerializationResult serialize(Shape argShape) {
  PbShape.Builder builder = serializeShape(argShape);
  if (builder == null) {
    return null;
  }
  // should we do lazy building?
  final PbShape shape = builder.build();
  return new SerializationResult() {
    @Override
    public void writeTo(OutputStream argOutputStream) throws IOException {
      shape.writeTo(argOutputStream);
    }

    @Override
    public Object getValue() {
      return shape;
    }
  };
}
 
Example #2
Source File: PolyShapes.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public boolean reportFixture(Fixture fixture) {
  if (m_count == e_maxCount) {
    return false;
  }

  Body body = fixture.getBody();
  Shape shape = fixture.getShape();

  boolean overlap = p.getCollision().testOverlap(shape, 0, m_circle, 0, body.getTransform(),
      m_transform);

  if (overlap) {
    DrawFixture(fixture);
    ++m_count;
  }

  return true;
}
 
Example #3
Source File: JBox2DSimulation.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private static void render() {
    renderingContext2D.setFillStyle("white");
    renderingContext2D.setStrokeStyle("black");
    renderingContext2D.fillRect(0, 0, 600, 600);
    renderingContext2D.save();
    renderingContext2D.translate(0, 600);
    renderingContext2D.scale(1, -1);
    renderingContext2D.scale(100, 100);
    renderingContext2D.setLineWidth(0.01f);
    for (Body body = scene.getWorld().getBodyList(); body != null; body = body.getNext()) {
        final Vec2 center = body.getPosition();
        renderingContext2D.save();
        renderingContext2D.translate(center.x, center.y);
        renderingContext2D.rotate(body.getAngle());
        for (Fixture fixture = body.getFixtureList(); fixture != null; fixture = fixture.getNext()) {
            final Shape shape = fixture.getShape();
            if (shape.getType() == ShapeType.CIRCLE) {
                final CircleShape circle = (CircleShape) shape;
                renderingContext2D.beginPath();
                renderingContext2D.arc(circle.m_p.x, circle.m_p.y, circle.getRadius(), 0, Math.PI * 2, true);
                renderingContext2D.closePath();
                renderingContext2D.stroke();
            } else if (shape.getType() == ShapeType.POLYGON) {
                final PolygonShape poly = (PolygonShape) shape;
                final Vec2[] vertices = poly.getVertices();
                renderingContext2D.beginPath();
                renderingContext2D.moveTo(vertices[0].x, vertices[0].y);
                for (int i = 1; i < poly.getVertexCount(); ++i) {
                    renderingContext2D.lineTo(vertices[i].x, vertices[i].y);
                }
                renderingContext2D.closePath();
                renderingContext2D.stroke();
            }
        }
        renderingContext2D.restore();
    }
    renderingContext2D.restore();
}
 
Example #4
Source File: Collision.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Determine if two generic shapes overlap.
 * 
 * @param shapeA
 * @param shapeB
 * @param xfA
 * @param xfB
 * @return
 */
public final boolean testOverlap(Shape shapeA, int indexA, Shape shapeB, int indexB,
    Transform xfA, Transform xfB) {
  input.proxyA.set(shapeA, indexA);
  input.proxyB.set(shapeB, indexB);
  input.transformA.set(xfA);
  input.transformB.set(xfB);
  input.useRadii = true;

  cache.count = 0;

  pool.getDistance().distance(output, cache, input);
  // djm note: anything significant about 10.0f?
  return output.distance < 10.0f * Settings.EPSILON;
}
 
Example #5
Source File: ParticleSystem.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void init(ParticleSystem system, Shape shape, Transform xf,
    boolean callDestructionListener) {
  this.system = system;
  this.shape = shape;
  this.xf = xf;
  this.destroyed = 0;
  this.callDestructionListener = callDestructionListener;
}
 
Example #6
Source File: Contact.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
/**
 * Get the world manifold.
 */
public void getWorldManifold(WorldManifold worldManifold) {
  final Body bodyA = m_fixtureA.getBody();
  final Body bodyB = m_fixtureB.getBody();
  final Shape shapeA = m_fixtureA.getShape();
  final Shape shapeB = m_fixtureB.getShape();

  worldManifold.initialize(m_manifold, bodyA.getTransform(), shapeA.m_radius,
      bodyB.getTransform(), shapeB.m_radius);
}
 
Example #7
Source File: MoBike.java    From kAndroid with Apache License 2.0 5 votes vote down vote up
private void createBody(View childView) {
    BodyDef bodyDef = new BodyDef();
    bodyDef.type = BodyType.DYNAMIC;

    //设置view中心点位置
    bodyDef.position.set(mappingView2Body(childView.getX() + childView.getWidth() / 2),
            mappingView2Body(childView.getY() + childView.getHeight() / 2));

    Shape shape = null;
    Boolean isCircle = (boolean) childView.getTag(R.id.wd_view_circle_tag);
    if (isCircle != null && isCircle) {
        shape = createCircleBody(childView);
    } else {
        shape = createPolygonBody(childView);
    }

    //设置系数
    FixtureDef def = new FixtureDef();
    def.shape = shape;
    def.density = density;
    def.friction = frictionRatio;
    def.restitution = restitutionRatio;

    Body body = world.createBody(bodyDef);
    body.createFixture(def);

    childView.setTag(R.id.wd_view_body_tag, body);
    body.setLinearVelocity(new Vec2(random.nextFloat(), random.nextFloat()));
}
 
Example #8
Source File: MoBike.java    From kAndroid with Apache License 2.0 4 votes vote down vote up
private Shape createPolygonBody(View childView) {
    PolygonShape polygonShape = new PolygonShape();
    //形状的大小为 view 的一半 (还可以等比缩放)
    polygonShape.setAsBox(mappingView2Body(childView.getWidth() / 2), mappingView2Body(childView.getHeight() / 2));
    return polygonShape;
}
 
Example #9
Source File: PbDeserializer.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Shape deserializeShape(PbShape argShape) {
  PbShape s = argShape;

  Shape shape = null;
  switch (s.getType()) {
    case CIRCLE:
      CircleShape c = new CircleShape();
      c.m_p.set(pbToVec(s.getCenter()));
      shape = c;
      break;
    case POLYGON:
      PolygonShape p = new PolygonShape();
      p.m_centroid.set(pbToVec(s.getCentroid()));
      p.m_count = s.getPointsCount();
      for (int i = 0; i < p.m_count; i++) {
        p.m_vertices[i].set(pbToVec(s.getPoints(i)));
        p.m_normals[i].set(pbToVec(s.getNormals(i)));
      }
      shape = p;
      break;
    case EDGE:
      EdgeShape edge = new EdgeShape();
      edge.m_vertex0.set(pbToVec(s.getV0()));
      edge.m_vertex1.set(pbToVec(s.getV1()));
      edge.m_vertex2.set(pbToVec(s.getV2()));
      edge.m_vertex3.set(pbToVec(s.getV3()));
      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)));
      }
      chain.m_hasPrevVertex = s.getHas0();
      chain.m_hasNextVertex = s.getHas3();
      chain.m_prevVertex.set(pbToVec(s.getPrev()));
      chain.m_nextVertex.set(pbToVec(s.getNext()));
      shape = chain;
      break;
    }
    default: {
      UnsupportedObjectException e =
          new UnsupportedObjectException("Unknown shape type: " + s.getType(), Type.SHAPE);
      if (ulistener == null || ulistener.isUnsupported(e)) {
        throw e;
      }
      return null;
    }
  }
  shape.m_radius = s.getRadius();

  if (listener != null && s.hasTag()) {
    listener.processShape(shape, s.getTag());
  }
  return shape;
}
 
Example #10
Source File: PbDeserializer.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Shape deserializeShape(InputStream argInput) throws IOException {
  PbShape s = PbShape.parseFrom(argInput);
  return deserializeShape(s);
}
 
Example #11
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void processShape(Shape argShape, Long argTag) {
  listener.processShape(argShape, argTag);
}
 
Example #12
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public Long getTag(Shape argShape) {
  return delegate.getTag(argShape);
}
 
Example #13
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void init(World world, Shape shape, Vec2 velocity) {
  this.world = world;
  this.shape = shape;
  this.velocity = velocity;
}
 
Example #14
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public void processShape(Shape shape, Long tag) {}
 
Example #15
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public Long getTag(Shape shape) {
  return null;
}
 
Example #16
Source File: PbSerializer.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public PbShape.Builder serializeShape(Shape argShape) {
  final PbShape.Builder builder = PbShape.newBuilder();
  if (signer != null) {
    Long tag = signer.getTag(argShape);
    if (tag != null) {
      builder.setTag(tag);
    }
  }
  builder.setRadius(argShape.m_radius);

  switch (argShape.m_type) {
    case CIRCLE:
      CircleShape c = (CircleShape) argShape;
      builder.setType(PbShapeType.CIRCLE);
      builder.setCenter(vecToPb(c.m_p));
      break;
    case POLYGON:
      PolygonShape p = (PolygonShape) argShape;
      builder.setType(PbShapeType.POLYGON);
      builder.setCentroid(vecToPb(p.m_centroid));
      for (int i = 0; i < p.m_count; i++) {
        builder.addPoints(vecToPb(p.m_vertices[i]));
        builder.addNormals(vecToPb(p.m_normals[i]));
      }
      break;
    case EDGE:
      EdgeShape e = (EdgeShape) argShape;
      builder.setType(PbShapeType.EDGE);
      builder.setV0(vecToPb(e.m_vertex0));
      builder.setV1(vecToPb(e.m_vertex1));
      builder.setV2(vecToPb(e.m_vertex2));
      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));
      builder.setNext(vecToPb(h.m_nextVertex));
      builder.setHas0(h.m_hasPrevVertex);
      builder.setHas3(h.m_hasNextVertex);
      break;
    default:
      UnsupportedObjectException ex = new UnsupportedObjectException(
          "Currently only encodes circle and polygon shapes", Type.SHAPE);
      if (listener == null || listener.isUnsupported(ex)) {
        throw ex;
      }
      return null;
  }

  return builder;
}
 
Example #17
Source File: Contact.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public void update(ContactListener listener) {

    oldManifold.set(m_manifold);

    // Re-enable this contact.
    m_flags |= ENABLED_FLAG;

    boolean touching = false;
    boolean wasTouching = (m_flags & TOUCHING_FLAG) == TOUCHING_FLAG;

    boolean sensorA = m_fixtureA.isSensor();
    boolean sensorB = m_fixtureB.isSensor();
    boolean sensor = sensorA || sensorB;

    Body bodyA = m_fixtureA.getBody();
    Body bodyB = m_fixtureB.getBody();
    Transform xfA = bodyA.getTransform();
    Transform xfB = bodyB.getTransform();
    // log.debug("TransformA: "+xfA);
    // log.debug("TransformB: "+xfB);

    if (sensor) {
      Shape shapeA = m_fixtureA.getShape();
      Shape shapeB = m_fixtureB.getShape();
      touching = pool.getCollision().testOverlap(shapeA, m_indexA, shapeB, m_indexB, xfA, xfB);

      // Sensors don't generate manifolds.
      m_manifold.pointCount = 0;
    } else {
      evaluate(m_manifold, xfA, xfB);
      touching = m_manifold.pointCount > 0;

      // Match old contact ids to new contact ids and copy the
      // stored impulses to warm start the solver.
      for (int i = 0; i < m_manifold.pointCount; ++i) {
        ManifoldPoint mp2 = m_manifold.points[i];
        mp2.normalImpulse = 0.0f;
        mp2.tangentImpulse = 0.0f;
        ContactID id2 = mp2.id;

        for (int j = 0; j < oldManifold.pointCount; ++j) {
          ManifoldPoint mp1 = oldManifold.points[j];

          if (mp1.id.isEqual(id2)) {
            mp2.normalImpulse = mp1.normalImpulse;
            mp2.tangentImpulse = mp1.tangentImpulse;
            break;
          }
        }
      }

      if (touching != wasTouching) {
        bodyA.setAwake(true);
        bodyB.setAwake(true);
      }
    }

    if (touching) {
      m_flags |= TOUCHING_FLAG;
    } else {
      m_flags &= ~TOUCHING_FLAG;
    }

    if (listener == null) {
      return;
    }

    if (wasTouching == false && touching == true) {
      listener.beginContact(this);
    }

    if (wasTouching == true && touching == false) {
      listener.endContact(this);
    }

    if (sensor == false && touching) {
      listener.preSolve(this, oldManifold);
    }
  }
 
Example #18
Source File: ParticleSystem.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean reportFixture(Fixture fixture) {
  if (fixture.isSensor()) {
    return true;
  }
  final Shape shape = fixture.getShape();
  Body body = fixture.getBody();
  int childCount = shape.getChildCount();
  for (int childIndex = 0; childIndex < childCount; childIndex++) {
    AABB aabb = fixture.getAABB(childIndex);
    final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter;
    final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter;
    final float aabbupperBoundx = aabb.upperBound.x + system.m_particleDiameter;
    final float aabbupperBoundy = aabb.upperBound.y + system.m_particleDiameter;
    int firstProxy =
        lowerBound(
            system.m_proxyBuffer,
            system.m_proxyCount,
            computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter
                * aabblowerBoundy));
    int lastProxy =
        upperBound(
            system.m_proxyBuffer,
            system.m_proxyCount,
            computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter
                * aabbupperBoundy));

    for (int proxy = firstProxy; proxy != lastProxy; ++proxy) {
      int a = system.m_proxyBuffer[proxy].index;
      Vec2 ap = system.m_positionBuffer.data[a];
      if (aabblowerBoundx <= ap.x && ap.x <= aabbupperBoundx && aabblowerBoundy <= ap.y
          && ap.y <= aabbupperBoundy) {
        Vec2 av = system.m_velocityBuffer.data[a];
        final Vec2 temp = tempVec;
        Transform.mulTransToOutUnsafe(body.m_xf0, ap, temp);
        Transform.mulToOutUnsafe(body.m_xf, temp, input.p1);
        input.p2.x = ap.x + step.dt * av.x;
        input.p2.y = ap.y + step.dt * av.y;
        input.maxFraction = 1;
        if (fixture.raycast(output, input, childIndex)) {
          final Vec2 p = tempVec;
          p.x =
              (1 - output.fraction) * input.p1.x + output.fraction * input.p2.x
                  + Settings.linearSlop * output.normal.x;
          p.y =
              (1 - output.fraction) * input.p1.y + output.fraction * input.p2.y
                  + Settings.linearSlop * output.normal.y;

          final float vx = step.inv_dt * (p.x - ap.x);
          final float vy = step.inv_dt * (p.y - ap.y);
          av.x = vx;
          av.y = vy;
          final float particleMass = system.getParticleMass();
          final float ax = particleMass * (av.x - vx);
          final float ay = particleMass * (av.y - vy);
          Vec2 b = output.normal;
          final float fdn = ax * b.x + ay * b.y;
          final Vec2 f = tempVec2;
          f.x = fdn * b.x;
          f.y = fdn * b.y;
          body.applyLinearImpulse(f, p, true);
        }
      }
    }
  }
  return true;
}
 
Example #19
Source File: ParticleSystem.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
@Override
public boolean reportFixture(Fixture fixture) {
  if (fixture.isSensor()) {
    return true;
  }
  final Shape shape = fixture.getShape();
  Body b = fixture.getBody();
  Vec2 bp = b.getWorldCenter();
  float bm = b.getMass();
  float bI = b.getInertia() - bm * b.getLocalCenter().lengthSquared();
  float invBm = bm > 0 ? 1 / bm : 0;
  float invBI = bI > 0 ? 1 / bI : 0;
  int childCount = shape.getChildCount();
  for (int childIndex = 0; childIndex < childCount; childIndex++) {
    AABB aabb = fixture.getAABB(childIndex);
    final float aabblowerBoundx = aabb.lowerBound.x - system.m_particleDiameter;
    final float aabblowerBoundy = aabb.lowerBound.y - system.m_particleDiameter;
    final float aabbupperBoundx = aabb.upperBound.x + system.m_particleDiameter;
    final float aabbupperBoundy = aabb.upperBound.y + system.m_particleDiameter;
    int firstProxy =
        lowerBound(
            system.m_proxyBuffer,
            system.m_proxyCount,
            computeTag(system.m_inverseDiameter * aabblowerBoundx, system.m_inverseDiameter
                * aabblowerBoundy));
    int lastProxy =
        upperBound(
            system.m_proxyBuffer,
            system.m_proxyCount,
            computeTag(system.m_inverseDiameter * aabbupperBoundx, system.m_inverseDiameter
                * aabbupperBoundy));

    for (int proxy = firstProxy; proxy != lastProxy; ++proxy) {
      int a = system.m_proxyBuffer[proxy].index;
      Vec2 ap = system.m_positionBuffer.data[a];
      if (aabblowerBoundx <= ap.x && ap.x <= aabbupperBoundx && aabblowerBoundy <= ap.y
          && ap.y <= aabbupperBoundy) {
        float d;
        final Vec2 n = tempVec;
        d = fixture.computeDistance(ap, childIndex, n);
        if (d < system.m_particleDiameter) {
          float invAm =
              (system.m_flagsBuffer.data[a] & ParticleType.b2_wallParticle) != 0 ? 0 : system
                  .getParticleInvMass();
          final float rpx = ap.x - bp.x;
          final float rpy = ap.y - bp.y;
          float rpn = rpx * n.y - rpy * n.x;
          if (system.m_bodyContactCount >= system.m_bodyContactCapacity) {
            int oldCapacity = system.m_bodyContactCapacity;
            int newCapacity =
                system.m_bodyContactCount != 0
                    ? 2 * system.m_bodyContactCount
                    : Settings.minParticleBufferCapacity;
            system.m_bodyContactBuffer =
                BufferUtils.reallocateBuffer(ParticleBodyContact.class,
                    system.m_bodyContactBuffer, oldCapacity, newCapacity);
            system.m_bodyContactCapacity = newCapacity;
          }
          ParticleBodyContact contact = system.m_bodyContactBuffer[system.m_bodyContactCount];
          contact.index = a;
          contact.body = b;
          contact.weight = 1 - d * system.m_inverseDiameter;
          contact.normal.x = -n.x;
          contact.normal.y = -n.y;
          contact.mass = 1 / (invAm + invBm + invBI * rpn * rpn);
          system.m_bodyContactCount++;
        }
      }
    }
  }
  return true;
}
 
Example #20
Source File: ParticleSystem.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) {
  dpcallback.init(this, shape, xf, callDestructionListener);
  shape.computeAABB(temp, xf, 0);
  m_world.queryAABB(dpcallback, temp);
  return dpcallback.destroyed;
}
 
Example #21
Source File: Distance.java    From jbox2d with BSD 2-Clause "Simplified" License 4 votes vote down vote up
/**
 * Initialize the proxy using the given shape. The shape must remain in scope while the proxy is
 * in use.
 */
public final void set(final Shape shape, int index) {
  switch (shape.getType()) {
    case CIRCLE:
      final CircleShape circle = (CircleShape) shape;
      m_vertices[0].set(circle.m_p);
      m_count = 1;
      m_radius = circle.m_radius;

      break;
    case POLYGON:
      final PolygonShape poly = (PolygonShape) shape;
      m_count = poly.m_count;
      m_radius = poly.m_radius;
      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];
      } else {
        m_buffer[1] = chain.m_vertices[0];
      }

      m_vertices[0].set(m_buffer[0]);
      m_vertices[1].set(m_buffer[1]);
      m_count = 2;
      m_radius = chain.m_radius;
      break;
    case EDGE:
      EdgeShape edge = (EdgeShape) shape;
      m_vertices[0].set(edge.m_vertex1);
      m_vertices[1].set(edge.m_vertex2);
      m_count = 2;
      m_radius = edge.m_radius;
      break;
    default:
      assert (false);
  }
}
 
Example #22
Source File: MoBike.java    From kAndroid with Apache License 2.0 4 votes vote down vote up
private Shape createCircleBody(View childView) {
    CircleShape circleShape = new CircleShape();
    //半径为 宽、高的一半
    circleShape.setRadius(mappingView2Body(childView.getHeight() / 2));
    return circleShape;
}
 
Example #23
Source File: Body.java    From jbox2d with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Creates a fixture from a shape and attach it to this body. This is a convenience function. Use
 * FixtureDef if you need to set parameters like friction, restitution, user data, or filtering.
 * If the density is non-zero, this function automatically updates the mass of the body.
 * 
 * @param shape the shape to be cloned.
 * @param density the shape density (set to zero for static bodies).
 * @warning This function is locked during callbacks.
 */
public final Fixture createFixture(Shape shape, float density) {
  fixDef.shape = shape;
  fixDef.density = density;

  return createFixture(fixDef);
}
 
Example #24
Source File: World.java    From jbox2d with BSD 2-Clause "Simplified" License 3 votes vote down vote up
/**
 * Destroy particles inside a shape. This function is locked during callbacks. In addition, this
 * function immediately destroys particles in the shape in contrast to DestroyParticle() which
 * defers the destruction until the next simulation step.
 * 
 * @param Shape which encloses particles that should be destroyed.
 * @param Transform applied to the shape.
 * @param Whether to call the world b2DestructionListener for each particle destroyed.
 * @warning This function is locked during callbacks.
 * @return Number of particles destroyed.
 */
public int destroyParticlesInShape(Shape shape, Transform xf, boolean callDestructionListener) {
  assert (isLocked() == false);
  if (isLocked()) {
    return 0;
  }
  return m_particleSystem.destroyParticlesInShape(shape, xf, callDestructionListener);
}
 
Example #25
Source File: JbDeserializer.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
  * Deserializes a shape
  * @param input
  * @return
  * @throws IOException
  * @throws UnsupportedObjectException if a read physics object is unsupported by this library
  * @see #setUnsupportedListener(UnsupportedListener)
  */
public Shape deserializeShape(InputStream input) throws IOException, UnsupportedObjectException;
 
Example #26
Source File: JbSerializer.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Serializes a shape
 * @param shape
 * @return
  * @throws UnsupportedObjectException if a physics object is unsupported by this library.
  * @see #setUnsupportedListener(UnsupportedListener)
 */
public SerializationResult serialize(Shape shape) throws UnsupportedObjectException;
 
Example #27
Source File: JbSerializer.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * @param shape
 * @return the tag for the shape. can be null.
 */
public Long getTag(Shape shape);
 
Example #28
Source File: World.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * Destroy particles inside a shape without enabling the destruction callback for destroyed
 * particles. This function is locked during callbacks. For more information see
 * DestroyParticleInShape(Shape&, Transform&,bool).
 * 
 * @param Shape which encloses particles that should be destroyed.
 * @param Transform applied to the shape.
 * @warning This function is locked during callbacks.
 * @return Number of particles destroyed.
 */
public int destroyParticlesInShape(Shape shape, Transform xf) {
  return destroyParticlesInShape(shape, xf, false);
}
 
Example #29
Source File: FixtureDef.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * The shape, this must be set. The shape will be cloned, so you can create the shape on the
 * stack.
 */
public void setShape(Shape shape) {
  this.shape = shape;
}
 
Example #30
Source File: FixtureDef.java    From jbox2d with BSD 2-Clause "Simplified" License 2 votes vote down vote up
/**
 * The shape, this must be set. The shape will be cloned, so you can create the shape on the
 * stack.
 */
public Shape getShape() {
  return shape;
}