Ejemplo n.º 1
0
  public void transform(Matrix4f mat, boolean updateLocal) {
    activate();

    Transform t = new Transform();
    t.set(mat);

    Vector3f v = new Vector3f();
    for (int i = 0; i < 3; ++i) {
      t.basis.getColumn(i, v);
      v.normalize();
      t.basis.setColumn(i, v);
    }

    body.setWorldTransform(t);

    // required for static objects:
    body.getMotionState().setWorldTransform(t);
    if (body.isInWorld() && body.isStaticOrKinematicObject()) {
      scene.world.updateSingleAabb(body);
      for (GameObject g : touchingObjects) g.activate();
    }
    //

    updateChildTransforms();

    if (parent != null && updateLocal) {
      updateLocalTransform();
    }
  }
Ejemplo n.º 2
0
  public void parent(GameObject p, boolean compound) {
    CompoundShape compShapeOld = null;

    if (parent != null) {
      parent.children.remove(this);

      if (compound) {
        compShapeOld = parent.compoundShape();
        if (compShapeOld != null) {
          scene.world.removeRigidBody(parent.body);
          compShapeOld.removeChildShape(body.getCollisionShape());
          scene.world.addRigidBody(parent.body);
        }
      }

    } else if (p == null) {
      return;
    }

    parent = p;

    if (parent != null) {

      parent.children.add(this);

      updateLocalTransform();
      updateLocalScale();

      if (compound) {
        CompoundShape compShape = parent.compoundShape();
        if (compShape != null) {
          scene.world.removeRigidBody(body);
          compShape.addChildShape(new Transform(localTransform), body.getCollisionShape());
        }
      } else {
        dynamics(false);
      }

    } else if (currBodyType.equals("STATIC") || currBodyType.equals("SENSOR")) {
      if (compound && compShapeOld != null) scene.world.addRigidBody(body);

    } else {
      dynamics(true);
    }
  }