Advertisement
Guest User

Sprite.h

a guest
Mar 24th, 2017
68
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.00 KB | None | 0 0
  1. #pragma once
  2.  
  3. #include "../glm/glm/glm.hpp"
  4.  
  5. class Texture;
  6. class Graphics;
  7.  
  8. //Sprite class
  9. //not a resource, does require one (texture)
  10. class Sprite
  11. {
  12. //graphics can interact with all sprite data directly, no other class would ever need direct access to these values.
  13. // thus, by making the graphics a friend class, the sprite class will have a cleaner interface for the user (me)
  14. friend class Graphics;
  15. public:
  16. Sprite();
  17. Sprite(Texture *texture);
  18. Sprite(Texture *texture, float x, float y, float width, float height, float rotation = 0, float U1 = 0, float V1 = 0, float U2 = 1, float V2 = 1);
  19. //delete VBO on destruction
  20. ~Sprite();
  21.  
  22. //create the VBO for the sprite plane
  23. void initialize(float x, float y, float width, float height, float rotation = 0, float U1 = 0, float V1 = 0, float U2 = 1, float V2 = 1);
  24. void load(Texture *texture);
  25.  
  26. //getters
  27. float getX();
  28. float getY();
  29. float getWidth();
  30. float getHeight();
  31. float getRotation();
  32.  
  33. //setters
  34. void setRotation(float newRotation);
  35. void setPosition(float x, float y);
  36. void setPosition(glm::vec2 newPosition);
  37. void setX(float x);
  38. void setY(float y);
  39. void setWidthAndHeight(float width, float height);
  40. void setWidthAndHeight(glm::vec2 widthAndHeight);
  41. void setUV(float U1, float V1, float U2, float V2);
  42. void setU1(float U1);
  43. void setU2(float U2);
  44. void setV1(float V1);
  45. void setV2(float V2);
  46.  
  47. //texture that will be drawn
  48. Texture *texture;
  49. private:
  50. //VBO of the sprite plane
  51. unsigned int VBO;
  52.  
  53. //matrices of the sprite
  54. glm::mat4 modelMat;
  55. glm::mat4 rotationMat;
  56.  
  57. //can go directly into main matrix
  58. glm::vec2 position;
  59. glm::vec2 widthHeight;
  60.  
  61. //store values to check if vbo needs to change
  62. float UVcoords[4];
  63.  
  64. //store value to check if rotation matrix needs to change
  65. float rotation;
  66.  
  67. //bool to check if the model matrix needs to be recalculated
  68. bool shouldRecalculateMatrix;
  69. //function that uses the variable to update the sprite (called in )
  70. void updateModelMatrix();
  71. };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement