Tabnine Logo
com.badlogic.gdx.physics.box2d
Code IndexAdd Tabnine to your IDE (free)

How to use com.badlogic.gdx.physics.box2d

Best Java code snippets using com.badlogic.gdx.physics.box2d (Showing top 20 results out of 315)

origin: libgdx/libgdx

Body createBox (BodyType type, float width, float height, float density) {
  BodyDef def = new BodyDef();
  def.type = type;
  Body box = world.createBody(def);
  PolygonShape poly = new PolygonShape();
  poly.setAsBox(width, height);
  box.createFixture(poly, density);
  poly.dispose();
  return box;
}
origin: libgdx/libgdx

Body createCircle (BodyType type, float radius, float density) {
  BodyDef def = new BodyDef();
  def.type = type;
  Body box = world.createBody(def);
  CircleShape poly = new CircleShape();
  poly.setRadius(radius);
  box.createFixture(poly, density);
  poly.dispose();
  return box;
}
origin: libgdx/libgdx

@Override
public void dispose () {
  renderer.dispose();
  world.dispose();
  renderer = null;
  world = null;
  mouseJoint = null;
  hitBody = null;
}
origin: libgdx/libgdx

private Body createEdge (BodyType type, float x1, float y1, float x2, float y2, float density) {
  BodyDef def = new BodyDef();
  def.type = type;
  Body box = world.createBody(def);
  EdgeShape poly = new EdgeShape();
  poly.set(new Vector2(0, 0), new Vector2(x2 - x1, y2 - y1));
  box.createFixture(poly, density);
  box.setTransform(x1, y1, 0);
  poly.dispose();
  return box;
}
origin: libgdx/libgdx

/** Returns the shape of this fixture */
public Shape getShape () {
  if (shape == null) {
    org.jbox2d.collision.shapes.Shape shape2 = fixture.getShape();
    ShapeType type = shape2.getType();
    if (type == ShapeType.CHAIN) shape = new ChainShape((org.jbox2d.collision.shapes.ChainShape)shape2);
    if (type == ShapeType.CIRCLE) shape = new CircleShape((org.jbox2d.collision.shapes.CircleShape)shape2);
    if (type == ShapeType.EDGE) shape = new EdgeShape((org.jbox2d.collision.shapes.EdgeShape)shape2);
    if (type == ShapeType.POLYGON) shape = new PolygonShape((org.jbox2d.collision.shapes.PolygonShape)shape2);
  }
  return shape;
}
origin: libgdx/libgdx

private void drawContact (Contact contact) {
  WorldManifold worldManifold = contact.getWorldManifold();
  if (worldManifold.getNumberOfContactPoints() == 0) return;
  Vector2 point = worldManifold.getPoints()[0];
  renderer.setColor(getColorByBody(contact.getFixtureA().getBody()));
  renderer.point(point.x, point.y, 0);
}
origin: libgdx/libgdx

@Override
public boolean shouldCollide (Fixture fixtureA, Fixture fixtureB) {
  if ((fixtureA == m_platform && fixtureB == m_character) || (fixtureB == m_platform && fixtureA == m_character)) {
    Vector2 position = m_character.getBody().getPosition();
    if (position.y < m_top + m_radius - 3.0f * 0.005f)
      return false;
    else
      return true;
  } else
    return true;
}
origin: libgdx/libgdx

/** Set the type of this body. This may alter the mass and velocity. */
public void setType (BodyType type) {
  jniSetType(addr, type.getValue());
}

origin: libgdx/libgdx

/** Set the active state of the body. An inactive body is not simulated and cannot be collided with or woken up. If you pass a
 * flag of true, all fixtures will be added to the broad-phase. If you pass a flag of false, all fixtures will be removed from
 * the broad-phase and all contacts will be destroyed. Fixtures and joints are otherwise unaffected. You may continue to
 * create/destroy fixtures and joints on inactive bodies. Fixtures on an inactive body are implicitly inactive and will not
 * participate in collisions, ray-casts, or queries. Joints connected to an inactive body are implicitly inactive. An inactive
 * body is still owned by a b2World object and remains in the body list. */
public void setActive (boolean flag) {
  if (flag) {
    jniSetActive(addr, flag);
  } else {
    this.world.deactivateBody(this);
  }
}
origin: libgdx/libgdx

/** Create a loop. This automatically adjusts connectivity.
 * @param vertices an array of vertices, these are copied */
public void createLoop (Vector2[] vertices) {
  float[] verts = new float[vertices.length * 2];
  for (int i = 0, j = 0; i < vertices.length * 2; i += 2, j++) {
    verts[i] = vertices[j].x;
    verts[i + 1] = vertices[j].y;
  }
  jniCreateLoop(addr, verts, 0, verts.length / 2);
  isLooped = true;
}
origin: libgdx/libgdx

/** Returns the vertex at the given position.
 * @param index the index of the vertex 0 <= index < getVertexCount( )
 * @param vertex vertex */
public void getVertex (int index, Vector2 vertex) {
  jniGetVertex(addr, index, verts);
  vertex.x = verts[0];
  vertex.y = verts[1];
}
origin: libgdx/libgdx

public ManifoldType getType () {
  int type = jniGetType(addr);
  if (type == 0) return ManifoldType.Circle;
  if (type == 1) return ManifoldType.FaceA;
  if (type == 2) return ManifoldType.FaceB;
  return ManifoldType.Circle;
}
origin: libgdx/libgdx

/** Get the linear velocity of the center of mass.
 * Note that the same Vector2 instance is returned each time this method is called. */
public Vector2 getLinearVelocity () {
  jniGetLinearVelocity(addr, tmp);
  linearVelocity.x = tmp[0];
  linearVelocity.y = tmp[1];
  return linearVelocity;
}
origin: libgdx/libgdx

/** Apply an angular impulse.
 * @param impulse the angular impulse in units of kg*m*m/s */
public void applyAngularImpulse (float impulse, boolean wake) {
  jniApplyAngularImpulse(addr, impulse, wake);
}
origin: libgdx/libgdx

/** Get the rotational inertia of the body about the local origin.
 * @return the rotational inertia, usually in kg-m^2. */
public float getInertia () {
  return jniGetInertia(addr);
}
origin: libgdx/libgdx

/** Get the mass data of the body.
 * @return a struct containing the mass, inertia and center of the body. */
public MassData getMassData () {
  jniGetMassData(addr, tmp);
  massData.mass = tmp[0];
  massData.center.x = tmp[1];
  massData.center.y = tmp[2];
  massData.I = tmp[3];
  return massData;
}
origin: libgdx/libgdx

/** Get the world velocity of a local point.
 * Note that the same Vector2 instance is returned each time this method is called.
 * @param localPoint a point in local coordinates.
 * @return the world velocity of a point. */
public Vector2 getLinearVelocityFromLocalPoint (Vector2 localPoint) {
  jniGetLinearVelocityFromLocalPoint(addr, localPoint.x, localPoint.y, tmp);
  linVelLoc.x = tmp[0];
  linVelLoc.y = tmp[1];
  return linVelLoc;
}
origin: libgdx/libgdx

public Vector2 getAnchorB () {
  jniGetAnchorB(addr, tmp);
  anchorB.x = tmp[0];
  anchorB.y = tmp[1];
  return anchorB;
}
origin: libgdx/libgdx

public Vector2 getReactionForce (float inv_dt) {
  jniGetReactionForce(addr, inv_dt, tmp);
  reactionForce.x = tmp[0];
  reactionForce.y = tmp[1];
  return reactionForce;
}
origin: libgdx/libgdx

  @Override
  public void dispose () {
    world.dispose();
    renderer.dispose();
  }
}
com.badlogic.gdx.physics.box2d

Most used classes

  • Body
    A rigid body. These are created via World.CreateBody.
  • World
    The world class manages all physics entities, dynamic simulation, and asynchronous queries. The worl
  • CircleShape
    A circle shape.
  • PolygonShape
  • FixtureDef
    A fixture definition is used to create a fixture. This class defines an abstract fixture definition.
  • Fixture,
  • Box2DDebugRenderer,
  • Contact,
  • ChainShape,
  • EdgeShape,
  • WorldManifold,
  • MouseJoint,
  • RevoluteJointDef,
  • Joint,
  • Transform,
  • FrictionJointDef,
  • MouseJointDef,
  • PrismaticJoint,
  • PrismaticJointDef
Tabnine Logo
  • Products

    Search for Java codeSearch for JavaScript code
  • IDE Plugins

    IntelliJ IDEAWebStormVisual StudioAndroid StudioEclipseVisual Studio CodePyCharmSublime TextPhpStormVimGoLandRubyMineEmacsJupyter NotebookJupyter LabRiderDataGripAppCode
  • Company

    About UsContact UsCareers
  • Resources

    FAQBlogTabnine AcademyTerms of usePrivacy policyJava Code IndexJavascript Code Index
Get Tabnine for your IDE now