Ejemplo n.º 1
0
  public void getOrientation(float[] angleAxis) {
    if (angleAxis == null) throw new NullPointerException("angleAxis can not be null");
    if (angleAxis.length < 4) throw new IllegalArgumentException("length must be greater than 3");

    float[] m = new float[16];
    orientation.get(m);

    Vector3 axis = new Vector3(m[6] - m[9], m[8] - m[2], m[1] - m[4]);
    axis.normalize();

    float angle = (float) StrictMath.acos(0.5 * (m[0] + m[5] + m[10] - 1));

    angleAxis[0] = angle;
    angleAxis[1] = axis.x;
    angleAxis[2] = axis.y;
    angleAxis[3] = axis.z;

    // TODO: Handle singularities for angle = 0 and angle = 180 degrees
  }
Ejemplo n.º 2
0
  public void getCompositeTransform(Transform transform) {
    if (transform == null) throw new NullPointerException("transform can not be null");

    // transform = T R S M

    // Combine translation and rotation (TR)
    float[] m = new float[16];
    orientation.get(m);
    m[3] = translation.x;
    m[7] = translation.y;
    m[11] = translation.z;
    transform.set(m);

    // Apply scale (S)
    transform.postScale(scale.x, scale.y, scale.z);

    // Apply custom (M)
    transform.postMultiply(this.transform);
  }