From 1f6079dd2596277be899ee1c10e62455aabed0ab Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 16 Jun 2022 14:04:18 +0100 Subject: [PATCH] added ability to resize models so I don't have to tinker with gun model. --- src/Model.cpp | 9 +++++++++ src/Model.h | 4 ++++ src/main.cpp | 4 +++- 3 files changed, 16 insertions(+), 1 deletion(-) diff --git a/src/Model.cpp b/src/Model.cpp index 6cd3111..8f9371f 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -20,6 +20,15 @@ void Model::translate(glm::vec3 translation) { // set model transform this->model = glm::translate(glm::mat4(1.0f), glm::vec3(this->position)); } +void Model::resize(glm::vec3 scale) { + // set worldspace postition + glm::mat4 transMatrix = + glm::translate(glm::mat4(1.0f), glm::vec3(this->position)); + this->scale = scale; + + // set model transform + this->model = glm::scale(transMatrix, glm::vec3(this->scale)); +} void Model::loadModel(std::string path) { // Attempt to import model data using assimp diff --git a/src/Model.h b/src/Model.h index 31c6fad..141fcca 100644 --- a/src/Model.h +++ b/src/Model.h @@ -23,6 +23,8 @@ private: // Position glm::vec4 position = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f); + // Scale + glm::vec3 scale = glm::vec3(1.0f, 1.0f, 1.0f); // Load in models using assimp void loadModel(std::string path); @@ -52,6 +54,8 @@ public: // Translate the model void translate(glm::vec3 translation); + // Scale the model + void resize(glm::vec3 scale); ~Model(); }; diff --git a/src/main.cpp b/src/main.cpp index cd541ef..a5a447c 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -74,7 +74,9 @@ int main(int argc, char **argv) { Model cube(ROOT_DIR "data/models/cube/cube.obj"); Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX"); cube.translate(glm::vec3(3.0f, 0.0f, -1.0f)); - gun.translate(glm::vec3(-3.0f, 0.0f, 0.0f)); + backpack.translate(glm::vec3(-3.0f, 0.0f, 0.0f)); + gun.translate(glm::vec3(0.0f, 1.0f, 0.0f)); + gun.resize(glm::vec3(0.02f, 0.02f, 0.02f)); // Create player camera object PlayerCamera camera;