Exemplo n.º 1
0
 /**
  * Post multiplies this {@link Matrix4} with the rotation specified by the provided {@link
  * Quaternion}.
  *
  * @param quat {@link Quaternion} describing the rotation to apply.
  * @return A reference to this {@link Matrix4} to facilitate chaining.
  */
 @NonNull
 public Matrix4 rotate(@NonNull Quaternion quat) {
   if (mMatrix == null) {
     mMatrix = quat.toRotationMatrix();
   } else {
     quat.toRotationMatrix(mMatrix);
   }
   return multiply(mMatrix);
 }
  public void inverseTransform(
      final Number3D position, final Number3D scale, final Quaternion orientation) {
    Number3D invTranslate = position.inverse();
    Number3D invScale = new Number3D(1 / scale.x, 1 / scale.y, 1 / scale.z);
    Quaternion invRot = orientation.inverse();

    invTranslate = invRot.multiply(invTranslate);
    invTranslate.multiply(invScale);
    invRot.toRotationMatrix(mTmp);

    m[0] = invScale.x * mTmp[0];
    m[1] = invScale.x * mTmp[1];
    m[2] = invScale.x * mTmp[2];
    m[3] = invTranslate.x;
    m[4] = invScale.y * mTmp[4];
    m[5] = invScale.y * mTmp[5];
    m[6] = invScale.y * mTmp[6];
    m[7] = invTranslate.y;
    m[8] = invScale.z * mTmp[8];
    m[9] = invScale.z * mTmp[9];
    m[10] = invScale.z * mTmp[10];
    m[11] = invTranslate.z;
    m[12] = 0;
    m[13] = 0;
    m[14] = 0;
    m[15] = 1;
  }
  public void transform(
      final Number3D position, final Number3D scale, final Quaternion orientation) {
    orientation.toRotationMatrix(mTmp);

    m[0] = scale.x * mTmp[0];
    m[1] = scale.y * mTmp[1];
    m[2] = scale.z * mTmp[2];
    m[3] = position.x;
    m[4] = scale.x * mTmp[4];
    m[5] = scale.y * mTmp[5];
    m[6] = scale.z * mTmp[6];
    m[7] = position.y;
    m[8] = scale.x * mTmp[8];
    m[9] = scale.y * mTmp[9];
    m[10] = scale.z * mTmp[10];
    m[11] = position.z;
    m[12] = 0;
    m[13] = 0;
    m[14] = 0;
    m[15] = 1;
  }
Exemplo n.º 4
0
 /**
  * Sets the elements of this {@link Matrix4} based on the rotation represented by the provided
  * {@link Quaternion}.
  *
  * @param quat {@link Quaternion} The {@link Quaternion} to represent.
  * @return A reference to this {@link Matrix4} to facilitate chaining.
  */
 @NonNull
 public Matrix4 setAll(@NonNull Quaternion quat) {
   quat.toRotationMatrix(m);
   return this;
 }