📄 transform3d.java
字号:
double ay = a1.y*mag; double az = a1.z*mag; double sinTheta = Math.sin(a1.angle); double cosTheta = Math.cos(a1.angle); double t = 1.0 - cosTheta; double xz = ax * az; double xy = ax * ay; double yz = ay * az; mat[0] = (t * ax * ax + cosTheta)*scales[0]; mat[1] = (t * xy - sinTheta * az)*scales[1]; mat[2] = (t * xz + sinTheta * ay)*scales[2]; mat[4] = (t * xy + sinTheta * az)*scales[0]; mat[5] = (t * ay * ay + cosTheta)*scales[1]; mat[6] = (t * yz - sinTheta * ax)*scales[2]; mat[8] = (t * xz - sinTheta * ay)*scales[0]; mat[9] = (t * yz + sinTheta * ax)*scales[1]; mat[10] = (t * az * az + cosTheta)*scales[2]; } // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(a1)) { dirtyBits = ALL_DIRTY; return; } // Rigid remain rigid, congruent remain congruent after // set rotation dirtyBits |= CLASSIFY_BIT | ROTATION_BIT; dirtyBits &= (~ORTHO_BIT | ~SVD_BIT); type |= ORTHO; type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); } /** * Sets the value of this transform to a counter clockwise rotation * about the x axis. All of the non-rotational components are set as * if this were an identity matrix. * @param angle the angle to rotate about the X axis in radians */ public void rotX(double angle) { double sinAngle = Math.sin(angle); double cosAngle = Math.cos(angle); mat[0] = 1.0; mat[1] = 0.0; mat[2] = 0.0; mat[3] = 0.0; mat[4] = 0.0; mat[5] = cosAngle; mat[6] = -sinAngle; mat[7] = 0.0; mat[8] = 0.0; mat[9] = sinAngle; mat[10] = cosAngle; mat[11] = 0.0; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(angle)) { dirtyBits = ALL_DIRTY; return; } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } /** * Sets the value of this transform to a counter clockwise rotation about * the y axis. All of the non-rotational components are set as if this * were an identity matrix. * @param angle the angle to rotate about the Y axis in radians */ public void rotY(double angle) { double sinAngle = Math.sin(angle); double cosAngle = Math.cos(angle); mat[0] = cosAngle; mat[1] = 0.0; mat[2] = sinAngle; mat[3] = 0.0; mat[4] = 0.0; mat[5] = 1.0; mat[6] = 0.0; mat[7] = 0.0; mat[8] = -sinAngle; mat[9] = 0.0; mat[10] = cosAngle; mat[11] = 0.0; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(angle)) { dirtyBits = ALL_DIRTY; return; } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } /** * Sets the value of this transform to a counter clockwise rotation * about the z axis. All of the non-rotational components are set * as if this were an identity matrix. * @param angle the angle to rotate about the Z axis in radians */ public void rotZ(double angle) { double sinAngle = Math.sin(angle); double cosAngle = Math.cos(angle); mat[0] = cosAngle; mat[1] = -sinAngle; mat[2] = 0.0; mat[3] = 0.0; mat[4] = sinAngle; mat[5] = cosAngle; mat[6] = 0.0; mat[7] = 0.0; mat[8] = 0.0; mat[9] = 0.0; mat[10] = 1.0; mat[11] = 0.0; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(angle)) { dirtyBits = ALL_DIRTY; return; } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } /** * Sets the translational value of this matrix to the Vector3f parameter * values, and sets the other components of the matrix as if this * transform were an identity matrix. * @param trans the translational component */ public final void set(Vector3f trans) { mat[0] = 1.0; mat[1] = 0.0; mat[2] = 0.0; mat[3] = trans.x; mat[4] = 0.0; mat[5] = 1.0; mat[6] = 0.0; mat[7] = trans.y; mat[8] = 0.0; mat[9] = 0.0; mat[10] = 1.0; mat[11] = trans.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(trans)) { dirtyBits = ALL_DIRTY; return; } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } /** * Sets the translational value of this matrix to the Vector3d paramter * values, and sets the other components of the matrix as if this * transform were an identity matrix. * @param trans the translational component */ public final void set(Vector3d trans) { mat[0] = 1.0; mat[1] = 0.0; mat[2] = 0.0; mat[3] = trans.x; mat[4] = 0.0; mat[5] = 1.0; mat[6] = 0.0; mat[7] = trans.y; mat[8] = 0.0; mat[9] = 0.0; mat[10] = 1.0; mat[11] = trans.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(trans)) { dirtyBits = ALL_DIRTY; return; } type = CONGRUENT | AFFINE | RIGID | ORTHO; dirtyBits = CLASSIFY_BIT | ROTATION_BIT | SCALE_BIT; } /** * Sets the scale component of the current transform; any existing * scale is first factored out of the existing transform before * the new scale is applied. * @param scale the new scale amount */ public final void setScale(double scale) { if ((dirtyBits & ROTATION_BIT)!= 0) { computeScaleRotation(false); } scales[0] = scales[1] = scales[2] = scale; mat[0] = rot[0]*scale; mat[1] = rot[1]*scale; mat[2] = rot[2]*scale; mat[4] = rot[3]*scale; mat[5] = rot[4]*scale; mat[6] = rot[5]*scale; mat[8] = rot[6]*scale; mat[9] = rot[7]*scale; mat[10] = rot[8]*scale; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(scale)) { dirtyBits = ALL_DIRTY; return; } dirtyBits |= (CLASSIFY_BIT | RIGID_BIT | CONGRUENT_BIT | SVD_BIT); dirtyBits &= ~SCALE_BIT; } /** * Sets the possibly non-uniform scale component of the current * transform; any existing scale is first factored out of the * existing transform before the new scale is applied. * @param scale the new x,y,z scale values */ public final void setScale(Vector3d scale) { if ((dirtyBits & ROTATION_BIT)!= 0) { computeScaleRotation(false); } scales[0] = scale.x; scales[1] = scale.y; scales[2] = scale.z; mat[0] = rot[0]*scale.x; mat[1] = rot[1]*scale.y; mat[2] = rot[2]*scale.z; mat[4] = rot[3]*scale.x; mat[5] = rot[4]*scale.y; mat[6] = rot[5]*scale.z; mat[8] = rot[6]*scale.x; mat[9] = rot[7]*scale.y; mat[10] = rot[8]*scale.z; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(scale)) { dirtyBits = ALL_DIRTY; return; } dirtyBits |= (CLASSIFY_BIT | RIGID_BIT | CONGRUENT_BIT | SVD_BIT); dirtyBits &= ~SCALE_BIT; } /** * Replaces the current transform with a non-uniform scale transform. * All values of the existing transform are replaced. * @param xScale the new X scale amount * @param yScale the new Y scale amount * @param zScale the new Z scale amount * @deprecated Use setScale(Vector3d) instead of setNonUniformScale; * note that the setScale only modifies the scale component */ public final void setNonUniformScale(double xScale, double yScale, double zScale) { if(scales == null) scales = new double[3]; scales[0] = xScale; scales[1] = yScale; scales[2] = zScale; mat[0] = xScale; mat[1] = 0.0; mat[2] = 0.0; mat[3] = 0.0; mat[4] = 0.0; mat[5] = yScale; mat[6] = 0.0; mat[7] = 0.0; mat[8] = 0.0; mat[9] = 0.0; mat[10] = zScale; mat[11] = 0.0; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits dirtyBits = ALL_DIRTY; } /** * Replaces the translational components of this transform to the values * in the Vector3f argument; the other values of this transform are not * modified. * @param trans the translational component */ public final void setTranslation(Vector3f trans) { mat[3] = trans.x; mat[7] = trans.y; mat[11] = trans.z; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(trans)) { dirtyBits = ALL_DIRTY; return; } // Only preserve CONGRUENT, RIGID, ORTHO type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); dirtyBits |= CLASSIFY_BIT; } /** * Replaces the translational components of this transform to the values * in the Vector3d argument; the other values of this transform are not * modified. * @param trans the translational component */ public final void setTranslation(Vector3d trans) { mat[3] = trans.x; mat[7] = trans.y; mat[11] = trans.z; // Issue 253: set all dirty bits if input is infinity or NaN if (isInfOrNaN(trans)) { dirtyBits = ALL_DIRTY; return; } type &= ~(ORTHOGONAL|IDENTITY|SCALE|TRANSLATION|SCALE|ZERO); dirtyBits |= CLASSIFY_BIT; } /** * Sets the value of this matrix from the rotation expressed * by the quaternion q1, the translation t1, and the scale s. * @param q1 the rotation expressed as a quaternion * @param t1 the translation * @param s the scale value */ public final void set(Quat4d q1, Vector3d t1, double s) { if(scales == null) scales = new double[3]; scales[0] = scales[1] = scales[2] = s; mat[0] = (1.0 - 2.0*q1.y*q1.y - 2.0*q1.z*q1.z)*s; mat[4] = (2.0*(q1.x*q1.y + q1.w*q1.z))*s; mat[8] = (2.0*(q1.x*q1.z - q1.w*q1.y))*s; mat[1] = (2.0*(q1.x*q1.y - q1.w*q1.z))*s; mat[5] = (1.0 - 2.0*q1.x*q1.x - 2.0*q1.z*q1.z)*s; mat[9] = (2.0*(q1.y*q1.z + q1.w*q1.x))*s; mat[2] = (2.0*(q1.x*q1.z + q1.w*q1.y))*s; mat[6] = (2.0*(q1.y*q1.z - q1.w*q1.x))*s; mat[10] = (1.0 - 2.0*q1.x*q1.x - 2.0*q1.y*q1.y)*s; mat[3] = t1.x; mat[7] = t1.y; mat[11] = t1.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits dirtyBits = ALL_DIRTY; } /** * Sets the value of this matrix from the rotation expressed * by the quaternion q1, the translation t1, and the scale s. * @param q1 the rotation expressed as a quaternion * @param t1 the translation * @param s the scale value */ public final void set(Quat4f q1, Vector3d t1, double s) { if(scales == null) scales = new double[3]; scales[0] = scales[1] = scales[2] = s; mat[0] = (1.0f - 2.0f*q1.y*q1.y - 2.0f*q1.z*q1.z)*s; mat[4] = (2.0f*(q1.x*q1.y + q1.w*q1.z))*s; mat[8] = (2.0f*(q1.x*q1.z - q1.w*q1.y))*s; mat[1] = (2.0f*(q1.x*q1.y - q1.w*q1.z))*s; mat[5] = (1.0f - 2.0f*q1.x*q1.x - 2.0f*q1.z*q1.z)*s; mat[9] = (2.0f*(q1.y*q1.z + q1.w*q1.x))*s; mat[2] = (2.0f*(q1.x*q1.z + q1.w*q1.y))*s; mat[6] = (2.0f*(q1.y*q1.z - q1.w*q1.x))*s; mat[10] = (1.0f - 2.0f*q1.x*q1.x - 2.0f*q1.y*q1.y)*s; mat[3] = t1.x; mat[7] = t1.y; mat[11] = t1.z; mat[12] = 0.0; mat[13] = 0.0; mat[14] = 0.0; mat[15] = 1.0; // Issue 253: set all dirty bits dirtyBits = ALL_DIRTY; } /** * Sets the value of this matrix from the rotation expressed * by the quaternion q1, the translation t1, and the scale s. * @param q1 the rotation expressed as a quaternion * @param t1 the translation * @param s the scale value */ public final void set(Quat4f q1, Vector3f t1, float s) { if(scales == null) scales = new double[3]; scales[0] = scales[1] = scales[2] = s; mat[0] = (1.0f - 2.0f*q1.y*q1.y - 2.0f*q1.z*q1.z)*s; mat[4] = (2.0f*(q1.x*q1.y + q1.w*q1.z))*s; mat[8] = (2.0f*(q1.x*q1.z - q1.w*q1.y))*s; mat[1] = (2.0f*(q1.x*q1.y - q1.w*q1.z))*s; mat[5] = (1.0f - 2.0f*q1.x*q1.x - 2.0f*q1.z*q1.z)*s;
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -