org.jbox2d.dynamics.Body.getWorldCenter()方法的使用及代码示例

x33g5p2x  于2022-01-17 转载在 其他  
字(7.3k)|赞(0)|评价(0)|浏览(203)

本文整理了Java中org.jbox2d.dynamics.Body.getWorldCenter()方法的一些代码示例,展示了Body.getWorldCenter()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Body.getWorldCenter()方法的具体详情如下:
包路径:org.jbox2d.dynamics.Body
类名称:Body
方法名:getWorldCenter

Body.getWorldCenter介绍

[英]Get the world position of the center of mass. Do not modify.
[中]获取质心的世界位置。不要修改。

代码示例

代码示例来源:origin: libgdx/libgdx

private float getBodyArea() {
 float area = 0.0f;
 for (int i = 0; i < bodies.length; ++i) {
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  area +=
    bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
      - bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
 }
 area *= .5f;
 return area;
}

代码示例来源:origin: libgdx/libgdx

public Vector2 getWorldCenter () {
  Vec2 wc = body.getWorldCenter();
  return worldCenter.set(wc.x, wc.y);
}

代码示例来源:origin: libgdx/libgdx

for (int i = 0; i < targetLengths.length; ++i) {
 final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
 float dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length();
 targetLengths[i] = dist;
  djd.initialize(bodies[i], bodies[next], bodies[i].getWorldCenter(),
    bodies[next].getWorldCenter());
  distanceJoints[i] = (DistanceJoint) world.createJoint(djd);

代码示例来源:origin: jbox2d/jbox2d

private float getBodyArea() {
 float area = 0.0f;
 for (int i = 0; i < bodies.length; ++i) {
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  area +=
    bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
      - bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
 }
 area *= .5f;
 return area;
}

代码示例来源:origin: libgdx/libgdx

Vec2 bp = b.getWorldCenter();
float bm = b.getMass();
float bI = b.getInertia() - bm * b.getLocalCenter().lengthSquared();

代码示例来源:origin: jbox2d/jbox2d

for (int i = 0; i < targetLengths.length; ++i) {
 final int next = (i == targetLengths.length - 1) ? 0 : i + 1;
 float dist = bodies[i].getWorldCenter().sub(bodies[next].getWorldCenter()).length();
 targetLengths[i] = dist;
  djd.initialize(bodies[i], bodies[next], bodies[i].getWorldCenter(),
    bodies[next].getWorldCenter());
  distanceJoints[i] = (DistanceJoint) world.createJoint(djd);

代码示例来源:origin: libgdx/libgdx

for (Body b = m_bodyList; b != null; b = b.getNext()) {
 xf.set(b.getTransform());
 xf.p.set(b.getWorldCenter());
 m_debugDraw.drawTransform(xf);

代码示例来源:origin: jbox2d/jbox2d

void Break() {
 // Create two bodies from one.
 Body body1 = m_piece1.getBody();
 Vec2 center = body1.getWorldCenter();
 body1.destroyFixture(m_piece2);
 m_piece2 = null;
 BodyDef bd = new BodyDef();
 bd.type = BodyType.DYNAMIC;
 bd.position = body1.getPosition();
 bd.angle = body1.getAngle();
 Body body2 = getWorld().createBody(bd);
 m_piece2 = body2.createFixture(m_shape2, 1.0f);
 // Compute consistent velocities for new bodies based on
 // cached velocity.
 Vec2 center1 = body1.getWorldCenter();
 Vec2 center2 = body2.getWorldCenter();
 Vec2 velocity1 = m_velocity.add(Vec2.cross(m_angularVelocity, center1.sub(center)));
 Vec2 velocity2 = m_velocity.add(Vec2.cross(m_angularVelocity, center2.sub(center)));
 body1.setAngularVelocity(m_angularVelocity);
 body1.setLinearVelocity(velocity1);
 body2.setAngularVelocity(m_angularVelocity);
 body2.setLinearVelocity(velocity2);
}

代码示例来源:origin: andmizi/MobikeTags

private float getBodyArea() {
 float area = 0.0f;
 for (int i = 0; i < bodies.length; ++i) {
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  area +=
    bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
      - bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
 }
 area *= .5f;
 return area;
}

代码示例来源:origin: com.github.almasb/fxgl-physics

private float getBodyArea() {
  float area = 0.0f;
  for (int i = 0; i < bodies.length; ++i) {
    final int next = (i == bodies.length - 1) ? 0 : i + 1;
    area +=
        bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
            - bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
  }
  area *= .5f;
  return area;
}

代码示例来源:origin: org.jbox2d/jbox2d-library

private float getBodyArea() {
 float area = 0.0f;
 for (int i = 0; i < bodies.length - 1; ++i) {
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  area +=
    bodies[i].getWorldCenter().x * bodies[next].getWorldCenter().y
      - bodies[next].getWorldCenter().x * bodies[i].getWorldCenter().y;
 }
 area *= .5f;
 return area;
}

代码示例来源:origin: stackoverflow.com

this.mScene = new Scene();
   this.mScene.setBackground(new Background(0, 0, 0));
   this.mScene.setOnSceneTouchListener(this);
   this.mScene.setOnAreaTouchListener(this);
   this.mPhysicsWorld = new PhysicsWorld(new Vector2(0, 10), false);
   this.mScene.registerUpdateHandler(this.mPhysicsWorld);
   final Rectangle ground = new Rectangle(0, CAMERA_HEIGHT - 2, CAMERA_WIDTH, 2, vertexBufferObjectManager);
   final Rectangle left = new Rectangle(0, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
   final Rectangle right = new Rectangle(CAMERA_WIDTH - 2, 0, 2, CAMERA_HEIGHT, vertexBufferObjectManager);
   Body g =PhysicsFactory.createBoxBody(this.mPhysicsWorld, ground, BodyType.StaticBody, wallFixtureDef2);
   Body l =PhysicsFactory.createBoxBody(this.mPhysicsWorld, left, BodyType.StaticBody, wallFixtureDef1);
   final float width = 2*g.getWorldCenter().x;
   final float height = 2*l.getWorldCenter().y;

代码示例来源:origin: stackoverflow.com

Body body, planet; //your 'character' and planet
 ...
 Vector2 bodyCenter = body.getWorldCenter();
 Vector2 planetCenter = planet.getWorldCenter(); //if you would use getPosition it would be related to the body's origin!
 Vector2 subVector = bodyCenter.sub( planetCenter );
 body.setTransform(x, y, subVector.angle() ); //it is possible that you will need to make '-angle()' here or something!

代码示例来源:origin: jbox2d/jbox2d

Vec2 bp = b.getWorldCenter();
float bm = b.getMass();
float bI = b.getInertia() - bm * b.getLocalCenter().lengthSquared();

代码示例来源:origin: mirkosertic/GameComposer

void applyImpulse(GameObjectInstance aInstance, Force aForce) {
  Body theBody = dynamicObjects.get(aInstance);
  if (theBody != null) {
    theBody.applyLinearImpulse(new Vec2(aForce.forceX, aForce.forceY), theBody.getWorldCenter());
  }
}

代码示例来源:origin: mirkosertic/GameComposer

void applyForce(GameObjectInstance aInstance, Force aForce) {
  Body theBody = dynamicObjects.get(aInstance);
  if (theBody != null) {
    theBody.applyForce(new Vec2(aForce.forceX, aForce.forceY), theBody.getWorldCenter());
  }
}

代码示例来源:origin: stackoverflow.com

if (keycode == Input.Keys.UP) 
 {
   Body body = player.getBody();
   body.applyLinearImpulse(new Vector2(0, 30000), body.getWorldCenter(), true);
 }

代码示例来源:origin: jbox2d/jbox2d

@Override
public void step(TestbedSettings settings) {
 super.step(settings);
 addTextLine("Use 'wasd' to move, 'e' and 's' drift.");
 if (getModel().getKeys()['w']) {
  Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
  Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(0.0f, 2.0f)));
  m_body.applyForce(f, p);
 } else if (getModel().getKeys()['q']) {
  Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
  Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(-.2f, 0f)));
  m_body.applyForce(f, p);
 } else if (getModel().getKeys()['e']) {
  Vec2 f = m_body.getWorldVector(new Vec2(0.0f, -30.0f));
  Vec2 p = m_body.getWorldPoint(m_body.getLocalCenter().add(new Vec2(.2f, 0f)));
  m_body.applyForce(f, p);
 } else if (getModel().getKeys()['s']) {
  Vec2 f = m_body.getWorldVector(new Vec2(0.0f, 30.0f));
  Vec2 p = m_body.getWorldCenter();
  m_body.applyForce(f, p);
 }
 if (getModel().getKeys()['a']) {
  m_body.applyTorque(20.0f);
 }
 if (getModel().getKeys()['d']) {
  m_body.applyTorque(-20.0f);
 }
}

代码示例来源:origin: stackoverflow.com

Body body, centerBody;
Vector2 center = new Vector2(0, 0);
...

//in render method
float G = 1; //modifier of gravity value - you can make it bigger to have stronger gravity

float distance = body.getPosition().dst( center ); 
float forceValue = G / (distance * distance);

Vector2 direction = center.sub( body.getPosition() ) );

body.applyForce( direction.scl( forceValue ), body.getWorldCenter() );

代码示例来源:origin: jbox2d/jbox2d

for (Body b = m_bodyList; b != null; b = b.getNext()) {
 xf.set(b.getTransform());
 xf.p.set(b.getWorldCenter());
 m_debugDraw.drawTransform(xf);

相关文章