Package org.jbox2d.dynamics

Examples of org.jbox2d.dynamics.Body


    }

    public ArrayList<Element> getElementsByType(Common.ElementType s) {
        ArrayList<Element> l = new ArrayList<Element>();
        Body b = world.getBodyList();
        int i = 0;
        while (b != null) {
            i++;
            Element e = (Element) b.getUserData();
            if (e != null && e.type == s)
                l.add(e);
            b = b.getNext();
        }

        return l;
    }
View Full Code Here


    }

    public ArrayList<Element> getRunnable() {
        ArrayList<Element> l = new ArrayList<Element>();
        Body b = world.getBodyList();
        int i = 0;
        while (b != null) {
            i++;
            Element e = (Element) b.getUserData();
            if (e != null && e.isRunnable)
                l.add(e);
            b = b.getNext();
        }

        return l;

    }
View Full Code Here

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

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

      final Fixture fixtureB = contact.m_fixtureB;
      final Shape shapeA = fixtureA.getShape();
      final Shape shapeB = fixtureB.getShape();
      final float radiusA = shapeA.m_radius;
      final float radiusB = shapeB.m_radius;
      final Body bodyA = fixtureA.getBody();
      final Body bodyB = fixtureB.getBody();
      final Manifold manifold = contact.getManifold();

      int pointCount = manifold.pointCount;
      assert (pointCount > 0);
View Full Code Here

    m_bodies = new Body[e_maxBodies];
    m_userData = new Integer[e_maxBodies];
    m_polygons = new PolygonShape[4];
    {
      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);
View Full Code Here

  public void init() {
    m_hit = false;
  }

  public float reportFixture(Fixture fixture, Vec2 point, Vec2 normal, float fraction) {
    Body body = fixture.getBody();
    Object userData = body.getUserData();
    if (userData != null) {
      int index = (Integer) userData;
      if (index == 0) {
        // filter
        return -1f;
View Full Code Here

  public void init() {
    m_hit = false;
  }

  public float reportFixture(Fixture fixture, Vec2 point, Vec2 normal, float fraction) {
    Body body = fixture.getBody();
    Object userData = body.getUserData();
    if (userData != null) {
      int index = (Integer) userData;
      if (index == 0) {
        // filter
        return -1f;
View Full Code Here

    }
    m_count = 0;
  }

  public float reportFixture(Fixture fixture, Vec2 point, Vec2 normal, float fraction) {
    Body body = fixture.getBody();
    int index = 0;
    Object userData = body.getUserData();
    if (userData != null) {
      index = (Integer) userData;
      if (index == 0) {
        // filter
        return -1f;
View Full Code Here

  public void initTest(boolean deserialized) {
    if (deserialized) {
      return;
    }

    Body ground = null;
    {
      PolygonShape sd = new PolygonShape();
      sd.setAsBox(50.0f, 0.4f);

      BodyDef bd = new BodyDef();
      bd.position.set(0.0f, 0.0f);
      ground = getWorld().createBody(bd);
      ground.createFixture(sd, 0f);

      sd.setAsBox(0.4f, 50.0f, new Vec2(-10.0f, 0.0f), 0.0f);
      ground.createFixture(sd, 0f);
      sd.setAsBox(0.4f, 50.0f, new Vec2(10.0f, 0.0f), 0.0f);
      ground.createFixture(sd, 0f);
    }

    ConstantVolumeJointDef cvjd = new ConstantVolumeJointDef();

    float cx = 0.0f;
    float cy = 10.0f;
    float rx = 5.0f;
    float ry = 5.0f;
    int nBodies = 20;
    float bodyRadius = 0.5f;
    for (int i = 0; i < nBodies; ++i) {
      float angle = MathUtils.map(i, 0, nBodies, 0, 2 * 3.1415f);
      BodyDef bd = new BodyDef();
      // bd.isBullet = true;
      bd.fixedRotation = true;

      float x = cx + rx * (float) Math.sin(angle);
      float y = cy + ry * (float) Math.cos(angle);
      bd.position.set(new Vec2(x, y));
      bd.type = BodyType.DYNAMIC;
      Body body = getWorld().createBody(bd);

      FixtureDef fd = new FixtureDef();
      CircleShape cd = new CircleShape();
      cd.m_radius = bodyRadius;
      fd.shape = cd;
      fd.density = 1.0f;
      body.createFixture(fd);
      cvjd.addBody(body);
    }

    cvjd.frequencyHz = 10.0f;
    cvjd.dampingRatio = 1.0f;
    cvjd.collideConnected = false;
    getWorld().createJoint(cvjd);

    BodyDef bd2 = new BodyDef();
    bd2.type = BodyType.DYNAMIC;
    PolygonShape psd = new PolygonShape();
    psd.setAsBox(3.0f, 1.5f, new Vec2(cx, cy + 15.0f), 0.0f);
    bd2.position = new Vec2(cx, cy + 15.0f);
    Body fallingBox = getWorld().createBody(bd2);
    fallingBox.createFixture(psd, 1.0f);
  }
View Full Code Here

TOP

Related Classes of org.jbox2d.dynamics.Body

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.