Here's a webstart of a ball rolling when it seems like ti shouldn't.
http://anotherearlymorning.com/games/rollingwrong.jnlp
If you let this run the ball will roll off eventually.
Perhaps I'm just not setting the friction high enough?
Here's the source code for the ball and bricks:
Code:
package com.anotherearlymorning.glide;
import net.phys2d.math.Vector2f;
import net.phys2d.raw.Body;
import net.phys2d.raw.shapes.Circle;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import com.anotherearlymorning.base.AbstractEntity;
import com.anotherearlymorning.base.Entity;
import com.anotherearlymorning.base.Role;
public class Ball extends AbstractEntity {
private static final float FRICTION = 5f;
private static final float RESTITUTION = .9f;
public Ball(float x, float y, float d, float m) {
super(Role.BALL, d, d);
body = new Body(new Circle(d / 2), m);
body.setUserData(this);
body.setPosition(x + d / 2, y + d / 2);
body.setFriction(FRICTION);
body.setRestitution(RESTITUTION);
body.setMaxVelocity(20, 50);
body.addForce(new Vector2f(100, 0));
}
public void collide(Entity e) {
// TODO Auto-generated method stub
}
protected void onDestroy() {
// TODO Auto-generated method stub
}
public void render(GameContainer container, Graphics g) {
g.drawOval(x(), y(), width(), height());
}
public void update(GameContainer container, int delta) {
// TODO Auto-generated method stub
}
}
Code:
package com.anotherearlymorning.glide;
import net.phys2d.raw.StaticBody;
import net.phys2d.raw.shapes.Box;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import com.anotherearlymorning.base.AbstractEntity;
import com.anotherearlymorning.base.Entity;
import com.anotherearlymorning.base.Role;
public class Brick extends AbstractEntity {
private static final float FRICTION = 5f;
private static final float RESTITUTION = .3f;
public Brick(float x, float y, float w, float h) {
super(Role.BRICK, w, h);
body = new StaticBody(new Box(w, h));
body.setUserData(this);
body.setPosition(x + w / 2, y + h / 2);
body.setFriction(FRICTION);
body.setRestitution(RESTITUTION);
body.setRotatable(false);
}
@Override
protected void onDestroy() {
// TODO Auto-generated method stub
}
public void collide(Entity e) {
// TODO Auto-generated method stub
}
public void render(GameContainer container, Graphics g) {
g.drawRect(x(), y(), width(), height());
}
public void update(GameContainer container, int delta) {
// TODO Auto-generated method stub
}
}