Hello!
I'm brand new here, and that means I'm ignorant. I just came out wrestling with the bot filtering question, so here's a question of my own.
I've read up on theories, API docs, manuals, source, or at least where I think I should look. I'm fluent in Java, but not in APIs. So I guess that's my problem.
I'm working with the Slick framework, and trying to mess around with JBox2D. At the moment, I've actually tried making a ground line, and drop a circle on it. However, the circle does not seem to be dropping. Here is my code:
So theoretically, the "yPosition" should start at 7, and then go to 0 as the gravity pulls it down. However, instead, it just starts and stays at 0. I'm obviously doing something wrong.
Maybe someone could help here? I'm kinda shmooped about this, as I haven't been able to get a single physics engine to play nicely. I've also tried Fizzy, Phys2D, and dyn4j, and no luck.
So if anyone can help me here, or tell me about a different physics engine, that'll be great, thanks!
Thanks for your attention!
P.S. What were you trying to do with those Bot Filter questions? "How may additional axes of rotation does a 3d object has as opposed to..." You would almost think that this site was exclusive to intellectuals. 🙂
I'm brand new here, and that means I'm ignorant. I just came out wrestling with the bot filtering question, so here's a question of my own.
I've read up on theories, API docs, manuals, source, or at least where I think I should look. I'm fluent in Java, but not in APIs. So I guess that's my problem.
I'm working with the Slick framework, and trying to mess around with JBox2D. At the moment, I've actually tried making a ground line, and drop a circle on it. However, the circle does not seem to be dropping. Here is my code:
Code: Select all
package game.state;
import org.jbox2d.collision.shapes.CircleShape;
import org.jbox2d.collision.shapes.PolygonShape;
import org.jbox2d.common.Vec2;
import org.jbox2d.dynamics.Body;
import org.jbox2d.dynamics.BodyDef;
import org.jbox2d.dynamics.BodyType;
import org.jbox2d.dynamics.World;
import org.newdawn.slick.Color;
import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.state.BasicGameState;
import org.newdawn.slick.state.StateBasedGame;
public class BoxTest extends BasicGameState {
private int state;
public BoxTest(int state)
{
this.state = state;
}
//Creates world.
Vec2 GRAVITY = new Vec2 (0,-10);
World world = new World(GRAVITY, true);
//Creates the ground.
BodyDef bd = new BodyDef();
//Creates the dynamic circle.
BodyDef cbd = new BodyDef();
Body circleBody = world.createBody(cbd);
public void create()
{
//ground.
Body ground = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsEdge(new Vec2(-40.0f, 0.0f), new Vec2(40.0f, 0.0f));
ground.createFixture(shape, 0.0f);
//circle.
CircleShape cshape = new CircleShape();
cshape.m_radius = 1.0f;
cbd.type = BodyType.DYNAMIC;
cbd.position.set(0.0f, 7f);
circleBody.createFixture(cshape, 1.0f);
}
@Override
public void init(GameContainer container, StateBasedGame game)
throws SlickException {
// TODO Auto-generated method stub
create();
}
String yPosition = "0";
@Override
public void render(GameContainer container, StateBasedGame game, Graphics g)
throws SlickException {
// TODO Auto-generated method stub
g.setBackground(Color.blue);
g.drawString("PhysTest", 6, 460);
//Step.
world.step(1/60, 6, 2);
//Show y position.
yPosition = Float.toString(circleBody.getPosition().y);
//yPosition = body.getPosition().y;
System.out.println(yPosition);
g.drawString(yPosition, 450, 450);
}
@Override
public void update(GameContainer container, StateBasedGame game, int delta)
throws SlickException {
// TODO Auto-generated method stub
//world.step(timeStep, velocityIterations, positionIterations);
}
@Override
public int getID() {
// TODO Auto-generated method stub
return 0;
}
}
So theoretically, the "yPosition" should start at 7, and then go to 0 as the gravity pulls it down. However, instead, it just starts and stays at 0. I'm obviously doing something wrong.
Maybe someone could help here? I'm kinda shmooped about this, as I haven't been able to get a single physics engine to play nicely. I've also tried Fizzy, Phys2D, and dyn4j, and no luck.
So if anyone can help me here, or tell me about a different physics engine, that'll be great, thanks!
Thanks for your attention!
P.S. What were you trying to do with those Bot Filter questions? "How may additional axes of rotation does a 3d object has as opposed to..." You would almost think that this site was exclusive to intellectuals. 🙂