Exemplo 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();
    }
  }
Exemplo n.º 2
0
  public void scale(float x, float y, float z, boolean updateLocal) {
    activate();
    // Set unit scale
    Matrix4 t = modelInstance.transform;
    Matrix4 mat_scale = new Matrix4();
    Vector3 s = new Vector3();
    t.getScale(s);
    mat_scale.scl(1 / s.x, 1 / s.y, 1 / s.z);
    t.mul(mat_scale);

    // Set target scale
    mat_scale.idt();
    mat_scale.scl(x, y, z);
    t.mul(mat_scale);

    // Relevant bullet body update
    CollisionShape cs = body.getCollisionShape();
    cs.setLocalScaling(new Vector3f(x, y, z));
    if (body.isInWorld() && body.isStaticOrKinematicObject()) scene.world.updateSingleAabb(body);

    // Child propagation
    Vector3f ps = scale();
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);

    for (GameObject c : children) {
      c.scale(scale().mul(c.localScale), false);
      ct.mul(pt, c.localTransform);
      c.transform(ct, false);
    }

    if (parent != null && updateLocal) {
      updateLocalScale();
    }
  }