Skip to content
Snippets Groups Projects
Commit b946f8ab authored by Robert Menzel's avatar Robert Menzel
Browse files

Improved MatrixStack performance

parent ba4db533
No related branches found
No related tags found
No related merge requests found
......@@ -74,29 +74,42 @@ public:
// will replace the top matrix with the given matrix
void loadMatrix( glm::mat4 matrixToLoad )
{
popMatrix();
if (!mStack.empty()) {
mStack.top() = matrixToLoad;
} else {
mStack.push( matrixToLoad );
}
}
// the top matrix will be multiplied with the given one and
// will then replace the top matrix
void multMatrix( const glm::mat4 &rhs )
{
mStack.push( popAndGetMatrix() * rhs );
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() *= rhs;
}
// pushes the product of top and rhs
void pushAndMultMatrix( const glm::mat4 &rhs )
{
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.push( mStack.top() * rhs );
}
// like glRotate rotates the top matrix around a given axis a given degree phi
void rotate(const float phi, const float x, const float y, const float z) { rotate( phi, glm::vec3( x,y,z )); }
void rotate(const float phi, const glm::vec3 &axis )
{
mStack.push( glm::rotate( popAndGetMatrix(), phi, axis ) );
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::rotate( mStack.top(), phi, axis );
}
// like glTranslate
void translate(float x, float y, float z) { translate( glm::vec3(x,y,z) ); }
void translate( glm::vec3 vector )
{
mStack.push( glm::translate( popAndGetMatrix(), vector) );
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::translate( mStack.top(), vector );
}
// like glScale
......@@ -104,7 +117,8 @@ public:
void scale( float x, float y, float z ) { scale( glm::vec3(x,y,z)); }
void scale( const glm::vec3 &factor )
{
mStack.push( glm::scale( popAndGetMatrix(), factor ) );
if (mStack.empty()) mStack.push( glm::mat4() );
mStack.top() = glm::scale( mStack.top(), factor );
}
private:
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment