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

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

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

Body.setTransform介绍

[英]Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a body's transform may cause non-physical behavior. Note: contacts are updated on the next call to World.step().
[中]设置实体原点和旋转的位置。这会断开任何接触并唤醒其他物体。操纵实体的变换可能会导致非物理行为。注意:联系人将在下次致电World时更新。步骤()。

代码示例

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

/** Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a
 * body's transform may cause non-physical behavior.
 * @param position the world position of the body's local origin.
 * @param angle the world rotation in radians. */
public void setTransform (Vector2 position, float angle) {
  tmp.set(position.x, position.y);
  body.setTransform(tmp, angle);
}

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

/** Set the position of the body's origin and rotation. This breaks any contacts and wakes the other bodies. Manipulating a
 * body's transform may cause non-physical behavior.
 * @param x the world position on the x-axis
 * @param y the world position on the y-axis
 * @param angle the world rotation in radians. */
public void setTransform (float x, float y, float angle) {
  tmp.set(x, y);
  body.setTransform(tmp, angle);
}

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

public void launch() {
 m_body.setTransform(new Vec2(0.0f, 20.0f), 0.0f);
 m_angularVelocity = (float) Math.random() * 100 - 50;
 m_body.setLinearVelocity(new Vec2(0.0f, -100.0f));
 m_body.setAngularVelocity(m_angularVelocity);
}

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

public void launch() {
 m_body.setTransform(new Vec2(0.0f, 4.0f), 0.0f);
 m_body.setLinearVelocity(new Vec2());
 m_body.setAngularVelocity(0.0f);
 m_x = MathUtils.randomFloat(-1.0f, 1.0f);
 m_bullet.setTransform(new Vec2(m_x, 10.0f), 0.0f);
 m_bullet.setLinearVelocity(new Vec2(0.0f, -50.0f));
 m_bullet.setAngularVelocity(0.0f);
 Distance.GJK_CALLS = 0;
 Distance.GJK_ITERS = 0;
 Distance.GJK_MAX_ITERS = 0;
 TimeOfImpact.toiCalls = 0;
 TimeOfImpact.toiIters = 0;
 TimeOfImpact.toiMaxIters = 0;
 TimeOfImpact.toiRootIters = 0;
 TimeOfImpact.toiMaxRootIters = 0;
}

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

for(Body body : jointGroup)
{
  body.setTransform(body.getPosition.x - someX, ...)
  ...

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

@Override
public boolean onAreaTouched( final TouchEvent pSceneTouchEvent, final ITouchArea pTouchArea,final float pTouchAreaLocalX, final float pTouchAreaLocalY) {

  if(pSceneTouchEvent.isActionMove()) {

    final AnimatedSprite face = (AnimatedSprite) pTouchArea;
    final Body faceBody = (Body)face.getUserData();
    faceBody.setTransform(pSceneTouchEvent.getX() / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, pSceneTouchEvent.getY() / PhysicsConstants.PIXEL_TO_METER_RATIO_DEFAULT, faceBody.getAngle());
    return true;
  }
  return false;
}

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

public class MoveBodyModifier extends MoveModifier {

private Body mBody;

public MoveBodyModifier(float pDuration, float pFromX, float pToX, float pFromY, float pToY, Body body) {
  super(pDuration, pFromX, pToX, pFromY, pToY);
  mBody = body;
}

@Override
protected void onSetInitialValues(IEntity pEntity, float pX, float pY) {
  mBody.setTransform(pX/ PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT,
      pY/ PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT, mBody.getAngle());
}

@Override
protected void onSetValues(IEntity pEntity, float pPercentageDone, float pX, float pY) {
  mBody.setTransform(pX/ PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT,
      pY/ PhysicsConnector.PIXEL_TO_METER_RATIO_DEFAULT, mBody.getAngle());
}
}

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

public void onControlChange(final BaseOnScreenControl pBaseOnScreenControl, final float pValueX, final float pValueY) {
     final Body carBody = CityRacerActivity.this.mCarBody;
     final float rotationInRad = (float)Math.atan2(-pValueX, pValueY);
     if ((pValueX == 0) && (pValueY == 0))
     {
         //Don't turn the body/sprite of the car
     }else
     {
         carBody.setTransform(carBody.getWorldCenter(), rotationInRad);
         //turn the car body in the direction of movement
         CityRacerActivity.this.mCar.setRotation(MathUtils.radToDeg(rotationInRad));
     }
     //set the velocity
     final Vector2 velocity = Vector2Pool.obtain(pValueX * 5, pValueY * 5);
     carBody.setLinearVelocity(velocity);
     Vector2Pool.recycle(velocity);
   }

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

public void launch() {
 m_body.setTransform(new Vec2(0.0f, 20.0f), 0.0f);
 m_angularVelocity = (float) Math.random() * 100 - 50;
 m_body.setLinearVelocity(new Vec2(0.0f, -100.0f));
 m_body.setAngularVelocity(m_angularVelocity);
}

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

createLeg(1.0f, wheelAnchor);
m_wheel.setTransform(m_wheel.getPosition(), 120.0f * MathUtils.PI / 180.0f);
createLeg(-1.0f, wheelAnchor);
createLeg(1.0f, wheelAnchor);
m_wheel.setTransform(m_wheel.getPosition(), -120.0f * MathUtils.PI / 180.0f);
createLeg(-1.0f, wheelAnchor);
createLeg(1.0f, wheelAnchor);

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

@Override
  public void handleGameEvent(PropertyChanged aEvent) {
    if (!insimulation) {
      //synchronized (physicsWorld) {
        GameObjectInstance theInstance = (GameObjectInstance) aEvent.getOwner();
        Body theBody = staticObjects.get(theInstance);
        if (theBody == null) {
          theBody = dynamicObjects.get(theInstance);
        }
        if (theBody != null) {
          theBody.setTransform(computePosition(theInstance),
              theInstance.rotationAngleProperty().get().invert().toRadians());
        }
      //}
    }
  }
}

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

createLeg(1.0f, wheelAnchor);
m_wheel.setTransform(m_wheel.getPosition(), 120.0f * MathUtils.PI / 180.0f);
createLeg(-1.0f, wheelAnchor);
createLeg(1.0f, wheelAnchor);
m_wheel.setTransform(m_wheel.getPosition(), -120.0f * MathUtils.PI / 180.0f);
createLeg(-1.0f, wheelAnchor);
createLeg(1.0f, wheelAnchor);

相关文章