本文整理汇总了Java中org.jbox2d.dynamics.BodyType.DYNAMIC属性的典型用法代码示例。如果您正苦于以下问题:Java BodyType.DYNAMIC属性的具体用法?Java BodyType.DYNAMIC怎么用?Java BodyType.DYNAMIC使用的例子?那么, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在类org.jbox2d.dynamics.BodyType
的用法示例。
在下文中一共展示了BodyType.DYNAMIC属性的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: makeBody
void makeBody(Vec2 center, float w_, float h_) {
// Define a polygon (this is what we use for a rectangle)
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w_ / 2);
float box2dH = box2d.scalarPixelsToWorld(h_ / 2);
sd.setAsBox(box2dW, box2dH);
// Define a fixture
FixtureDef fd = new FixtureDef();
fd.shape = sd;
// Parameters that affect physics
fd.density = 1;
fd.friction = 0.3F;
fd.restitution = 0.5F;
// Define the body and make it from the shape
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(box2d.coordPixelsToWorld(center));
body = box2d.createBody(bd);
body.createFixture(fd);
// Give it some initial random velocity
shake();
}
示例2: reportFixture
@Override
public boolean reportFixture(Fixture argFixture) {
Body body = argFixture.getBody();
// static bodies can be moved too, but need to set to dynamic for the
// mouse-joint to work.
BodyType type = body.getType();
if (BodyType.DYNAMIC == type || enable_static_drag) {
if (argFixture.testPoint(point)) {
body_type_cpy = type;
fixture = argFixture;
body.setType(BodyType.DYNAMIC);
return false;
}
}
return true;
}
示例3: Init
@Override
public synchronized void Init()
{
//System.out.println("init");
Vector2 meters = Coordinates.PixelsToMeters(this.position);
Vector2 meterssize = Coordinates.PixelsToMeters(this.size);
//System.out.println("Metersize: " + meterssize.ToString());
//System.out.println("Metersize to pixels: " + Coordinates.MetersToPixels(meterssize).ToString());
//System.out.println("this.size is " + this.size.ToString());
this.physics = new BoxPhysics(meters.x, meters.y, meterssize.x, meterssize.y, (this.simulatePhysics) ? BodyType.DYNAMIC : BodyType.KINEMATIC, this, this.information);
this.physics.Create();
//this.physics.GetPhysicsBody().setFixedRotation(false);
//this.physics.GetPhysicsBody().setBullet(true);
super.Init();
System.out.println("My name is " + this.name);
//System.out.println("Physics size is " + this.physics.GetPhysicsBody().getToString());
}
示例4: createCircle
public void createCircle()
{
float radius = 2.0f;
CircleShape shape = new CircleShape();
shape.m_p.setZero();
shape.m_radius = radius;
FixtureDef fd = new FixtureDef();
fd.shape = shape;
fd.density = 1.0f;
fd.friction = 0.0f;
Vec2 p = new Vec2((float)Math.random(), 3.0f + (float)Math.random());
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position = p;
//bd.allowSleep = false;
Body body = m_world.createBody(bd);
body.createFixture(fd);
}
示例5: step
@Override
public void step(TestbedSettings settings) {
super.step(settings);
for (Body b = m_world.getBodyList(); b != null; b = b.getNext())
{
if (b.getType() != BodyType.DYNAMIC)
{
continue;
}
Vec2 p = b.getPosition();
if (p.x <= -10.0f || 10.0f <= p.x || p.y <= 0.0f || 20.0f <= p.y)
{
p.x += 0.0;
}
}
addTextLine("Press 'c' to create a circle");
}
示例6: makeDomino
public void makeDomino(float x, float y, boolean horizontal, World world) {
PolygonShape sd = new PolygonShape();
sd.setAsBox(.5f*dwidth, .5f*dheight);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = ddensity;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
fd.friction = dfriction;
fd.restitution = 0.65f;
bd.position = new Vec2(x, y);
bd.angle = horizontal? (float)(Math.PI/2.0):0f;
Body myBody = world.createBody(bd);
myBody.createFixture(fd);
}
示例7: initTest
@Override
public void initTest() {
setTitle("Couple of Things Test");
m_world.setGravity(new Vec2());
for (int i = 0; i < 2; i++)
{
// CircleShape circleShape = new CircleShape();
// circleShape.m_radius = 1;
// Shape shape = circleShape;
PolygonShape polygonShape = new PolygonShape();
polygonShape.setAsBox(1, 1);
Shape shape = polygonShape;
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position.set(5 * i, 0);
bodyDef.angle = (float) (Math.PI / 4 * i);
bodyDef.allowSleep = false;
Body body = m_world.createBody(bodyDef);
body.createFixture(shape, 5.0f);
body.applyForce(new Vec2(-10000 * (i - 1), 0), new Vec2());
}
}
示例8: init
/**
* Sets up the actual physics part of this helper class.
*
* As always call super or else this definition has no use and you get crashing.
*/
@Override
public void init(Scene scene) {
BodyDef def = new BodyDef();
if (isDynamic) {
def.type = BodyType.DYNAMIC;
}
else {
def.type = BodyType.STATIC;
}
body = scene.world2D.createBody(def);
body.setUserData(this);
if (isBullet) {
body.setBullet(true);
}
}
示例9: init
@Override
public void init(RunConfig config) throws InvalidTestFormatException {
super.init(config);
gravity = new Vec2(0.0f, -10.0f);
platformFixtureDef = new FixtureDef();
PolygonShape platformPolygonShape = new PolygonShape();
platformPolygonShape.setAsBox(15.0f, 0.1f);
platformFixtureDef.shape = platformPolygonShape;
dominoFixtureDef = new FixtureDef();
PolygonShape dominoPolygonShape = new PolygonShape();
dominoPolygonShape.setAsBox(0.2f, 2.5f);
dominoFixtureDef.shape = dominoPolygonShape;
dominoFixtureDef.density = 25.0f;
dominoFixtureDef.friction = .5f;
dominoBody = new BodyDef();
dominoBody.type = BodyType.DYNAMIC;
floorFixtureDef = new FixtureDef();
PolygonShape floorPolygonShape = new PolygonShape();
floorPolygonShape.setAsBox(60.0f, 5.0f);
floorFixtureDef.shape = floorPolygonShape;
floor = new BodyDef();
}
示例10: initPhysicsBody
@Override
Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
CircleShape circleShape = new CircleShape();
circleShape.m_radius = getRadius();
fixtureDef.shape = circleShape;
fixtureDef.density = 0.4f;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 0.35f;
circleShape.m_p.set(0, 0);
body.createFixture(fixtureDef);
body.setLinearDamping(0.2f);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例11: initPhysicsBody
Body initPhysicsBody(World world, float x, float y, float angle) {
FixtureDef fixtureDef = new FixtureDef();
BodyDef bodyDef = new BodyDef();
bodyDef.type = BodyType.DYNAMIC;
bodyDef.position = new Vec2(0, 0);
Body body = world.createBody(bodyDef);
PolygonShape polygonShape = new PolygonShape();
Vec2[] polygon = new Vec2[4];
polygon[0] = new Vec2(-getWidth() / 2f, -getHeight() / 2f + getTopOffset());
polygon[1] = new Vec2(getWidth() / 2f, -getHeight() / 2f + getTopOffset());
polygon[2] = new Vec2(getWidth() / 2f, polygon[0].y + getSpringBoxHeight());
polygon[3] = new Vec2(-getWidth() / 2f, polygon[1].y + getSpringBoxHeight());
polygonShape.set(polygon, polygon.length);
fixtureDef.shape = polygonShape;
fixtureDef.friction = 0.1f;
fixtureDef.restitution = 1.4f;
body.createFixture(fixtureDef);
body.setTransform(new Vec2(x, y), angle);
return body;
}
示例12: setType
/**
* Sets the simulation type of the physical body. It can be one of the values
* {@link Behavior#STATIC}, {@link Behavior#DYNAMIC}, or {@link Behavior#KINEMATIC}.
*
* @param type The desired simulation type
*
* @see Behavior
*/
public final void setType(Behavior type) {
if (body != null) {
switch (type) {
case DYNAMIC:
body.m_type = BodyType.DYNAMIC;
break;
case STATIC:
body.m_type = BodyType.STATIC;
break;
default:
body.m_type = BodyType.KINEMATIC;
break;
}
} else desc.type = type;
}
示例13: step
@Override
public synchronized void step(TestbedSettings settings) {
super.step(settings);
if (m_count < MAX_NUM) {
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(0.0f, 10.0f);
Body body = m_world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.125f, 0.125f);
body.createFixture(shape, 1.0f);
++m_count;
}
}
示例14: step
@Override
public void step(TestbedSettings settings) {
super.step(settings);
for (Body b = getWorld().getBodyList(); b != null; b = b.getNext())
{
if (b.getType() != BodyType.DYNAMIC)
{
continue;
}
Vec2 p = b.getPosition();
if (p.x <= -10.0f || 10.0f <= p.x || p.y <= 0.0f || 20.0f <= p.y)
{
p.x += 0.0;
}
}
addTextLine("Press 'c' to create a circle");
}
示例15: makeDomino
public void makeDomino(float x, float y, boolean horizontal, World world) {
PolygonShape sd = new PolygonShape();
sd.setAsBox(.5f * dwidth, .5f * dheight);
FixtureDef fd = new FixtureDef();
fd.shape = sd;
fd.density = ddensity;
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
fd.friction = dfriction;
fd.restitution = 0.65f;
bd.position = new Vec2(x, y);
bd.angle = horizontal ? (float) (Math.PI / 2.0) : 0f;
Body myBody = getWorld().createBody(bd);
myBody.createFixture(fd);
}