Skip to content

Commit

Permalink
GRAPHICS: Add Model::getCenter() and Model::getAbsoluteCenter()
Browse files Browse the repository at this point in the history
  • Loading branch information
DrMcCoy committed Nov 19, 2018
1 parent a3b99e4 commit 04ea958
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 0 deletions.
16 changes: 16 additions & 0 deletions src/graphics/aurora/model.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -216,6 +216,22 @@ void Model::getAbsolutePosition(float &x, float &y, float &z) const {
z = _absolutePosition[3][2];
}

void Model::getCenter(float &x, float &y, float &z) {
x = _center[0] * _scale[0];
y = _center[1] * _scale[1];
z = _center[2] * _scale[2];
}

void Model::getAbsoluteCenter(float &x, float &y, float &z) {
glm::mat4 center = _absolutePosition;

center = glm::translate(center, glm::vec3(_center[0], _center[1], _center[2]));

x = center[3][0];
y = center[3][1];
z = center[3][2];
}

void Model::setScale(float x, float y, float z) {
lockFrameIfVisible();

Expand Down
5 changes: 5 additions & 0 deletions src/graphics/aurora/model.h
Original file line number Diff line number Diff line change
Expand Up @@ -115,6 +115,11 @@ class Model : public GLContainer, public Renderable {
/** Set the current position of the model. */
void setPosition(float x, float y, float z);

/** Get the model's center position. */
void getCenter(float &x, float &y, float &z);
/** Get the model's center position after translate/rotate. */
void getAbsoluteCenter(float &x, float &y, float &z);

/** Scale the model, relative to its current scale. */
void scale (float x, float y, float z);
/** Rotate the model, relative to its current orientation. */
Expand Down

0 comments on commit 04ea958

Please sign in to comment.