Quad.cpp 2.2 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192939495969798
  1. /**
  2. * Copyright (c) 2006-2016 LOVE Development Team
  3. *
  4. * This software is provided 'as-is', without any express or implied
  5. * warranty. In no event will the authors be held liable for any damages
  6. * arising from the use of this software.
  7. *
  8. * Permission is granted to anyone to use this software for any purpose,
  9. * including commercial applications, and to alter it and redistribute it
  10. * freely, subject to the following restrictions:
  11. *
  12. * 1. The origin of this software must not be misrepresented; you must not
  13. * claim that you wrote the original software. If you use this software
  14. * in a product, an acknowledgment in the product documentation would be
  15. * appreciated but is not required.
  16. * 2. Altered source versions must be plainly marked as such, and must not be
  17. * misrepresented as being the original software.
  18. * 3. This notice may not be removed or altered from any source distribution.
  19. **/
  20. // LOVE
  21. #include "Quad.h"
  22. // C
  23. #include <cstring> // For memcpy
  24. namespace love
  25. {
  26. namespace graphics
  27. {
  28. Quad::Quad(const Quad::Viewport &v, double sw, double sh)
  29. : sw(sw)
  30. , sh(sh)
  31. {
  32. memset(vertices, 255, sizeof(Vertex) * 4);
  33. refresh(v, sw, sh);
  34. }
  35. Quad::~Quad()
  36. {
  37. }
  38. void Quad::refresh(const Quad::Viewport &v, double sw, double sh)
  39. {
  40. viewport = v;
  41. // Vertices are ordered for use with triangle strips:
  42. // 0----2
  43. // | / |
  44. // | / |
  45. // 1----3
  46. vertices[0].x = 0.0f;
  47. vertices[0].y = 0.0f;
  48. vertices[1].x = 0.0f;
  49. vertices[1].y = (float) v.h;
  50. vertices[2].x = (float) v.w;
  51. vertices[2].y = 0.0f;
  52. vertices[3].x = (float) v.w;
  53. vertices[3].y = (float) v.h;
  54. vertices[0].s = (float) (v.x/sw);
  55. vertices[0].t = (float) (v.y/sh);
  56. vertices[1].s = (float) (v.x/sw);
  57. vertices[1].t = (float) ((v.y+v.h)/sh);
  58. vertices[2].s = (float) ((v.x+v.w)/sw);
  59. vertices[2].t = (float) (v.y/sh);
  60. vertices[3].s = (float) ((v.x+v.w)/sw);
  61. vertices[3].t = (float) ((v.y+v.h)/sh);
  62. }
  63. void Quad::setViewport(const Quad::Viewport &v)
  64. {
  65. refresh(v, sw, sh);
  66. }
  67. Quad::Viewport Quad::getViewport() const
  68. {
  69. return viewport;
  70. }
  71. double Quad::getTextureWidth() const
  72. {
  73. return sw;
  74. }
  75. double Quad::getTextureHeight() const
  76. {
  77. return sh;
  78. }
  79. const Vertex *Quad::getVertices() const
  80. {
  81. return vertices;
  82. }
  83. } // graphics
  84. } // love