Added the ability to set the position of a model.

This commit is contained in:
Warwick 2022-08-11 13:50:39 +01:00
parent 28cd790e31
commit a0a0861723
3 changed files with 16 additions and 1 deletions

View file

@ -198,4 +198,13 @@ void Model::unloadTextures() {
}
}
void Model::setPositionToOrigin() {
this->translate(this->position * -1.0f);
this->position = glm::vec4(0.0f, 0.0f, 0.0f, 1.0f);
}
void Model::setPosition(glm::vec3 position) {
this->setPositionToOrigin();
this->translate(position);
}
Model::~Model() { this->unloadTextures(); }

View file

@ -37,6 +37,9 @@ private:
aiTextureType type,
std::string typeName);
// Reset the models position to 0,0,0,
void setPositionToOrigin();
void unloadTextures();
std::string directory;
@ -60,6 +63,8 @@ public:
void resize(glm::vec3 scale);
// Scale the model
void rotate(float angle, glm::vec3 axis);
// Set the postion of the model to a set of coordinates
void setPosition(glm::vec3 position);
~Model();
};

View file

@ -80,7 +80,8 @@ int main(int argc, char **argv) {
// Model gun(ROOT_DIR "data/models/gun/Cerberus_LP.FBX");
Model boxbarrel(ROOT_DIR
"data/models/wooden_boxbarrel/wooden_box_and_barrel.obj");
boxbarrel.translate(glm::vec3(0.0f, -1.0f, 0.0f));
// boxbarrel.translate(glm::vec3(0.0f, -1.0f, 0.0f));
boxbarrel.setPosition(glm::vec3(0.0f, -1.0f, 0.0f));
// cube.translate(glm::vec3(3.0f, 0.0f, -1.0f));
// backpack.translate(glm::vec3(-3.0f, 0.0f, 0.0f));
// gun.translate(glm::vec3(0.0f, 1.0f, 0.0f));