1 #ifndef NTA_ANIMATION2D_H_INCLUDED
2 #define NTA_ANIMATION2D_H_INCLUDED
4 #include "nta/ContextData.h"
20 return num_rows * num_cols;
22 glm::vec2 sprite_dims()
const {
23 return glm::vec2(
tex.
width/num_cols,
tex.height/num_rows);
26 std::size_t sprite_area()
const {
27 auto dims = sprite_dims();
33 glm::vec4
get_uv(std::size_t index)
const {
34 std::size_t r = index/num_cols;
35 std::size_t c = index%num_cols;
36 float w = 1.f/num_cols;
37 float h = 1.f/num_rows;
38 return glm::vec4(c*w, r*h, w, h);
42 auto coords =
get_uv(index);
43 coords.x += coords[2];
49 return glm::vec2(
tex.
width/num_cols,
tex.height/num_rows);
81 std::size_t length = 1,
float speed = 1);
83 std::size_t start = 0, std::size_t length = 1,
float speed = 1);
85 std::size_t start = 0, std::size_t length = 1,
float speed = 1);
86 glm::vec4 get_uv()
const;
87 glm::vec4 get_flipped_uv()
const;
88 glm::vec2 get_frame_dims()
const;
89 std::size_t get_index()
const;
90 std::size_t get_start()
const;
91 std::size_t get_length()
const;
92 float get_speed()
const;
93 GLuint get_tex_id()
const;
94 float get_time()
const;
95 void switch_animation(std::size_t start, std::size_t length,
float speed = 1);
97 void set_speed(
float speed);
98 void reset_time() {
m_time = 0.0f; }
103 #endif // NTA_ANIMATION2D_H_INCLUDED