Advertisement
Guest User

Untitled

a guest
Aug 24th, 2019
106
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.23 KB | None | 0 0
  1. void AngleMatrix(const Vector angles, matrix3x4_t& matrix)
  2. {
  3. float sr, sp, sy, cr, cp, cy;
  4.  
  5. sy = sin(DEG2RAD(angles[1]));
  6. cy = cos(DEG2RAD(angles[1]));
  7.  
  8. sp = sin(DEG2RAD(angles[0]));
  9. cp = cos(DEG2RAD(angles[0]));
  10.  
  11. sr = sin(DEG2RAD(angles[2]));
  12. cr = cos(DEG2RAD(angles[2]));
  13.  
  14. //matrix = (YAW * PITCH) * ROLL
  15. matrix[0][0] = cp * cy;
  16. matrix[1][0] = cp * sy;
  17. matrix[2][0] = -sp;
  18.  
  19. float crcy = cr * cy;
  20. float crsy = cr * sy;
  21. float srcy = sr * cy;
  22. float srsy = sr * sy;
  23.  
  24. matrix[0][1] = sp * srcy - crsy;
  25. matrix[1][1] = sp * srsy + crcy;
  26. matrix[2][1] = sr * cp;
  27.  
  28. matrix[0][2] = (sp * crcy + srsy);
  29. matrix[1][2] = (sp * crsy - srcy);
  30. matrix[2][2] = cr * cp;
  31.  
  32. matrix[0][3] = 0.0f;
  33. matrix[1][3] = 0.0f;
  34. matrix[2][3] = 0.0f;
  35. }
  36.  
  37. void MatrixSetColumn(const Vector &in, int column, matrix3x4_t& out)
  38. {
  39. out[0][column] = in.x;
  40. out[1][column] = in.y;
  41. out[2][column] = in.z;
  42. }
  43.  
  44. void AngleMatrix(const QAngle &angles, const Vector &position, matrix3x4_t& matrix_out)
  45. {
  46. AngleMatrix(angles, matrix_out);
  47. MatrixSetColumn(position, 3, matrix_out);
  48. }
  49.  
  50. void MatrixCopy(const matrix3x4_t& source, matrix3x4_t& target)
  51. {
  52. for (int i = 0; i < 3; i++) {
  53. for (int j = 0; j < 4; j++) {
  54. target[i][j] = source[i][j];
  55. }
  56. }
  57. }
  58.  
  59. void MatrixMultiply(matrix3x4_t& in1, const matrix3x4_t& in2)
  60. {
  61. matrix3x4_t out;
  62. if (&in1 == &out)
  63. {
  64. matrix3x4_t in1b;
  65. MatrixCopy(in1, in1b);
  66. MatrixMultiply(in1b, in2);
  67. return;
  68. }
  69. if (&in2 == &out)
  70. {
  71. matrix3x4_t in2b;
  72. MatrixCopy(in2, in2b);
  73. MatrixMultiply(in1, in2b);
  74. return;
  75. }
  76. out[0][0] = in1[0][0] * in2[0][0] + in1[0][1] * in2[1][0] +
  77. in1[0][2] * in2[2][0];
  78. out[0][1] = in1[0][0] * in2[0][1] + in1[0][1] * in2[1][1] +
  79. in1[0][2] * in2[2][1];
  80. out[0][2] = in1[0][0] * in2[0][2] + in1[0][1] * in2[1][2] +
  81. in1[0][2] * in2[2][2];
  82. out[0][3] = in1[0][0] * in2[0][3] + in1[0][1] * in2[1][3] +
  83. in1[0][2] * in2[2][3] + in1[0][3];
  84. out[1][0] = in1[1][0] * in2[0][0] + in1[1][1] * in2[1][0] +
  85. in1[1][2] * in2[2][0];
  86. out[1][1] = in1[1][0] * in2[0][1] + in1[1][1] * in2[1][1] +
  87. in1[1][2] * in2[2][1];
  88. out[1][2] = in1[1][0] * in2[0][2] + in1[1][1] * in2[1][2] +
  89. in1[1][2] * in2[2][2];
  90. out[1][3] = in1[1][0] * in2[0][3] + in1[1][1] * in2[1][3] +
  91. in1[1][2] * in2[2][3] + in1[1][3];
  92. out[2][0] = in1[2][0] * in2[0][0] + in1[2][1] * in2[1][0] +
  93. in1[2][2] * in2[2][0];
  94. out[2][1] = in1[2][0] * in2[0][1] + in1[2][1] * in2[1][1] +
  95. in1[2][2] * in2[2][1];
  96. out[2][2] = in1[2][0] * in2[0][2] + in1[2][1] * in2[1][2] +
  97. in1[2][2] * in2[2][2];
  98. out[2][3] = in1[2][0] * in2[0][3] + in1[2][1] * in2[1][3] +
  99. in1[2][2] * in2[2][3] + in1[2][3];
  100.  
  101. in1 = out;
  102. }
  103.  
  104. void VectorRotate(const float *in1, const matrix3x4_t& in2, float *out)
  105. {
  106. out[0] = DotProduct(in1, in2[0]);
  107. out[1] = DotProduct(in1, in2[1]);
  108. out[2] = DotProduct(in1, in2[2]);
  109. }
  110.  
  111. void VectorRotate(const Vector& in1, const matrix3x4_t &in2, Vector &out)
  112. {
  113. VectorRotate(&in1.x, in2, &out.x);
  114. }
  115.  
  116. void VectorRotate(const Vector &in1, const QAngle &in2, Vector &out)
  117. {
  118. matrix3x4_t matRotate;
  119. AngleMatrix(in2, matRotate);
  120. VectorRotate(in1, matRotate, out);
  121. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement