✨ Canvas rotation and translation.
parent
a9567e703c
commit
a8a2bd893c
|
@ -8,9 +8,10 @@ out vec4 _color;
|
|||
out vec2 _tex_coord;
|
||||
|
||||
uniform mat4 proj;
|
||||
uniform mat4 model;
|
||||
|
||||
void main() {
|
||||
gl_Position = proj * vec4(pos, 1.0);
|
||||
gl_Position = proj * model * vec4(pos, 1.0);
|
||||
_color = color;
|
||||
_tex_coord = tex_coord;
|
||||
}
|
||||
|
|
|
@ -11,12 +11,14 @@ namespace rid
|
|||
tex->load(RID_DATADIR / "assets" / "images" / "walk_0.png");
|
||||
m_canvas->set_texture(std::move(tex));
|
||||
|
||||
m_canvas->draw_tex(glm::vec2 {512.0f, 512.0f},
|
||||
m_canvas->draw_tex(glm::vec2 {0.0f, 0.0f},
|
||||
glm::vec2 {96.0f, 96.0f},
|
||||
glm::vec4 {1.0f, 1.0f, 1.0f, 1.0f},
|
||||
glm::vec2 {0.f, 0.0f},
|
||||
glm::vec2 {32.0f, 32.0f});
|
||||
|
||||
m_canvas->move(glm::vec2 {512.f, 512.f});
|
||||
|
||||
}
|
||||
|
||||
/*virtual*/ Arena::~Arena()
|
||||
|
|
|
@ -21,6 +21,16 @@ namespace rid
|
|||
glDeleteBuffers(1, &m_vbo);
|
||||
}
|
||||
|
||||
void Canvas::move(glm::vec2 pos)
|
||||
{
|
||||
m_pos += pos;
|
||||
}
|
||||
|
||||
void Canvas::rotate(float rad)
|
||||
{
|
||||
m_angle += rad;
|
||||
}
|
||||
|
||||
void Canvas::set_texture(std::unique_ptr<Texture> texture)
|
||||
{
|
||||
m_shaders->use();
|
||||
|
@ -90,6 +100,11 @@ namespace rid
|
|||
{
|
||||
use();
|
||||
m_shaders->set_mat4("proj", transform);
|
||||
|
||||
auto rot = glm::rotate(glm::mat4 {1.0f}, m_angle, glm::vec3 {0.f, 0.f, 1.f});
|
||||
auto loc = glm::translate(glm::mat4 {1.0f}, glm::vec3 {m_pos.x, m_pos.y, 0.f});
|
||||
|
||||
m_shaders->set_mat4("model", loc * rot);
|
||||
glDrawArrays(GL_TRIANGLES, 0, m_vertices.size());
|
||||
}
|
||||
|
||||
|
|
|
@ -20,6 +20,9 @@ namespace rid
|
|||
explicit Canvas();
|
||||
virtual ~Canvas();
|
||||
|
||||
void move(glm::vec2 pos);
|
||||
void rotate(float rad);
|
||||
|
||||
void set_texture(std::unique_ptr<Texture> texture);
|
||||
|
||||
// Draw stuff
|
||||
|
@ -37,6 +40,9 @@ namespace rid
|
|||
std::unique_ptr<Shaders> m_shaders;
|
||||
std::vector<Vertex> m_vertices;
|
||||
std::unique_ptr<Texture> m_texture;
|
||||
glm::vec2 m_pos {0.f};
|
||||
float m_angle = 0.f;
|
||||
|
||||
GLuint m_vao;
|
||||
GLuint m_vbo;
|
||||
|
||||
|
|
Loading…
Reference in New Issue