added ability to resize models so I don't have to tinker with gun model.

This commit is contained in:
Warwick 2022-06-16 14:04:18 +01:00
parent 8ef9ef72ca
commit 1f6079dd25
3 changed files with 16 additions and 1 deletions

View file

@ -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

View file

@ -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();
};

View file

@ -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;