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

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

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

Body.getMass介绍

[英]Get the total mass of the body.
[中]得到物体的总质量。

代码示例

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

/** Get the total mass of the body.
 * @return the mass, usually in kilograms (kg). */
public float getMass () {
  return body.getMass();
}

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

@Override
public void solveVelocityConstraints(final SolverData step) {
 float crossMassSum = 0.0f;
 float dotMassSum = 0.0f;
 Velocity[] velocities = step.velocities;
 Position[] positions = step.positions;
 final Vec2 d[] = pool.getVec2Array(bodies.length);
 for (int i = 0; i < bodies.length; ++i) {
  final int prev = (i == 0) ? bodies.length - 1 : i - 1;
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  d[i].set(positions[bodies[next].m_islandIndex].c);
  d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
  dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
  crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
 }
 float lambda = -2.0f * crossMassSum / dotMassSum;
 // System.out.println(crossMassSum + " " +dotMassSum);
 // lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
 // Settings.maxLinearCorrection);
 m_impulse += lambda;
 // System.out.println(m_impulse);
 for (int i = 0; i < bodies.length; ++i) {
  velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
  velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
 }
}

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

Body b = fixture.getBody();
Vec2 bp = b.getWorldCenter();
float bm = b.getMass();
float bI = b.getInertia() - bm * b.getLocalCenter().lengthSquared();
float invBm = bm > 0 ? 1 / bm : 0;

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

float mass = m_bodyB.getMass();

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

float mass1 = body1.getMass();
float mass2 = body2.getMass();

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

@Override
public void solveVelocityConstraints(final SolverData step) {
 float crossMassSum = 0.0f;
 float dotMassSum = 0.0f;
 Velocity[] velocities = step.velocities;
 Position[] positions = step.positions;
 final Vec2 d[] = pool.getVec2Array(bodies.length);
 for (int i = 0; i < bodies.length; ++i) {
  final int prev = (i == 0) ? bodies.length - 1 : i - 1;
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  d[i].set(positions[bodies[next].m_islandIndex].c);
  d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
  dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
  crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
 }
 float lambda = -2.0f * crossMassSum / dotMassSum;
 // System.out.println(crossMassSum + " " +dotMassSum);
 // lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
 // Settings.maxLinearCorrection);
 m_impulse += lambda;
 // System.out.println(m_impulse);
 for (int i = 0; i < bodies.length; ++i) {
  velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
  velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
 }
}

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

private void spawnMouseJoint(Vec2 p) {
 if (mouseJoint != null) {
  return;
 }
 queryAABB.lowerBound.set(p.x - .001f, p.y - .001f);
 queryAABB.upperBound.set(p.x + .001f, p.y + .001f);
 callback.point.set(p);
 callback.fixture = null;
 m_world.queryAABB(callback, queryAABB);
 if (callback.fixture != null) {
  Body body = callback.fixture.getBody();
  MouseJointDef def = new MouseJointDef();
  def.bodyA = groundBody;
  def.bodyB = body;
  def.collideConnected = true;
  def.target.set(p);
  def.maxForce = 1000f * body.getMass();
  mouseJoint = (MouseJoint) m_world.createJoint(def);
  body.setAwake(true);
 }
}

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

Body b = fixture.getBody();
Vec2 bp = b.getWorldCenter();
float bm = b.getMass();
float bI = b.getInertia() - bm * b.getLocalCenter().lengthSquared();
float invBm = bm > 0 ? 1 / bm : 0;

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

float mass = m_bodyB.getMass();

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

if(vr<destroyerVelocity){
  if(vx>0&&vy<0)
    body.applyForce((float) ((destroyerVelocity-vr)*Math.cos(t)*body.getMass()), (float) (-(destroyerVelocity-vr)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx>0&&vy>0)
    body.applyForce((float) ((destroyerVelocity-vr)*Math.cos(t)*body.getMass()), (float) ((destroyerVelocity-vr)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx<0&&vy>0)
    body.applyForce((float) (-(destroyerVelocity-vr)*Math.cos(t)*body.getMass()), (float) ((destroyerVelocity-vr)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx<0&&vy<0)
    body.applyForce((float) (-(destroyerVelocity-vr)*Math.cos(t)*body.getMass()), (float) (-(destroyerVelocity-vr)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
    body.applyForce((float) (-(vr-destroyerVelocity)*Math.cos(t)*body.getMass()), (float) ((vr-destroyerVelocity)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx>0&&vy>0)
    body.applyForce((float) (-(vr-destroyerVelocity)*Math.cos(t)*body.getMass()), (float) (-(vr-destroyerVelocity)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx<0&&vy>0)
    body.applyForce((float) ((vr-destroyerVelocity)*Math.cos(t)*body.getMass()), (float) (-(vr-destroyerVelocity)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);
  else if(vx<0&&vy<0)
    body.applyForce((float) ((vr-destroyerVelocity)*Math.cos(t)*body.getMass()), (float) ((vr-destroyerVelocity)*Math.sin(t)*body.getMass()), body.getWorldCenter().x,  body.getWorldCenter().y);

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

float mass1 = body1.getMass();
float mass2 = body2.getMass();

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

@Override
public void solveVelocityConstraints(final SolverData step) {
  float crossMassSum = 0.0f;
  float dotMassSum = 0.0f;
  Velocity[] velocities = step.velocities;
  Position[] positions = step.positions;
  final Vec2 d[] = pool.getVec2Array(bodies.length);
  for (int i = 0; i < bodies.length; ++i) {
    final int prev = (i == 0) ? bodies.length - 1 : i - 1;
    final int next = (i == bodies.length - 1) ? 0 : i + 1;
    d[i].set(positions[bodies[next].m_islandIndex].c);
    d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
    dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
    crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
  }
  float lambda = -2.0f * crossMassSum / dotMassSum;
  // lambda = JBoxUtils.clamp(lambda, -JBoxSettings.maxLinearCorrection,
  // JBoxSettings.maxLinearCorrection);
  m_impulse += lambda;
  for (int i = 0; i < bodies.length; ++i) {
    velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
    velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
  }
}

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

@Override
public void solveVelocityConstraints(final SolverData step) {
 float crossMassSum = 0.0f;
 float dotMassSum = 0.0f;
 Velocity[] velocities = step.velocities;
 Position[] positions = step.positions;
 final Vec2 d[] = pool.getVec2Array(bodies.length);
 for (int i = 0; i < bodies.length; ++i) {
  final int prev = (i == 0) ? bodies.length - 1 : i - 1;
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  d[i].set(positions[bodies[next].m_islandIndex].c);
  d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
  dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
  crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
 }
 float lambda = -2.0f * crossMassSum / dotMassSum;
 // System.out.println(crossMassSum + " " +dotMassSum);
 // lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
 // Settings.maxLinearCorrection);
 m_impulse += lambda;
 // System.out.println(m_impulse);
 for (int i = 0; i < bodies.length; ++i) {
  velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
  velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
 }
}

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

@Override
public void solveVelocityConstraints(final SolverData step) {
 float crossMassSum = 0.0f;
 float dotMassSum = 0.0f;
 Velocity[] velocities = step.velocities;
 Position[] positions = step.positions;
 final Vec2 d[] = pool.getVec2Array(bodies.length);
 for (int i = 0; i < bodies.length; ++i) {
  final int prev = (i == 0) ? bodies.length - 1 : i - 1;
  final int next = (i == bodies.length - 1) ? 0 : i + 1;
  d[i].set(positions[bodies[next].m_islandIndex].c);
  d[i].subLocal(positions[bodies[prev].m_islandIndex].c);
  dotMassSum += (d[i].lengthSquared()) / bodies[i].getMass();
  crossMassSum += Vec2.cross(velocities[bodies[i].m_islandIndex].v, d[i]);
 }
 float lambda = -2.0f * crossMassSum / dotMassSum;
 // System.out.println(crossMassSum + " " +dotMassSum);
 // lambda = MathUtils.clamp(lambda, -Settings.maxLinearCorrection,
 // Settings.maxLinearCorrection);
 m_impulse += lambda;
 // System.out.println(m_impulse);
 for (int i = 0; i < bodies.length; ++i) {
  velocities[bodies[i].m_islandIndex].v.x += bodies[i].m_invMass * d[i].y * .5f * lambda;
  velocities[bodies[i].m_islandIndex].v.y += bodies[i].m_invMass * -d[i].x * .5f * lambda;
 }
}

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

float mass = body.getMass();

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

/**
 * Called for mouse-down
 * 
 * @param p
 */
public void mouseDown(Vec2 p) {
 mouseWorld.set(p);
 if (mouseJoint != null) {
  return;
 }
 queryAABB.lowerBound.set(p.x - .001f, p.y - .001f);
 queryAABB.upperBound.set(p.x + .001f, p.y + .001f);
 callback.point.set(p);
 callback.fixture = null;
 m_world.queryAABB(callback, queryAABB);
 if (callback.fixture != null) {
  Body body = callback.fixture.getBody();
  MouseJointDef def = new MouseJointDef();
  def.bodyA = groundBody;
  def.bodyB = body;
  def.target.set(p);
  def.maxForce = 1000f * body.getMass();
  mouseJoint = (MouseJoint) m_world.createJoint(def);
  body.setAwake(true);
 }
}

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

float mass = m_bodyB.getMass();

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

float mass = m_bodyB.getMass();

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

float mass = m_bodyB.getMass();

相关文章