Java Code Examples for org.jbox2d.common.Settings#EPSILON

The following examples show how to use org.jbox2d.common.Settings#EPSILON . 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: 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 2
Source File: SensorTest.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
@Override
public void step(TestbedSettings settings) {
  // TODO Auto-generated method stub
  super.step(settings);

  // Traverse the contact results. Apply a force on shapes
  // that overlap the sensor.
  for (int i = 0; i < e_count; ++i) {
    if (m_touching[i].tf == false) {
      continue;
    }

    Body body = m_bodies[i];
    Body ground = m_sensor.getBody();

    CircleShape circle = (CircleShape) m_sensor.getShape();
    Vec2 center = ground.getWorldPoint(circle.m_p);

    Vec2 position = body.getPosition();

    Vec2 d = center.sub(position);
    if (d.lengthSquared() < Settings.EPSILON * Settings.EPSILON) {
      continue;
    }

    d.normalize();
    Vec2 F = d.mulLocal(100f);
    body.applyForce(F, position);
  }
}
 
Example 3
Source File: DynamicTreeTest.java    From jbox2d with BSD 2-Clause "Simplified" License 5 votes vote down vote up
public void RayCast() {
	m_rayActor = null;

	RayCastInput input = new RayCastInput();
	input.set(m_rayCastInput);

	// Ray cast against the dynamic tree.
	m_tree.raycast(this, input);

	// Brute force ray cast.
	Actor bruteActor = null;
	RayCastOutput bruteOutput = new RayCastOutput();
	for (int i = 0; i < e_actorCount; ++i) {
		if (m_actors[i].proxyId == -1) {
			continue;
		}

		RayCastOutput output = new RayCastOutput();
		boolean hit = m_actors[i].aabb.raycast(output, input,
				getWorld().getPool());
		if (hit) {
			bruteActor = m_actors[i];
			bruteOutput = output;
			input.maxFraction = output.fraction;
		}
	}

	if (bruteActor != null) {
	  if(MathUtils.abs(bruteOutput.fraction
                   - m_rayCastOutput.fraction) > Settings.EPSILON) {
	    System.out.println("wrong!");
	    assert (MathUtils.abs(bruteOutput.fraction
             - m_rayCastOutput.fraction) <= 20 * Settings.EPSILON);
	  }
		
	}
}