Beispiel #1
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 #2
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 #3
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();
    }
  }
  /** Calculate transforms needed to handle VRML semantics formula: T x C x R x SR x S x -SR x -C */
  private void updateTransform() {

    // System.out.println(this);
    tempVec.x = -vfCenter[0];
    tempVec.y = -vfCenter[1];
    tempVec.z = -vfCenter[2];

    matrix.setIdentity();
    matrix.setTranslation(tempVec);

    float scaleVal = 1.0f;

    if (floatEq(vfScale[0], vfScale[1]) && floatEq(vfScale[0], vfScale[2])) {

      scaleVal = vfScale[0];
      tempMtx1.set(scaleVal);
      // System.out.println("S" + tempMtx1);

    } else {
      // non-uniform scale
      // System.out.println("Non Uniform Scale");
      tempAxis.x = vfScaleOrientation[0];
      tempAxis.y = vfScaleOrientation[1];
      tempAxis.z = vfScaleOrientation[2];
      tempAxis.angle = -vfScaleOrientation[3];

      double tempAxisNormalizer =
          1
              / Math.sqrt(
                  tempAxis.x * tempAxis.x + tempAxis.y * tempAxis.y + tempAxis.z * tempAxis.z);

      tempAxis.x *= tempAxisNormalizer;
      tempAxis.y *= tempAxisNormalizer;
      tempAxis.z *= tempAxisNormalizer;

      tempMtx1.set(tempAxis);
      tempMtx2.mul(tempMtx1, matrix);

      // Set the scale by individually setting each element
      tempMtx1.setIdentity();
      tempMtx1.m00 = vfScale[0];
      tempMtx1.m11 = vfScale[1];
      tempMtx1.m22 = vfScale[2];

      matrix.mul(tempMtx1, tempMtx2);

      tempAxis.x = vfScaleOrientation[0];
      tempAxis.y = vfScaleOrientation[1];
      tempAxis.z = vfScaleOrientation[2];
      tempAxis.angle = vfScaleOrientation[3];
      tempMtx1.set(tempAxis);
    }

    tempMtx2.mul(tempMtx1, matrix);

    // System.out.println("Sx-C" + tempMtx2);
    float magSq =
        vfRotation[0] * vfRotation[0]
            + vfRotation[1] * vfRotation[1]
            + vfRotation[2] * vfRotation[2];

    if (magSq < ZEROEPS) {
      tempAxis.x = 0;
      tempAxis.y = 0;
      tempAxis.z = 1;
      tempAxis.angle = 0;
    } else {
      if ((magSq > 1.01) || (magSq < 0.99)) {

        float mag = (float) (1 / Math.sqrt(magSq));
        tempAxis.x = vfRotation[0] * mag;
        tempAxis.y = vfRotation[1] * mag;
        tempAxis.z = vfRotation[2] * mag;
      } else {
        tempAxis.x = vfRotation[0];
        tempAxis.y = vfRotation[1];
        tempAxis.z = vfRotation[2];
      }

      tempAxis.angle = vfRotation[3];
    }

    tempMtx1.set(tempAxis);
    // System.out.println("R" + tempMtx1);

    matrix.mul(tempMtx1, tempMtx2);
    // System.out.println("RxSx-C" + matrix);

    tempVec.x = vfCenter[0];
    tempVec.y = vfCenter[1];
    tempVec.z = vfCenter[2];

    tempMtx1.setIdentity();
    tempMtx1.setTranslation(tempVec);
    // System.out.println("C" + tempMtx1);

    tempMtx2.mul(tempMtx1, matrix);
    // System.out.println("CxRxSx-C" + tempMtx2);

    tempVec.x = vfTranslation[0];
    tempVec.y = vfTranslation[1];
    tempVec.z = vfTranslation[2];

    tempMtx1.setIdentity();
    tempMtx1.setTranslation(tempVec);

    matrix.mul(tempMtx1, tempMtx2);

    transform.set(matrix);
    implTG.setTransform(transform);
  }