Açıklama Yok
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

olcPGEX_Graphics2D.h 4.1KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. /*
  2. olcPGEX_Graphics2D.h
  3. +-------------------------------------------------------------+
  4. | OneLoneCoder Pixel Game Engine Extension |
  5. | Advanced 2D Rendering - v0.4 |
  6. +-------------------------------------------------------------+
  7. What is this?
  8. ~~~~~~~~~~~~~
  9. This is an extension to the olcPixelGameEngine, which provides
  10. advanced olc::Sprite manipulation and drawing routines. To use
  11. it, simply include this header file.
  12. License (OLC-3)
  13. ~~~~~~~~~~~~~~~
  14. Copyright 2018 - 2019 OneLoneCoder.com
  15. Redistribution and use in source and binary forms, with or without
  16. modification, are permitted provided that the following conditions
  17. are met:
  18. 1. Redistributions or derivations of source code must retain the above
  19. copyright notice, this list of conditions and the following disclaimer.
  20. 2. Redistributions or derivative works in binary form must reproduce
  21. the above copyright notice. This list of conditions and the following
  22. disclaimer must be reproduced in the documentation and/or other
  23. materials provided with the distribution.
  24. 3. Neither the name of the copyright holder nor the names of its
  25. contributors may be used to endorse or promote products derived
  26. from this software without specific prior written permission.
  27. THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
  28. "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
  29. LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
  30. A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT
  31. HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
  32. SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
  33. LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
  34. DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
  35. THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
  36. (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE
  37. OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
  38. Links
  39. ~~~~~
  40. YouTube: https://www.youtube.com/javidx9
  41. Discord: https://discord.gg/WhwHUMV
  42. Twitter: https://www.twitter.com/javidx9
  43. Twitch: https://www.twitch.tv/javidx9
  44. GitHub: https://www.github.com/onelonecoder
  45. Homepage: https://www.onelonecoder.com
  46. Author
  47. ~~~~~~
  48. David Barr, aka javidx9, �OneLoneCoder 2019
  49. */
  50. /*
  51. Matrices stored as [Column][Row] (i.e. x, y)
  52. |C0R0 C1R0 C2R0| | x | | x'|
  53. |C0R1 C1R1 C2R1| * | y | = | y'|
  54. |C0R2 C1R2 C2R2| |1.0| | - |
  55. */
  56. #ifndef OLC_PGEX_GFX2D
  57. #define OLC_PGEX_GFX2D
  58. #include "olcPixelGameEngine.h"
  59. #include <algorithm>
  60. #undef min
  61. #undef max
  62. namespace olc
  63. {
  64. // Container class for Advanced 2D Drawing functions
  65. class GFX2D : public olc::PGEX
  66. {
  67. // A representation of an affine transform, used to rotate, scale, offset & shear space
  68. public:
  69. class Transform2D
  70. {
  71. public:
  72. inline Transform2D();
  73. public:
  74. // Set this transformation to unity
  75. inline void Reset();
  76. // Append a rotation of fTheta radians to this transform
  77. inline void Rotate(float fTheta);
  78. // Append a translation (ox, oy) to this transform
  79. inline void Translate(float ox, float oy);
  80. // Append a scaling operation (sx, sy) to this transform
  81. inline void Scale(float sx, float sy);
  82. // Append a shear operation (sx, sy) to this transform
  83. inline void Shear(float sx, float sy);
  84. inline void Perspective(float ox, float oy);
  85. // Calculate the Forward Transformation of the coordinate (in_x, in_y) -> (out_x, out_y)
  86. inline void Forward(float in_x, float in_y, float &out_x, float &out_y);
  87. // Calculate the Inverse Transformation of the coordinate (in_x, in_y) -> (out_x, out_y)
  88. inline void Backward(float in_x, float in_y, float &out_x, float &out_y);
  89. // Regenerate the Inverse Transformation
  90. inline void Invert();
  91. private:
  92. inline void Multiply();
  93. float matrix[4][3][3];
  94. int nTargetMatrix;
  95. int nSourceMatrix;
  96. bool bDirty;
  97. };
  98. public:
  99. // Draws a sprite with the transform applied
  100. inline static void DrawSprite(olc::Sprite *sprite, olc::GFX2D::Transform2D &transform);
  101. };
  102. }
  103. #endif