예제 #1
0
  public static float[] rotateDirection(GVRTransform rotationQuat, float[] point) {
    float[] rotation = new float[4];
    rotation[0] = rotationQuat.getRotationX();
    rotation[1] = rotationQuat.getRotationY();
    rotation[2] = rotationQuat.getRotationZ();
    rotation[3] = rotationQuat.getRotationW();

    float num = rotation[0] * 2f;
    float num2 = rotation[1] * 2f;
    float num3 = rotation[2] * 2f;
    float num4 = rotation[0] * num;
    float num5 = rotation[1] * num2;
    float num6 = rotation[2] * num3;
    float num7 = rotation[0] * num2;
    float num8 = rotation[0] * num3;
    float num9 = rotation[1] * num3;
    float num10 = rotation[3] * num;
    float num11 = rotation[3] * num2;
    float num12 = rotation[3] * num3;
    float[] result = new float[3];
    result[0] =
        (1f - (num5 + num6)) * point[0] + (num7 - num12) * point[1] + (num8 + num11) * point[2];
    result[1] =
        (num7 + num12) * point[0] + (1f - (num4 + num6)) * point[1] + (num9 - num10) * point[2];
    result[2] =
        (num8 - num11) * point[0] + (num9 + num10) * point[1] + (1f - (num4 + num5)) * point[2];
    return result;
  }
예제 #2
0
  public static float[] quaternionMultiply(GVRTransform quat1, GVRTransform quat2) {

    float[] lhs = new float[4];
    lhs[0] = quat1.getRotationX();
    lhs[1] = quat1.getRotationY();
    lhs[2] = quat1.getRotationZ();
    lhs[3] = quat1.getRotationW();
    float[] rhs = new float[4];
    rhs[0] = quat2.getRotationX();
    rhs[1] = quat2.getRotationY();
    rhs[2] = quat2.getRotationZ();
    rhs[3] = quat2.getRotationW();
    float[] quat = new float[4];
    quat[0] = lhs[3] * rhs[0] + lhs[0] * rhs[3] + lhs[1] * rhs[2] - lhs[2] * rhs[1];
    quat[1] = lhs[3] * rhs[1] + lhs[1] * rhs[3] + lhs[2] * rhs[0] - lhs[0] * rhs[2];
    quat[2] = lhs[3] * rhs[2] + lhs[2] * rhs[3] + lhs[0] * rhs[1] - lhs[1] * rhs[0];
    quat[3] = lhs[3] * rhs[3] - lhs[0] * rhs[0] - lhs[1] * rhs[1] - lhs[2] * rhs[2];
    return quat;
  }