org.jbox2d.common.Vec2 Java Examples

The following examples show how to use org.jbox2d.common.Vec2. 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: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public void transformViewport(GL2 gl, Vec2 center) {
  Vec2 e = viewportTransform.getExtents();
  Vec2 vc = viewportTransform.getCenter();
  Mat22 vt = viewportTransform.getMat22Representation();

  int f = viewportTransform.isYFlip() ? -1 : 1;
  mat[0] = vt.ex.x;
  mat[4] = vt.ey.x;
  // mat[8] = 0;
  mat[12] = e.x;
  mat[1] = f * vt.ex.y;
  mat[5] = f * vt.ey.y;
  // mat[9] = 0;
  mat[13] = e.y;
  // mat[2] = 0;
  // mat[6] = 0;
  // mat[10] = 1;
  // mat[14] = 0;
  // mat[3] = 0;
  // mat[7] = 0;
  // mat[11] = 0;
  // mat[15] = 1;

  gl.glMultMatrixf(mat, 0);
  gl.glTranslatef(center.x - vc.x, center.y - vc.y, 0);
}
 
Example #2
Source File: EdgeShape.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void computeAABB(AABB aabb, Transform xf, int childIndex) {
  final Vec2 lowerBound = aabb.lowerBound;
  final Vec2 upperBound = aabb.upperBound;
  final Rot xfq = xf.q;

  final float v1x = (xfq.c * m_vertex1.x - xfq.s * m_vertex1.y) + xf.p.x;
  final float v1y = (xfq.s * m_vertex1.x + xfq.c * m_vertex1.y) + xf.p.y;
  final float v2x = (xfq.c * m_vertex2.x - xfq.s * m_vertex2.y) + xf.p.x;
  final float v2y = (xfq.s * m_vertex2.x + xfq.c * m_vertex2.y) + xf.p.y;

  lowerBound.x = v1x < v2x ? v1x : v2x;
  lowerBound.y = v1y < v2y ? v1y : v2y;
  upperBound.x = v1x > v2x ? v1x : v2x;
  upperBound.y = v1y > v2y ? v1y : v2y;

  lowerBound.x -= m_radius;
  lowerBound.y -= m_radius;
  upperBound.x += m_radius;
  upperBound.y += m_radius;
}
 
Example #3
Source File: Distance.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public float getMetric() {
  switch (m_count) {
    case 0:
      assert (false);
      return 0.0f;

    case 1:
      return 0.0f;

    case 2:
      return MathUtils.distance(m_v1.w, m_v2.w);

    case 3:
      case3.set(m_v2.w).subLocal(m_v1.w);
      case33.set(m_v3.w).subLocal(m_v1.w);
      // return Vec2.cross(m_v2.w - m_v1.w, m_v3.w - m_v1.w);
      return Vec2.cross(case3, case33);

    default:
      assert (false);
      return 0.0f;
  }
}
 
Example #4
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
  GraphicsContext g = getGraphics();
  saveState(g);
  double scaling = transformGraphics(g, zero) * radius;
  g.setLineWidth(stroke / scaling);
  for (int i = 0; i < count; i++) {
    Vec2 center = centers[i];
    Color color;
    if (colors == null) {
      color = pcolorA;
    } else {
      ParticleColor c = colors[i];
      color = cpool.getColor(c.r * 1f / 127, c.g * 1f / 127, c.b * 1f / 127, c.a * 1f / 127);
    }
    Affine old = g.getTransform();
    g.translate(center.x, center.y);
    g.scale(radius, radius);
    g.setFill(color);
    g.fillOval(circle.getMinX(), circle.getMinX(), circle.getWidth(), circle.getHeight());
    g.setTransform(old);
  }
  restoreState(g);
}
 
Example #5
Source File: OneSidedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void preSolve(Contact contact, Manifold oldManifold) {
  super.preSolve(contact, oldManifold);

  Fixture fixtureA = contact.getFixtureA();
  Fixture fixtureB = contact.getFixtureB();

  if (fixtureA != m_platform && fixtureA != m_character) {
    return;
  }

  if (fixtureB != m_character && fixtureB != m_character) {
    return;
  }

  Vec2 position = m_character.getBody().getPosition();

  if (position.y < m_top + m_radius - 3.0f * Settings.linearSlop) {
    contact.setEnabled(false);
  }
}
 
Example #6
Source File: BodyTypes.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void keyPressed(char argKeyChar, int argKeyCode) {
  switch (argKeyChar) {
    case 'd':
      m_platform.setType(BodyType.DYNAMIC);
      break;

    case 's':
      m_platform.setType(BodyType.STATIC);
      break;

    case 'k':
      m_platform.setType(BodyType.KINEMATIC);
      m_platform.setLinearVelocity(new Vec2(-m_speed, 0.0f));
      m_platform.setAngularVelocity(0.0f);
      break;
  }
}
 
Example #7
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  GraphicsContext g = getGraphics();
  saveState(g);
  double[] xs = xDoublePool.get(vertexCount);
  double[] ys = yDoublePool.get(vertexCount);
  for (int i = 0; i < vertexCount; i++) {
    getWorldToScreenToOut(vertices[i], temp);
    xs[i] = temp.x;
    ys[i] = temp.y;
  }
  g.setLineWidth(stroke);
  g.setStroke(s);
  g.strokePolygon(xs, ys, vertexCount);
  restoreState(g);
}
 
Example #8
Source File: ChainShape.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
/**
 * Create a chain with isolated end vertices.
 * 
 * @param vertices an array of vertices, these are copied
 * @param count the vertex count
 */
public void createChain(final Vec2 vertices[], int count) {
  assert (m_vertices == null && m_count == 0);
  assert (count >= 2);
  m_count = count;
  m_vertices = new Vec2[m_count];
  for (int i = 1; i < m_count; i++) {
    Vec2 v1 = vertices[i - 1];
    Vec2 v2 = vertices[i];
    // If the code crashes here, it means your vertices are too close together.
    if (MathUtils.distanceSquared(v1, v2) < Settings.linearSlop * Settings.linearSlop) {
      throw new RuntimeException("Vertices of chain shape are too close together");
    }
  }
  for (int i = 0; i < m_count; i++) {
    m_vertices[i] = new Vec2(vertices[i]);
  }
  m_hasPrevVertex = false;
  m_hasNextVertex = false;

  m_prevVertex.setZero();
  m_nextVertex.setZero();
}
 
Example #9
Source File: DebugDrawJ2D.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  Color s = cpool.getColor(color.x, color.y, color.z, 1f);
  Graphics2D g = getGraphics();
  saveState(g);
  int[] xInts = xIntsPool.get(vertexCount);
  int[] yInts = yIntsPool.get(vertexCount);
  for (int i = 0; i < vertexCount; i++) {
    getWorldToScreenToOut(vertices[i], temp);
    xInts[i] = (int) temp.x;
    yInts[i] = (int) temp.y;
  }
  g.setStroke(stroke);
  g.setColor(s);
  g.drawPolygon(xInts, yInts, vertexCount);
  restoreState(g);
}
 
Example #10
Source File: ParticleSystem.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
void solveSolid(final TimeStep step) {
  // applies extra repulsive force from solid particle groups
  m_depthBuffer = requestParticleBuffer(m_depthBuffer);
  float ejectionStrength = step.inv_dt * m_ejectionStrength;
  for (int k = 0; k < m_contactCount; k++) {
    final ParticleContact contact = m_contactBuffer[k];
    int a = contact.indexA;
    int b = contact.indexB;
    if (m_groupBuffer[a] != m_groupBuffer[b]) {
      float w = contact.weight;
      Vec2 n = contact.normal;
      float h = m_depthBuffer[a] + m_depthBuffer[b];
      final Vec2 va = m_velocityBuffer.data[a];
      final Vec2 vb = m_velocityBuffer.data[b];
      final float inter = ejectionStrength * h * w;
      final float fx = inter * n.x;
      final float fy = inter * n.y;
      va.x -= fx;
      va.y -= fy;
      vb.x += fx;
      vb.y += fy;
    }
  }
}
 
Example #11
Source File: DrawingParticles.java    From jbox2d with BSD 2-Clause "Simplified" License 6 votes vote down vote up
@Override
public void mouseDrag(Vec2 p, int button) {
  super.mouseDrag(p, button);
  if (m_drawing) {
    pshape.m_p.set(p);
    pshape.m_radius = 2.0f;
    pxf.setIdentity();
    m_world.destroyParticlesInShape(pshape, pxf);
    ppd.shape = pshape;
    ppd.color = color;
    ppd.flags = m_particleFlags;
    ppd.groupFlags = m_groupFlags;
    ParticleGroup group = m_world.createParticleGroup(ppd);
    if (m_lastGroup != null && group.getGroupFlags() == m_lastGroup.getGroupFlags()) {
      m_world.joinParticleGroups(m_lastGroup, group);
    } else {
      m_lastGroup = group;
    }
    mouseTracing = false;
  }
}
 
Example #12
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void completeBombSpawn(Vec2 p) {
  if (bombSpawning == false) {
    return;
  }

  float multiplier = 30f;
  vel.set(bombSpawnPoint).subLocal(p);
  vel.mulLocal(multiplier);
  launchBomb(bombSpawnPoint, vel);
  bombSpawning = false;
}
 
Example #13
Source File: World.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
private void drawJoint(Joint joint) {
  Body bodyA = joint.getBodyA();
  Body bodyB = joint.getBodyB();
  Transform xf1 = bodyA.getTransform();
  Transform xf2 = bodyB.getTransform();
  Vec2 x1 = xf1.p;
  Vec2 x2 = xf2.p;
  Vec2 p1 = pool.popVec2();
  Vec2 p2 = pool.popVec2();
  joint.getAnchorA(p1);
  joint.getAnchorB(p2);

  color.set(0.5f, 0.8f, 0.8f);

  switch (joint.getType()) {
  // TODO djm write after writing joints
    case DISTANCE:
      m_debugDraw.drawSegment(p1, p2, color);
      break;

    case PULLEY: {
      PulleyJoint pulley = (PulleyJoint) joint;
      Vec2 s1 = pulley.getGroundAnchorA();
      Vec2 s2 = pulley.getGroundAnchorB();
      m_debugDraw.drawSegment(s1, p1, color);
      m_debugDraw.drawSegment(s2, p2, color);
      m_debugDraw.drawSegment(s1, s2, color);
    }
      break;
    case CONSTANT_VOLUME:
    case MOUSE:
      // don't draw this
      break;
    default:
      m_debugDraw.drawSegment(x1, p1, color);
      m_debugDraw.drawSegment(p1, p2, color);
      m_debugDraw.drawSegment(x2, p2, color);
  }
  pool.pushVec2(2);
}
 
Example #14
Source File: DistanceJoint.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
  public void solveVelocityConstraints(final SolverData data) {
    Vec2 vA = data.velocities[m_indexA].v;
    float wA = data.velocities[m_indexA].w;
    Vec2 vB = data.velocities[m_indexB].v;
    float wB = data.velocities[m_indexB].w;

    final Vec2 vpA = pool.popVec2();
    final Vec2 vpB = pool.popVec2();

    // Cdot = dot(u, v + cross(w, r))
    Vec2.crossToOutUnsafe(wA, m_rA, vpA);
    vpA.addLocal(vA);
    Vec2.crossToOutUnsafe(wB, m_rB, vpB);
    vpB.addLocal(vB);
    float Cdot = Vec2.dot(m_u, vpB.subLocal(vpA));

    float impulse = -m_mass * (Cdot + m_bias + m_gamma * m_impulse);
    m_impulse += impulse;


    float Px = impulse * m_u.x;
    float Py = impulse * m_u.y;

    vA.x -= m_invMassA * Px;
    vA.y -= m_invMassA * Py;
    wA -= m_invIA * (m_rA.x * Py - m_rA.y * Px);
    vB.x += m_invMassB * Px;
    vB.y += m_invMassB * Py;
    wB += m_invIB * (m_rB.x * Py - m_rB.y * Px);

//    data.velocities[m_indexA].v.set(vA);
    data.velocities[m_indexA].w = wA;
//    data.velocities[m_indexB].v.set(vB);
    data.velocities[m_indexB].w = wB;

    pool.pushVec2(2);
  }
 
Example #15
Source File: PulleyJoint.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
  public void solveVelocityConstraints(final SolverData data) {
    Vec2 vA = data.velocities[m_indexA].v;
    float wA = data.velocities[m_indexA].w;
    Vec2 vB = data.velocities[m_indexB].v;
    float wB = data.velocities[m_indexB].w;

    final Vec2 vpA = pool.popVec2();
    final Vec2 vpB = pool.popVec2();
    final Vec2 PA = pool.popVec2();
    final Vec2 PB = pool.popVec2();

    Vec2.crossToOutUnsafe(wA, m_rA, vpA);
    vpA.addLocal(vA);
    Vec2.crossToOutUnsafe(wB, m_rB, vpB);
    vpB.addLocal(vB);

    float Cdot = -Vec2.dot(m_uA, vpA) - m_ratio * Vec2.dot(m_uB, vpB);
    float impulse = -m_mass * Cdot;
    m_impulse += impulse;

    PA.set(m_uA).mulLocal(-impulse);
    PB.set(m_uB).mulLocal(-m_ratio * impulse);
    vA.x += m_invMassA * PA.x;
    vA.y += m_invMassA * PA.y;
    wA += m_invIA * Vec2.cross(m_rA, PA);
    vB.x += m_invMassB * PB.x;
    vB.y += m_invMassB * PB.y;
    wB += m_invIB * Vec2.cross(m_rB, PB);

//    data.velocities[m_indexA].v.set(vA);
    data.velocities[m_indexA].w = wA;
//    data.velocities[m_indexB].v.set(vB);
    data.velocities[m_indexB].w = wB;

    pool.pushVec2(4);
  }
 
Example #16
Source File: JBox2DTest.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
public TestShape() {

            m_count = 0;
            m_vertices = new Vec2[Settings.maxPolygonVertices];
            for (int i = 0; i < m_vertices.length; i++) {
                m_vertices[i] = new Vec2();
            }
            m_normals = new Vec2[Settings.maxPolygonVertices];
            for (int i = 0; i < m_normals.length; i++) {
                m_normals[i] = new Vec2();
            }
            m_centroid.setZero();
        }
 
Example #17
Source File: PolygonShape.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public PolygonShape() {
  super(ShapeType.POLYGON);

  m_count = 0;
  m_vertices = new Vec2[Settings.maxPolygonVertices];
  for (int i = 0; i < m_vertices.length; i++) {
    m_vertices[i] = new Vec2();
  }
  m_normals = new Vec2[Settings.maxPolygonVertices];
  for (int i = 0; i < m_normals.length; i++) {
    m_normals[i] = new Vec2();
  }
  setRadius(Settings.polygonRadius);
  m_centroid.setZero();
}
 
Example #18
Source File: PoolingPerf.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public final Vec2 get() {
  index++;
  if (index >= length) {
    index = 0;
  }
  return pool[index];
}
 
Example #19
Source File: DebugDrawJavaFX.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
  getWorldToScreenToOut(argPoint, sp1);
  GraphicsContext g = getGraphics();

  Color c = cpool.getColor(argColor.x, argColor.y, argColor.z);
  g.setStroke(c);
  sp1.x -= argRadiusOnScreen;
  sp1.y -= argRadiusOnScreen;
  g.fillOval((int) sp1.x, (int) sp1.y, (int) argRadiusOnScreen * 2, (int) argRadiusOnScreen * 2);
}
 
Example #20
Source File: JBox2DSimulation.java    From Bytecoder with Apache License 2.0 5 votes vote down vote up
private void initReel() {
    final BodyDef reelDef = new BodyDef();
    reelDef.type = BodyType.DYNAMIC;
    reelDef.position = new Vec2(3, 3);
    reel = world.createBody(reelDef);

    final FixtureDef fixture = new FixtureDef();
    fixture.friction = 0.5f;
    fixture.restitution = 0.4f;
    fixture.density = 1;

    final int parts = 30;
    for (int i = 0; i < parts; ++i) {
        final PolygonShape shape = new PolygonShape();
        final double angle1 = i / (double) parts * 2 * Math.PI;
        final double x1 = 2.7 * Math.cos(angle1);
        final double y1 = 2.7 * Math.sin(angle1);
        final double angle2 = (i + 1) / (double) parts * 2 * Math.PI;
        final double x2 = 2.7 * Math.cos(angle2);
        final double y2 = 2.7 * Math.sin(angle2);
        final double angle = (angle1 + angle2) / 2;
        final double x = 0.01 * Math.cos(angle);
        final double y = 0.01 * Math.sin(angle);

        shape.set(new Vec2[] { new Vec2((float) x1, (float) y1), new Vec2((float) x2, (float) y2),
                new Vec2((float) (x2 - x), (float) (y2 - y)), new Vec2((float) (x1 - x), (float) (y1 - y)) }, 4);
        fixture.shape = shape;
        reel.createFixture(fixture);
    }
}
 
Example #21
Source File: DebugDrawJ2D.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawPoint(Vec2 argPoint, float argRadiusOnScreen, Color3f argColor) {
  getWorldToScreenToOut(argPoint, sp1);
  Graphics2D g = getGraphics();

  Color c = cpool.getColor(argColor.x, argColor.y, argColor.z);
  g.setColor(c);
  sp1.x -= argRadiusOnScreen;
  sp1.y -= argRadiusOnScreen;
  g.fillOval((int) sp1.x, (int) sp1.y, (int) argRadiusOnScreen * 2, (int) argRadiusOnScreen * 2);
}
 
Example #22
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 #23
Source File: PulleyJoint.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public float getCurrentLengthA() {
  final Vec2 p = pool.popVec2();
  m_bodyA.getWorldPointToOut(m_localAnchorA, p);
  p.subLocal(m_groundAnchorA);
  float length = p.length();
  pool.pushVec2(1);
  return length;
}
 
Example #24
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawPolygon(Vec2[] vertices, int vertexCount, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  gl.glBegin(GL2.GL_LINE_LOOP);
  gl.glColor4f(color.x, color.y, color.z, 1f);
  for (int i = 0; i < vertexCount; i++) {
    Vec2 v = vertices[i];
    gl.glVertex2f(v.x, v.y);
  }
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example #25
Source File: VerticalStack.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void keyPressed(char argKeyChar, int argKeyCode) {
  switch (argKeyChar) {
    case ',':
      if (m_bullet != null) {
        getWorld().destroyBody(m_bullet);
        m_bullet = null;
      }

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

        FixtureDef fd = new FixtureDef();
        fd.shape = shape;
        fd.density = 20.0f;
        fd.restitution = 0.05f;

        BodyDef bd = new BodyDef();
        bd.type = BodyType.DYNAMIC;
        bd.bullet = true;
        bd.position.set(-31.0f, 5.0f);

        m_bullet = getWorld().createBody(bd);
        m_bullet.createFixture(fd);

        m_bullet.setLinearVelocity(new Vec2(400.0f, 0.0f));
      }
      break;
  }
}
 
Example #26
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawSegment(Vec2 p1, Vec2 p2, Color3f color) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);
  gl.glBegin(GL2.GL_LINES);
  gl.glColor3f(color.x, color.y, color.z);
  gl.glVertex3f(p1.x, p1.y, 0);
  gl.glVertex3f(p2.x, p2.y, 0);
  gl.glEnd();
  gl.glPopMatrix();
}
 
Example #27
Source File: JoglDebugDraw.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void drawParticles(Vec2[] centers, float radius, ParticleColor[] colors, int count) {
  GL2 gl = panel.getGL().getGL2();
  gl.glPushMatrix();
  transformViewport(gl, zero);

  float theta = 2 * MathUtils.PI / NUM_CIRCLE_POINTS;
  float c = MathUtils.cos(theta);
  float s = MathUtils.sin(theta);

  float x = radius;
  float y = 0;

  for (int i = 0; i < count; i++) {
    Vec2 center = centers[i];
    float cx = center.x;
    float cy = center.y;
    gl.glBegin(GL2.GL_TRIANGLE_FAN);
    if (colors == null) {
      gl.glColor4f(1, 1, 1, .4f);
    } else {
      ParticleColor color = colors[i];
      gl.glColor4b(color.r, color.g, color.b, color.a);
    }
    for (int j = 0; j < NUM_CIRCLE_POINTS; j++) {
      gl.glVertex3f(x + cx, y + cy, 0);
      float temp = x;
      x = c * x - s * y;
      y = s * temp + c * y;
    }
    gl.glEnd();
  }
  gl.glPopMatrix();
}
 
Example #28
Source File: TestbedTest.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public boolean reportParticle(int index) {
  Vec2 p = world.getParticlePositionBuffer()[index];
  if (shape.testPoint(xf, p)) {
    Vec2 v = world.getParticleVelocityBuffer()[index];
    v.set(velocity);
  }
  return true;
}
 
Example #29
Source File: PulleyJoint.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public float getLength1() {
  final Vec2 p = pool.popVec2();
  m_bodyA.getWorldPointToOut(m_localAnchorA, p);
  p.subLocal(m_groundAnchorA);

  float len = p.length();
  pool.pushVec2(1);
  return len;
}
 
Example #30
Source File: DynamicTreeTest.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void GetRandomAABB(AABB aabb) {
	Vec2 w = new Vec2();
	w.set(2.0f * m_proxyExtent, 2.0f * m_proxyExtent);
	// aabb.lowerBound.x = -m_proxyExtent;
	// aabb.lowerBound.y = -m_proxyExtent + worldExtent;
	aabb.lowerBound.x = MathUtils.randomFloat(rand, -worldExtent,
			worldExtent);
	aabb.lowerBound.y = MathUtils.randomFloat(rand, 0.0f,
			2.0f * worldExtent);
	aabb.upperBound.set(aabb.lowerBound).addLocal(w);
}