Advertisement
roro1506HD

Old Quaternion rotation

Jun 8th, 2023 (edited)
179
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
Java 3.05 KB | Source Code | 0 0
  1.     private void replicateOldMulPoseBehavior(@NotNull PoseStack poseStack, float angle, float x, float y, float z) {
  2.         // Quaternion fields
  3.         float q_sin = Mth.sin(angle * 0.5F);
  4.         float q_x = x * q_sin;
  5.         float q_y = y * q_sin;
  6.         float q_z = z * q_sin;
  7.         float q_w = Mth.cos(angle * 0.5F);
  8.  
  9.         // Matrix4f/Matrix3f fields
  10.         float m_xFactor = 2.0F * q_x * q_x;
  11.         float m_yFactor = 2.0F * q_y * q_y;
  12.         float m_zFactor = 2.0F * q_z * q_z;
  13.         float m_xy = q_x * q_y;
  14.         float m_yz = q_y * q_z;
  15.         float m_zx = q_z * q_x;
  16.         float m_xw = q_x * q_w;
  17.         float m_yw = q_y * q_w;
  18.         float m_zw = q_z * q_w;
  19.         float m_m00 = 1.0F - m_yFactor - m_zFactor;
  20.         float m_m01 = 2.0F * (m_xy - m_zw);
  21.         float m_m02 = 2.0F * (m_zx + m_yw);
  22.         float m_m10 = 2.0F * (m_xy + m_zw);
  23.         float m_m11 = 1.0F - m_zFactor - m_xFactor;
  24.         float m_m12 = 2.0F * (m_yz - m_xw);
  25.         float m_m20 = 2.0F * (m_zx - m_yw);
  26.         float m_m21 = 2.0F * (m_yz + m_xw);
  27.         float m_m22 = 1.0F - m_xFactor - m_yFactor;
  28.  
  29.         PoseStack.Pose lastPose = poseStack.last();
  30.         Matrix4f pose = lastPose.pose();
  31.         Matrix3f normal = lastPose.normal();
  32.  
  33.         // Multiply pose matrix
  34.         pose.m00(m_m00 * pose.m00() + m_m01 * pose.m10() + m_m02 * pose.m20());
  35.         pose.m01(m_m00 * pose.m01() + m_m01 * pose.m11() + m_m02 * pose.m21());
  36.         pose.m02(m_m00 * pose.m02() + m_m01 * pose.m12() + m_m02 * pose.m22());
  37.         pose.m03(m_m00 * pose.m03() + m_m01 * pose.m13() + m_m02 * pose.m23());
  38.         pose.m10(m_m10 * pose.m00() + m_m11 * pose.m10() + m_m12 * pose.m20());
  39.         pose.m11(m_m10 * pose.m01() + m_m11 * pose.m11() + m_m12 * pose.m21());
  40.         pose.m12(m_m10 * pose.m02() + m_m11 * pose.m12() + m_m12 * pose.m22());
  41.         pose.m13(m_m10 * pose.m03() + m_m11 * pose.m13() + m_m12 * pose.m23());
  42.         pose.m20(m_m20 * pose.m00() + m_m21 * pose.m10() + m_m22 * pose.m20());
  43.         pose.m21(m_m20 * pose.m01() + m_m21 * pose.m11() + m_m22 * pose.m21());
  44.         pose.m22(m_m20 * pose.m02() + m_m21 * pose.m12() + m_m22 * pose.m22());
  45.         pose.m23(m_m20 * pose.m03() + m_m21 * pose.m13() + m_m22 * pose.m23());
  46.  
  47.         // Multiply normal matrix
  48.         normal.m00(m_m00 * normal.m00() + m_m01 * normal.m10() + m_m02 * normal.m20());
  49.         normal.m01(m_m00 * normal.m01() + m_m01 * normal.m11() + m_m02 * normal.m21());
  50.         normal.m02(m_m00 * normal.m02() + m_m01 * normal.m12() + m_m02 * normal.m22());
  51.         normal.m10(m_m10 * normal.m00() + m_m11 * normal.m10() + m_m12 * normal.m20());
  52.         normal.m11(m_m10 * normal.m01() + m_m11 * normal.m11() + m_m12 * normal.m21());
  53.         normal.m12(m_m10 * normal.m02() + m_m11 * normal.m12() + m_m12 * normal.m22());
  54.         normal.m20(m_m20 * normal.m00() + m_m21 * normal.m10() + m_m22 * normal.m20());
  55.         normal.m21(m_m20 * normal.m01() + m_m21 * normal.m11() + m_m22 * normal.m21());
  56.         normal.m22(m_m20 * normal.m02() + m_m21 * normal.m12() + m_m22 * normal.m22());
  57.     }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement