Advertisement
Guest User

Untitled

a guest
Jun 26th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.13 KB | None | 0 0
  1. Mat4 RotationMatrix(float radians)
  2. {
  3. Mat4 result;
  4.  
  5. // assuming column-major order (first index is column, second is row)
  6. result[0][0] = Math.Cos(radians);
  7. result[0][1] = -Math.Sin(radians);
  8. result[1][0] = Math.Sin(radians);
  9. result[1][1] = Math.Cos(radians);
  10.  
  11. return result;
  12. }
  13.  
  14. Mat4 MirrorXMatrix()
  15. {
  16. Mat4 result;
  17.  
  18. result[0][0] = -1.0f;
  19. result[0][1] = 0.0f;
  20. result[1][0] = 0.0f;
  21. result[1][1] = 1.0f;
  22.  
  23. return result;
  24. }
  25.  
  26. Mat4 ScaleMatrix(float x, float y)
  27. {
  28. Mat4 result;
  29.  
  30. result[0][0] = x;
  31. result[0][1] = 0;
  32. result[1][0] = 0;
  33. result[1][1] = y;
  34.  
  35. return result;
  36. }
  37.  
  38. int main()
  39. {
  40. float heading = 0.2f;
  41. float scaleX = 2.0f;
  42. float scaleY = 3.0f;
  43.  
  44. // because the order of transformations goes right to left, this matrix will rotate, then mirror, then scale.
  45. Mat4 shipMatrix = ScaleMatrix(scaleX, scaleY) * MirrorXMatrix() * RotateMatrix(heading);
  46.  
  47. // assume we have ship.Points or whatever
  48. for (int i = 0; i < ship.Points.Length; i++)
  49. {
  50. Vec2 transformedPoint = shipMatrix * ship.Points[i];
  51. // now do whatever with it
  52. }
  53. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement