Added the ability to set the position of a model.
This commit is contained in:
parent
28cd790e31
commit
a0a0861723
3 changed files with 16 additions and 1 deletions
|
|
@ -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(); }
|
||||
|
|
|
|||
|
|
@ -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();
|
||||
};
|
||||
|
|
|
|||
|
|
@ -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));
|
||||
|
|
|
|||
Loading…
Reference in a new issue