Fixed point available in JBox2D?

Although the thread is a little old now, I still wanted to share a few things. I am the author of the afforementioned Emini Engine.
I have written a small ant script that acts basically as a precompiler to "inline" important vector calls (like dot or cross product). This overcomes the problem of the mentioned method calls in the vector math part without making the code awkward to read, write and maintain. And yeah I'm really looking forward to the JIT compiler as well.

Also beeing the developer I have to defend my Engine. I wouldn't say it has less features, it rather has different features. Instead of a myriad of different constraints, it include particle emitters and world loading from file.
//Updated to rev 100

/**
* A circle shape.
*/
public class CircleShape extends Shape {

public final Vec2 m_p;

/**
* this is used internally, instead use {@link Body#createShape(ShapeDef)} with a {@link CircleDef}
* @see Body#createShape(ShapeDef)
* @see CircleDef
* @param def
*/
public CircleShape(){
m_type = ShapeType.CIRCLE;
m_p = new Vec2();
m_radius = 0;
}

public final Shape clone(){
CircleShape shape = new CircleShape();
shape.m_p.set(m_p);
shape.m_radius = m_radius;
return shape;
}

/**
* Get the supporting vertex index in the given direction.
* @param d
* @return
*/
public final int getSupport(final Vec2 d){
return 0;
}

/**
* Get the supporting vertex in the given direction.
* @param d
* @return
*/
public final Vec2 getSupportVertex( final Vec2 d){
return m_p;
}

/**
* Get the vertex count.
* @return
*/
public final int getVertexCount() {
return 1;
}

/**
* Get a vertex by index. Used by Distance.
* @param index
* @return
*/
public final Vec2 getVertex(final int index){
assert(index == 0);
return m_p;
}

// djm pooling
private final static TLVec2 tlcenter = new TLVec2();
/**
* @see Shape#testPoint(Transform, Vec2)
*/
@Override
public final boolean testPoint(final Transform transform, final Vec2 p) {
final Vec2 center = tlcenter.get();
Mat22.mulToOut(transform.R, m_p, center);
center.addLocal(transform.position);

final Vec2 d = center.subLocal(p).negateLocal();
return Vec2.dot(d, d) <= m_radius * m_radius;
}


// Collision Detection in Interactive 3D Environments by Gino van den Bergen
// From Section 3.1.2
// x = s + a * r
// norm(x) = radius
// djm pooled
private static final TLVec2 tlposition = new TLVec2();
private static final TLVec2 tls = new TLVec2();
private static final TLVec2 tlr = new TLVec2();
/**
* @see Shape#raycast(org.jbox2d.structs.collision.RayCastOutput, org.jbox2d.structs.collision.RayCastInput, org.jbox2d.common.Transform, int)
*/
@Override
public final boolean raycast( RayCastOutput argOutput, RayCastInput argInput, Transform argTransform){

final Vec2 position = tlposition.get();;
final Vec2 s = tls.get();
final Vec2 r = tlr.get();

Mat22.mulToOut( argTransform.R, m_p, position);
position.addLocal( argTransform.position);
s.set( argInput.p1).subLocal(position);
final float b = Vec2.dot( s, s) - m_radius * m_radius;

// Solve quadratic equation.
r.set(argInput.p2).subLocal(argInput.p1);
final float c = Vec2.dot(s, r);
final float rr = Vec2.dot(r, r);
final float sigma = c * c - rr * b;

// Check for negative discriminant and short segment.
if (sigma < 0.0f || rr < Settings.EPSILON){
return false;
}

// Find the point of intersection of the line with the circle.
float a = -(c + MathUtils.sqrt(sigma));

// Is the intersection point on the segment?
if (0.0f <= a && a <= argInput.maxFraction * rr){
a /= rr;
argOutput.fraction = a;
argOutput.normal.set(r).mulLocal( a);
argOutput.normal.addLocal(s);
argOutput.normal.normalize();
return true;
}

return false;
}




________________________________________________________________




Want to get-on Google's first page and loads of traffic to your website? Hire a SEO specialist from Ocean Groups seo specialist

Original thread: https://box2d.org/forum/viewtopic.php?t=5170