Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- #pragma once
- #include "../glm/glm/glm.hpp"
- class Texture;
- class Graphics;
- //Sprite class
- //not a resource, does require one (texture)
- class Sprite
- {
- //graphics can interact with all sprite data directly, no other class would ever need direct access to these values.
- // thus, by making the graphics a friend class, the sprite class will have a cleaner interface for the user (me)
- friend class Graphics;
- public:
- Sprite();
- Sprite(Texture *texture);
- 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);
- //delete VBO on destruction
- ~Sprite();
- //create the VBO for the sprite plane
- 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);
- void load(Texture *texture);
- //getters
- float getX();
- float getY();
- float getWidth();
- float getHeight();
- float getRotation();
- //setters
- void setRotation(float newRotation);
- void setPosition(float x, float y);
- void setPosition(glm::vec2 newPosition);
- void setX(float x);
- void setY(float y);
- void setWidthAndHeight(float width, float height);
- void setWidthAndHeight(glm::vec2 widthAndHeight);
- void setUV(float U1, float V1, float U2, float V2);
- void setU1(float U1);
- void setU2(float U2);
- void setV1(float V1);
- void setV2(float V2);
- //texture that will be drawn
- Texture *texture;
- private:
- //VBO of the sprite plane
- unsigned int VBO;
- //matrices of the sprite
- glm::mat4 modelMat;
- glm::mat4 rotationMat;
- //can go directly into main matrix
- glm::vec2 position;
- glm::vec2 widthHeight;
- //store values to check if vbo needs to change
- float UVcoords[4];
- //store value to check if rotation matrix needs to change
- float rotation;
- //bool to check if the model matrix needs to be recalculated
- bool shouldRecalculateMatrix;
- //function that uses the variable to update the sprite (called in )
- void updateModelMatrix();
- };
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement