Fisica issues

edited February 2014 in Library Questions

I am testing Fisica and found several issues: (1) FCompound does not have getBodies() method mentioned in the javadoc; (2) addImpulse to (0, 0) cause a FCompound to move without rotation, even when (0, 0) is not the center of mass; (3) addForce() seems to have no effect on FBody.

My test codes are copied below:

import fisica.util.nonconvex.*; import fisica.*;

FWorld world;

void setup() { size(500, 500);

Fisica.init(this); world = new FWorld(); world.setEdges(); world.setEdgesFriction(0.5); world.setEdgesRestitution(0.5);

FCompound m = new FCompound();

FBox b = new FBox(20, 60); m.addBody(b); FCircle c = new FCircle(80); c.setPosition(0, -70); m.addBody(c);

// this line will cause error: getBodies() does not exist //ArrayList list = m.getBodies();

println("b:", b.getX(), b.getY()); println("c:", c.getX(), c.getY()); println("m:", m.getX(), m.getY());

m.setPosition(random(20, width-20), random(80, height-80)); world.add(m);
}

void draw() { background(204);

ArrayList list = world.getBodies();

// the body moves without rotation whether the last two // parameters are provided or not, even though (0, 0) // definitely is not the center of mass in this case list.get(0).addImpulse(50, 0, 0, 0);

// replacing addImpulse above by addForce below and the // body does not move sideways, implying addForce has no // effect //list.get(0).addForce(50, 0, 0, 0);

world.step(); world.draw();

}

Any suggestions are deeply appreciated!

Huanchun

Tagged:

Answers

  • I had a chance to compare the source code of Fisica vs JBox2d vs Box2d and found that Fisica does not seem to do mass computation correctly. For example, when a vertex is added to FPoly, it is only added to an ArrayList which is used for drawing; there is no mass calculation. The same goes when a FBody is added to a FCompound. Therefore I think the physics in Fisica is probably only correct for simple shapes like FBox and FCircle.

  • Don't know if anyone else is looking at similar addForce/addImpulse issues, but here goes.

    I can get FBox.addImpulse() to work. But I have to call FWorld.step() first, at least once. Otherwise FBox.addImpulse() is ignored.

    I can also get FBlob.addForce() to work, after the first FWorld.step(). But oddly enough, FBlob.addImpulse() doesn't work!

    Hope this helps.

    Bill

Sign In or Register to comment.