add ModelBatch.translate(...), .rotate(...), .scale(...)
This commit is contained in:
@@ -116,6 +116,18 @@ static glm::mat4 extract_rotation(glm::mat4 matrix) {
|
|||||||
return glm::toMat3(rotation);
|
return glm::toMat3(rotation);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ModelBatch::translate(glm::vec3 vec) {
|
||||||
|
pushMatrix(glm::translate(glm::mat4(1.0f), vec));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelBatch::rotate(glm::vec3 axis, float angle) {
|
||||||
|
pushMatrix(glm::rotate(glm::mat4(1.0f), angle, axis));
|
||||||
|
}
|
||||||
|
|
||||||
|
void ModelBatch::scale(glm::vec3 vec) {
|
||||||
|
pushMatrix(glm::scale(glm::mat4(1.0f), vec));
|
||||||
|
}
|
||||||
|
|
||||||
void ModelBatch::pushMatrix(glm::mat4 matrix) {
|
void ModelBatch::pushMatrix(glm::mat4 matrix) {
|
||||||
matrices.push_back(combined);
|
matrices.push_back(combined);
|
||||||
combined = combined * matrix;
|
combined = combined * matrix;
|
||||||
|
|||||||
@@ -74,6 +74,10 @@ public:
|
|||||||
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
ModelBatch(size_t capacity, Assets* assets, Chunks* chunks);
|
||||||
~ModelBatch();
|
~ModelBatch();
|
||||||
|
|
||||||
|
void translate(glm::vec3 vec);
|
||||||
|
void rotate(glm::vec3 axis, float angle);
|
||||||
|
void scale(glm::vec3 vec);
|
||||||
|
|
||||||
void pushMatrix(glm::mat4 matrix);
|
void pushMatrix(glm::mat4 matrix);
|
||||||
void popMatrix();
|
void popMatrix();
|
||||||
|
|
||||||
|
|||||||
@@ -196,20 +196,23 @@ void WorldRenderer::renderLevel(
|
|||||||
|
|
||||||
model::Model model {};
|
model::Model model {};
|
||||||
auto& mesh = model.addMesh("gui/warning");
|
auto& mesh = model.addMesh("gui/warning");
|
||||||
mesh.addBox({}, glm::vec3(1));
|
mesh.addBox({}, glm::vec3(0.3f));
|
||||||
mesh.addBox({}, glm::vec3(2));
|
mesh.addBox({}, glm::vec3(0.6f));
|
||||||
|
|
||||||
auto& mesh2 = model.addMesh("gui/error");
|
auto& mesh2 = model.addMesh("gui/error");
|
||||||
mesh2.addBox({}, glm::vec3(1.25f));
|
mesh2.addBox({}, glm::vec3(0.7f));
|
||||||
mesh2.addBox({}, glm::vec3(3.25f));
|
mesh2.addBox({}, glm::vec3(0.9f));
|
||||||
|
|
||||||
|
float timer = static_cast<float>(Window::time());
|
||||||
assets->getTexture("gui/menubg")->bind();
|
assets->getTexture("gui/menubg")->bind();
|
||||||
shader->uniformMatrix("u_model", glm::mat4(1.0f));
|
shader->uniformMatrix("u_model", glm::mat4(1.0f));
|
||||||
modelBatch->pushMatrix(glm::translate(glm::mat4(1.0f), glm::vec3(0, 88, 0)));
|
modelBatch->translate({0, 86, 0});
|
||||||
modelBatch->pushMatrix(glm::rotate(glm::mat4(1.0f), static_cast<float>(Window::time()), glm::vec3(1, 0, 0)));
|
modelBatch->scale(glm::vec3(glm::sin(timer*6)+1));
|
||||||
|
modelBatch->rotate(glm::vec3(1, 0, 0), timer);
|
||||||
modelBatch->draw(model);
|
modelBatch->draw(model);
|
||||||
modelBatch->popMatrix();
|
modelBatch->popMatrix();
|
||||||
modelBatch->popMatrix();
|
modelBatch->popMatrix();
|
||||||
|
modelBatch->popMatrix();
|
||||||
|
|
||||||
skybox->unbind();
|
skybox->unbind();
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user