Beispiel #1
0
  public void position(Vector3f vec) {
    activate();

    Matrix4f t = transform();
    t.setTranslation(vec);

    transform(t);
  }
Beispiel #2
0
 private void updateLocalTransform() {
   localTransform = parent.transform();
   Matrix4f ms = new Matrix4f();
   ms.setIdentity();
   Vector3f ps = parent.scale();
   ms.m00 = ps.x;
   ms.m11 = ps.y;
   ms.m22 = ps.z;
   localTransform.mul(ms);
   localTransform.invert();
   localTransform.mul(transform());
 }
Beispiel #3
0
  public void updateChildTransforms() {
    Matrix4f pt = transform();
    Matrix4f ct = new Matrix4f();
    Matrix4f ms = new Matrix4f();
    ms.setIdentity();
    Vector3f ps = scale();
    ms.m00 = ps.x;
    ms.m11 = ps.y;
    ms.m22 = ps.z;
    pt.mul(ms);

    for (GameObject c : children) {
      ct.mul(pt, c.localTransform);
      c.transform(ct, false);
    }
  }
Beispiel #4
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();
    }
  }
Beispiel #5
0
  public void replaceModel(String modelName, boolean updateVisual, boolean updatePhysics) {
    if (modelName.equals(modelInstance.model.meshParts.get(0).id)) return;

    Model model = null;
    JsonValue mOrigin = null;
    JsonValue mDimNoScale = null;
    for (Scene sce : Bdx.scenes) {
      if (sce.models.containsKey(modelName)) {
        model = sce.models.get(modelName);
        mOrigin = sce.json.get("origins").get(modelName);
        mDimNoScale = sce.json.get("dimensions").get(modelName);
        break;
      }
    }
    if (model == null) {
      throw new RuntimeException("No model found with name: '" + modelName + "'");
    }
    origin = mOrigin == null ? new Vector3f() : new Vector3f(mOrigin.asFloatArray());
    dimensionsNoScale =
        mDimNoScale == null ? new Vector3f(1, 1, 1) : new Vector3f(mDimNoScale.asFloatArray());
    Matrix4 trans = modelInstance.transform;

    if (updateVisual) {
      ModelInstance mi = new ModelInstance(model);
      mi.transform.set(trans);
      modelInstance = mi;
    }

    if (updatePhysics) {
      GameObject compParent =
          parent != null && parent.body.getCollisionShape().isCompound() ? parent : null;
      boolean isCompChild =
          compParent != null
              && !(currBodyType.equals("NO_COLLISION") || currBodyType.equals("SENSOR"));
      if (isCompChild) {
        parent(null);
      }

      Matrix4f transform = transform();
      Vector3f scale = scale();
      String boundsType = json.get("physics").get("bounds_type").asString();
      float margin = json.get("physics").get("margin").asFloat();
      boolean compound = json.get("physics").get("compound").asBoolean();
      body.setCollisionShape(Bullet.makeShape(model.meshes.first(), boundsType, margin, compound));

      if (boundsType.equals("CONVEX_HULL")) {
        Transform startTransform = new Transform();
        body.getMotionState().getWorldTransform(startTransform);
        Matrix4f originMatrix = new Matrix4f();
        originMatrix.set(origin);
        Transform centerOfMassTransform = new Transform();
        centerOfMassTransform.set(originMatrix);
        centerOfMassTransform.mul(startTransform);
        body.setCenterOfMassTransform(centerOfMassTransform);
      }

      transform(transform);
      scale(scale);

      if (body.isInWorld()) {
        scene.world.updateSingleAabb(body);
      } else { // update Aabb hack for when not in world
        scene.world.addRigidBody(body);
        scene.world.updateSingleAabb(body);
        scene.world.removeRigidBody(body);
      }

      if (isCompChild) {
        parent(compParent);
      }
    }
  }
Beispiel #6
0
 public void transform(Matrix4f mat) {
   transform(mat, true);
 }
Beispiel #7
0
 public void orientation(Matrix3f ori) {
   Matrix4f t = transform();
   t.setRotation(ori);
   transform(t);
 }