Package org.box2d.proto.Box2D

Examples of org.box2d.proto.Box2D.PbBody


  public SerializationResult serialize(Body argBody) {
    PbBody.Builder builder = serializeBody(argBody);
    if (builder == null) {
      return null;
    }
    final PbBody body = builder.build();
    return new SerializationResult() {
      @Override
      public void writeTo(OutputStream argOutputStream) throws IOException {
        body.writeTo(argOutputStream);
      }

      @Override
      public Object getValue() {
        return body;
View Full Code Here


    HashMap<Integer, Body> bodyMap = new HashMap<Integer, Body>();
    HashMap<Integer, Joint> jointMap = new HashMap<Integer, Joint>();

    for (int i = 0; i < pbWorld.getBodiesCount(); i++) {
      PbBody pbBody = pbWorld.getBodies(i);
      Body body = deserializeBody(world, pbBody);
      bodyMap.put(i, body);
    }

    // first pass, indep joints
View Full Code Here

    return world;
  }

  @Override
  public Body deserializeBody(World argWorld, InputStream argInput) throws IOException {
    PbBody body = PbBody.parseFrom(argInput);
    return deserializeBody(argWorld, body);
  }
View Full Code Here

    PbBody body = PbBody.parseFrom(argInput);
    return deserializeBody(argWorld, body);
  }

  public Body deserializeBody(World argWorld, PbBody argBody) {
    PbBody b = argBody;

    BodyDef bd = new BodyDef();
    bd.position.set(pbToVec(b.getPosition()));
    bd.angle = b.getAngle();
    bd.linearDamping = b.getLinearDamping();
    bd.angularDamping = b.getAngularDamping();
    bd.gravityScale = b.getGravityScale();
    // velocities are populated after fixture addition
   
    bd.bullet = b.getBullet();
    bd.allowSleep = b.getAllowSleep();
    bd.awake = b.getAwake();
    bd.active = b.getActive();
    bd.fixedRotation = b.getFixedRotation();

    switch (b.getType()) {
      case DYNAMIC:
        bd.type = BodyType.DYNAMIC;
        break;
      case KINEMATIC:
        bd.type = BodyType.KINEMATIC;
        break;
      case STATIC:
        bd.type = BodyType.STATIC;
        break;
      default:
        UnsupportedObjectException e =
            new UnsupportedObjectException("Unknown body type: " + argBody.getType(), Type.BODY);
        if (ulistener == null || ulistener.isUnsupported(e)) {
          throw e;
        }
        return null;
    }

    Body body = argWorld.createBody(bd);

    for (int i = 0; i < b.getFixturesCount(); i++) {
      deserializeFixture(body, b.getFixtures(i));
    }
   
    // adding fixtures can change this, so we put this here and set it directly in the body
    body.m_linearVelocity.set(pbToVec(b.getLinearVelocity()));
    body.m_angularVelocity = b.getAngularVelocity();

    if (listener != null && b.hasTag()) {
      listener.processBody(body, b.getTag());
    }
    return body;
  }
View Full Code Here

TOP

Related Classes of org.box2d.proto.Box2D.PbBody

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.