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

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

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

Body.getWorldPoint介绍

[英]Get the world coordinates of a point given the local coordinates.
[中]获取给定局部坐标的点的世界坐标。

代码示例

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

/** Get the world coordinates of a point given the local coordinates.
 * @param localPoint a point on the body measured relative to the the body's origin.
 * @return the same point expressed in world coordinates. */
public Vector2 getWorldPoint (Vector2 localPoint) {
  tmp.set(localPoint.x, localPoint.y);
  Vec2 wp = body.getWorldPoint(tmp);
  return worldPoint.set(wp.x, wp.y);
}

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

jd.localAnchorA.set(-10.0f, 0.0f);
jd.localAnchorB.set(-0.5f, -0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(10.0f, 0.0f);
jd.localAnchorB.set(0.5f, -0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(10.0f, 20.0f);
jd.localAnchorB.set(0.5f, 0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(-10.0f, 20.0f);
jd.localAnchorB.set(-0.5f, 0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(0.5f, 0.0f);

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

@Override
public void step(TestbedSettings settings) {
 // TODO Auto-generated method stub
 super.step(settings);
 // Traverse the contact results. Apply a force on shapes
 // that overlap the sensor.
 for (int i = 0; i < e_count; ++i) {
  if (m_touching[i].tf == false) {
   continue;
  }
  Body body = m_bodies[i];
  Body ground = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 center = ground.getWorldPoint(circle.m_p);
  Vec2 position = body.getPosition();
  Vec2 d = center.sub(position);
  if (d.lengthSquared() < Settings.EPSILON * Settings.EPSILON) {
   continue;
  }
  d.normalize();
  Vec2 F = d.mulLocal(100f);
  body.applyForce(F, position);
 }
}

代码示例来源: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

public MouseJoint createMouseJoint(AnimatedSprite box , float x, float y)
{
  final Body boxBody =
  this.mPhysicsWorld.getPhysicsConnectorManager().findBodyByShape(box);

  Vector2 v = boxBody.getWorldPoint(
          new Vector2(x/pixelToMeteRatio, y/pixelToMeteRatio)
          );

  MouseJointDef mjd = new MouseJointDef();
  mjd.bodyA               = groundBody;
  mjd.bodyB               = boxBody;
  mjd.dampingRatio        = 0.2f;
  mjd.frequencyHz         = 30;
  mjd.maxForce            = (float) (200.0f * boxBody.getMass());
  mjd.collideConnected    = true;
  mjd.target.set(v);
  return (MouseJoint) this.mPhysicsWorld.createJoint(mjd);
}

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

jd.localAnchorA.set(-10.0f, 0.0f);
jd.localAnchorB.set(-0.5f, -0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(10.0f, 0.0f);
jd.localAnchorB.set(0.5f, -0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(10.0f, 20.0f);
jd.localAnchorB.set(0.5f, 0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(-10.0f, 20.0f);
jd.localAnchorB.set(-0.5f, 0.5f);
p1 = jd.bodyA.getWorldPoint(jd.localAnchorA);
p2 = jd.bodyB.getWorldPoint(jd.localAnchorB);
d = p2.sub(p1);
jd.length = d.length();
jd.localAnchorA.set(0.5f, 0.0f);

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

@Override
public void step(TestbedSettings settings) {
 // TODO Auto-generated method stub
 super.step(settings);
 // Traverse the contact results. Apply a force on shapes
 // that overlap the sensor.
 for (int i = 0; i < e_count; ++i) {
  if (m_touching[i].tf == false) {
   continue;
  }
  Body body = m_bodies[i];
  Body ground = m_sensor.getBody();
  CircleShape circle = (CircleShape) m_sensor.getShape();
  Vec2 center = ground.getWorldPoint(circle.m_p);
  Vec2 position = body.getPosition();
  Vec2 d = center.sub(position);
  if (d.lengthSquared() < Settings.EPSILON * Settings.EPSILON) {
   continue;
  }
  d.normalize();
  Vec2 F = d.mulLocal(100f);
  body.applyForce(F, position);
 }
}

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

@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);
 }
}

相关文章