Quad.cpp 2.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100
  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. love::Type Quad::type("Quad", &Object::type);
  29. Quad::Quad(const Quad::Viewport &v, double sw, double sh)
  30. : sw(sw)
  31. , sh(sh)
  32. {
  33. memset(vertices, 255, sizeof(Vertex) * 4);
  34. refresh(v, sw, sh);
  35. }
  36. Quad::~Quad()
  37. {
  38. }
  39. void Quad::refresh(const Quad::Viewport &v, double sw, double sh)
  40. {
  41. viewport = v;
  42. // Vertices are ordered for use with triangle strips:
  43. // 0----2
  44. // | / |
  45. // | / |
  46. // 1----3
  47. vertices[0].x = 0.0f;
  48. vertices[0].y = 0.0f;
  49. vertices[1].x = 0.0f;
  50. vertices[1].y = (float) v.h;
  51. vertices[2].x = (float) v.w;
  52. vertices[2].y = 0.0f;
  53. vertices[3].x = (float) v.w;
  54. vertices[3].y = (float) v.h;
  55. vertices[0].s = (float) (v.x/sw);
  56. vertices[0].t = (float) (v.y/sh);
  57. vertices[1].s = (float) (v.x/sw);
  58. vertices[1].t = (float) ((v.y+v.h)/sh);
  59. vertices[2].s = (float) ((v.x+v.w)/sw);
  60. vertices[2].t = (float) (v.y/sh);
  61. vertices[3].s = (float) ((v.x+v.w)/sw);
  62. vertices[3].t = (float) ((v.y+v.h)/sh);
  63. }
  64. void Quad::setViewport(const Quad::Viewport &v)
  65. {
  66. refresh(v, sw, sh);
  67. }
  68. Quad::Viewport Quad::getViewport() const
  69. {
  70. return viewport;
  71. }
  72. double Quad::getTextureWidth() const
  73. {
  74. return sw;
  75. }
  76. double Quad::getTextureHeight() const
  77. {
  78. return sh;
  79. }
  80. const Vertex *Quad::getVertices() const
  81. {
  82. return vertices;
  83. }
  84. } // graphics
  85. } // love