2021-01-01 16:20:09 +00:00
|
|
|
#include <GL/glew.h>
|
|
|
|
#include <glm/mat4x4.hpp>
|
|
|
|
#include <glm/gtc/type_ptr.hpp>
|
|
|
|
|
|
|
|
#include <graphics.hpp>
|
|
|
|
#include <modelpart.hpp>
|
|
|
|
|
|
|
|
#include <iostream>
|
|
|
|
|
|
|
|
ModelPart::ModelPart() {
|
|
|
|
}
|
|
|
|
|
|
|
|
ModelPart::ModelPart(const char* texPath, GLuint transUniformNum) {
|
|
|
|
//create vbo, ebo, vao
|
|
|
|
initBuffers(&vao);
|
|
|
|
//create texture
|
2021-01-01 18:55:12 +00:00
|
|
|
initTexture(&tex[0], texPath);
|
2021-01-01 16:20:09 +00:00
|
|
|
|
|
|
|
transUniform = transUniformNum;
|
2021-01-01 18:55:12 +00:00
|
|
|
|
|
|
|
empty = false;
|
2021-01-01 16:20:09 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelPart::bindAndDraw() {
|
2021-01-01 18:55:12 +00:00
|
|
|
if (empty) { return; }
|
2021-01-01 16:20:09 +00:00
|
|
|
glBindVertexArray(vao);
|
2021-01-01 18:55:12 +00:00
|
|
|
glBindTexture(GL_TEXTURE_2D, tex[texSelection]);
|
2021-01-01 16:20:09 +00:00
|
|
|
glUniformMatrix4fv(transUniform, 1, GL_FALSE, glm::value_ptr(transMatrix));
|
|
|
|
glDrawElements(GL_TRIANGLES, 6, GL_UNSIGNED_INT, 0);
|
|
|
|
}
|
|
|
|
|
2021-01-03 15:11:35 +00:00
|
|
|
void ModelPart::setTransform(glm::vec2 position, float scale) {
|
2021-01-01 18:55:12 +00:00
|
|
|
transMatrix = glm::translate(glm::mat4(1.0f), glm::vec3(position.x, -position.y, 0.0f));
|
2021-01-03 15:11:35 +00:00
|
|
|
transMatrix = glm::scale(transMatrix, glm::vec3(scale, scale, scale));
|
2021-01-01 18:55:12 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void ModelPart::addTexture(const char* texPath, size_t slot) {
|
|
|
|
initTexture(&tex[slot], texPath);
|
|
|
|
}
|
|
|
|
|
|
|
|
void ModelPart::selectTexture(size_t slot) {
|
|
|
|
texSelection = slot;
|
2021-01-01 16:20:09 +00:00
|
|
|
}
|