From 3700494d840fca82c76fdf72ce1f974e72420893 Mon Sep 17 00:00:00 2001 From: Warwick Date: Thu, 16 Jun 2022 14:23:12 +0100 Subject: [PATCH] Rotation added to model (whole system is currently dirty) --- src/Model.cpp | 3 +++ src/Model.h | 4 ++++ src/main.cpp | 1 + 3 files changed, 8 insertions(+) diff --git a/src/Model.cpp b/src/Model.cpp index 8f9371f..acacc6c 100644 --- a/src/Model.cpp +++ b/src/Model.cpp @@ -29,6 +29,9 @@ void Model::resize(glm::vec3 scale) { // set model transform this->model = glm::scale(transMatrix, glm::vec3(this->scale)); } +void Model::rotate(float angle, glm::vec3 axis) { + this->model = glm::rotate(this->model, angle, axis); +} void Model::loadModel(std::string path) { // Attempt to import model data using assimp diff --git a/src/Model.h b/src/Model.h index 141fcca..ab29bac 100644 --- a/src/Model.h +++ b/src/Model.h @@ -25,6 +25,8 @@ private: 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); + // Rotation + glm::vec3 rotation = glm::vec3(0.0f, 0.0f, 0.0f); // Load in models using assimp void loadModel(std::string path); @@ -56,6 +58,8 @@ public: void translate(glm::vec3 translation); // Scale the model void resize(glm::vec3 scale); + // Scale the model + void rotate(float angle, glm::vec3 axis); ~Model(); }; diff --git a/src/main.cpp b/src/main.cpp index a5a447c..9c439d2 100644 --- a/src/main.cpp +++ b/src/main.cpp @@ -77,6 +77,7 @@ int main(int argc, char **argv) { 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)); + gun.rotate(glm::radians(-90.0f), glm::vec3(0.0f, 1.0f, 0.0f)); // Create player camera object PlayerCamera camera;