Last active
August 27, 2017 13:24
-
-
Save olevegard/dbc3ef7f94930ab8a45005822f537dad to your computer and use it in GitHub Desktop.
A simple class for creating and returning model matrices
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#pragma once | |
#include <glm/glm.hpp> | |
#include <glm/gtx/transform.hpp> | |
class ModelMatrix | |
{ | |
public: | |
glm::mat4 GetModel() | |
{ | |
return model; | |
} | |
void SetMatrix(glm::mat4 mvp) | |
{ | |
shader.UseProgram(); | |
shader.SetMatrix( mvp ); | |
} | |
void Render() const | |
{ | |
shader.UseProgram(); | |
glDrawArrays(GL_TRIANGLES, 0, positions.size() / 3 ); | |
} | |
void ResetMatrix() | |
{ | |
model = glm::mat4(1.0f); | |
rotate = glm::mat4(1.0f); | |
scale = glm::mat4(1.0f); | |
translate = glm::mat4(1.0f); | |
} | |
void Translate(const glm::vec3 &axis) | |
{ | |
translate = glm::translate(translate, axis); | |
UpdateMatrix(); | |
} | |
void Rotate(glm::vec3 axis, double angle) | |
{ | |
rotate = glm::rotate(rotate, angle, axis); | |
UpdateMatrix(); | |
} | |
void Scale(glm::vec3 axis) | |
{ | |
scale = glm::scale(scale, axis); | |
UpdateMatrix(); | |
} | |
void UpdateMatrix() | |
{ | |
model = scale * translate * rotate ; | |
} | |
private: | |
glm::mat4 model; | |
glm::mat4 rotate; | |
glm::mat4 translate; | |
glm::mat4 scale; | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment