本文整理汇总了Java中org.jbox2d.dynamics.BodyType类的典型用法代码示例。如果您正苦于以下问题:Java BodyType类的具体用法?Java BodyType怎么用?Java BodyType使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
BodyType类属于org.jbox2d.dynamics包,在下文中一共展示了BodyType类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: Wall
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
Wall(Box2DProcessing box2d, float x_, float y_, float w_, float h_) {
this.box2d = box2d;
x = x_;
y = y_;
w = w_;
h = h_;
PolygonShape sd = new PolygonShape();
float box2dW = box2d.scalarPixelsToWorld(w / 2);
float box2dH = box2d.scalarPixelsToWorld(h / 2);
sd.setAsBox(box2dW, box2dH);
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(box2d.coordPixelsToWorld(x, y));
b = box2d.createBody(bd);
// Attached the shape to the body using a Fixture
b.createFixture(sd, 1);
}
示例2: makeBody
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
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();
}
示例3: testNewWorld
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
@Test
public void testNewWorld() {
World world = new World(new Vec2(0, -9.8f));
BodyDef axisDef = new BodyDef();
axisDef.type = BodyType.STATIC;
axisDef.position = new Vec2(3, 3);
Body axis = world.createBody(axisDef);
CircleShape axisShape = new CircleShape();
axisShape.setRadius(0.02f);
axisShape.m_p.set(0, 0);
//FixtureDef axisFixture = new FixtureDef();
//axisFixture.shape = axisShape;
//axis.createFixture(axisFixture);
}
示例4: Ground
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
public Ground(Texture texture) {
super(new Vec2(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2),texture);
//Body def
BodyDef bd = new BodyDef();
bd.type = BodyType.STATIC;
bd.position.set(Public.box2d.coordPixelsToWorld(WINDOW_WIDTH/2,WINDOW_HEIGHT-texture.getTexture().height/2) );
bd.setUserData("PhysicalGameObject,Ground");
//Create body
body = Public.box2d.createBody(bd);
//Creat Shape
PolygonShape ps = new PolygonShape();
ps.setAsBox(Public.box2d.scalarPixelsToWorld(Public.p.width*100),-Public.box2d.scalarPixelsToWorld(-texture.getTexture().height/2) );
//Fixture
FixtureDef fd = new FixtureDef();
fd.shape = ps;
fd.density = 1f;
fd.friction = 0.3f;
fd.restitution = 0.15f;
body.createFixture(fd);
}
示例5: addBodies
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
public void addBodies(){
if (m_count < MAX_NUM) {
float x = random(-0.7f, 0.7f);
float y = random(-0.7f, 0.7f);
BodyDef bd = new BodyDef();
bd.type = BodyType.DYNAMIC;
bd.position.set(x, y);
Body body = world.createBody(bd);
PolygonShape shape = new PolygonShape();
shape.setAsBox(0.18f, 0.18f);
Fixture fixture = body.createFixture(shape, 0.01f);
fixture.m_friction = 0.1f;
fixture.m_restitution = 0.5f;
++m_count;
colorMode(HSB, 360, 100, 100);
float hue = (360 * m_count /(float)MAX_NUM) % 360;
world.bodies.add(body, true, color(hue, 100, 100), true, color(hue, 100, 50), 1f);
colorMode(RGB, 255, 255, 255);
}
}
示例6: DwMouseShootBullet
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
public DwMouseShootBullet(World world, DwViewportTransform transform){
this.world = world;
this.transform = transform;
// bullet specific settings
cirlce_shape.m_radius = 0.3f;
fixture_def.shape = cirlce_shape;
fixture_def.density = 200f;
fixture_def.restitution = 0.1f;
body_def.type = BodyType.DYNAMIC;
body_def.bullet = true;
body_dragger = new DwMouseDragBodies(world, transform);
}
示例7: reportFixture
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
@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;
}
示例8: Init
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
@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());
}
示例9: GroundPhysics
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
public GroundPhysics(float x, float y, float w, float h, BodyType type, Ground ground)
{
super(new PhysicsInformation(0, 0, false));
BodyDef def = new BodyDef();
def.position.set(new Vec2(x, y));
def.type = type;
def.angle = 0;
this.body = Game.world.createBody(def);
PolygonShape shape = new PolygonShape();
shape.setAsBox(w/2, h/2);
FixtureDef fixture = new FixtureDef();
Filter filter = new Filter();
filter.groupIndex = 1;
fixture.density = 0.1f;
fixture.setShape(shape);
fixture.setFilter(filter);
fixture.isSensor = false;
fixture.setFriction(0.5f);
fixture.restitution = 0;
fixture.density = 1;
fixture.friction = 1;
fixture.setUserData(ground);
body.createFixture(fixture);
}
示例10: step
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#step(org.jbox2d.testbed.framework.TestbedSettings)
*/
@Override
public void step(TestbedSettings settings) {
super.step(settings);
addTextLine("Keys: (d) dynamic, (s) static, (k) kinematic");
// Drive the kinematic body.
if (m_platform.getType() == BodyType.KINEMATIC) {
Vec2 p = m_platform.getTransform().position;
Vec2 v = m_platform.getLinearVelocity();
if ((p.x < -10.0f && v.x < 0.0f) || (p.x > 10.0f && v.x > 0.0f)) {
v.x = -v.x;
m_platform.setLinearVelocity(v);
}
}
}
示例11: keyPressed
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
/**
* @see org.jbox2d.testbed.framework.TestbedTest#keyPressed(char, int)
*/
@Override
public void keyPressed(char argKeyChar, int argKeyCode) {
switch (argKeyChar) {
case 'd' :
m_platform.setType(BodyType.DYNAMIC);
break;
case 's' :
m_platform.setType(BodyType.STATIC);
break;
case 'k' :
m_platform.setType(BodyType.KINEMATIC);
m_platform.setLinearVelocity(new Vec2(-m_speed, 0.0f));
m_platform.setAngularVelocity(0.0f);
break;
}
}
示例12: createCircle
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
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);
}
示例13: step
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
@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");
}
示例14: makeDomino
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
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);
}
示例15: initTest
import org.jbox2d.dynamics.BodyType; //导入依赖的package包/类
@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());
}
}