Quad.cpp 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. /**
  2. * Copyright (c) 2006-2015 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, float sw, float 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, float sw, float sh)
  39. {
  40. viewport = v;
  41. vertices[0].x = 0;
  42. vertices[0].y = 0;
  43. vertices[1].x = 0;
  44. vertices[1].y = v.h;
  45. vertices[2].x = v.w;
  46. vertices[2].y = v.h;
  47. vertices[3].x = v.w;
  48. vertices[3].y = 0;
  49. vertices[0].s = v.x/sw;
  50. vertices[0].t = v.y/sh;
  51. vertices[1].s = v.x/sw;
  52. vertices[1].t = (v.y+v.h)/sh;
  53. vertices[2].s = (v.x+v.w)/sw;
  54. vertices[2].t = (v.y+v.h)/sh;
  55. vertices[3].s = (v.x+v.w)/sw;
  56. vertices[3].t = v.y/sh;
  57. }
  58. void Quad::setViewport(const Quad::Viewport &v)
  59. {
  60. refresh(v, sw, sh);
  61. }
  62. Quad::Viewport Quad::getViewport() const
  63. {
  64. return viewport;
  65. }
  66. const Vertex *Quad::getVertices() const
  67. {
  68. return vertices;
  69. }
  70. } // graphics
  71. } // love