From: Mikko Rasa Date: Sun, 2 Nov 2008 21:18:56 +0000 (+0000) Subject: Move transform functions to matrix.h X-Git-Tag: 1.1~14 X-Git-Url: http://git.tdb.fi/?a=commitdiff_plain;h=2316272b57cf9bea26d2c35b9451910c169efafa;p=libs%2Fgl.git Move transform functions to matrix.h Add RAII version of push_matrix --- diff --git a/source/matrix.cpp b/source/matrix.cpp index 7a910786..78412180 100644 --- a/source/matrix.cpp +++ b/source/matrix.cpp @@ -40,5 +40,25 @@ void pop_matrix() glPopMatrix(); } +void translate(float x, float y, float z) +{ + glTranslatef(x, y, z); +} + +void rotate(float a, float x, float y, float z) +{ + glRotatef(a, x, y, z); +} + +void scale(float x, float y, float z) +{ + glScalef(x, y, z); +} + +void scale_uniform(float s) +{ + scale(s, s, s); +} + } // namespace GL } // namespace Msp diff --git a/source/matrix.h b/source/matrix.h index fe67ad7e..13de6c8f 100644 --- a/source/matrix.h +++ b/source/matrix.h @@ -27,6 +27,18 @@ void mult_matrix(const double *); void push_matrix(); void pop_matrix(); +/// RAII object - pushes matrix when constructed and pops when destroyed +struct PushMatrix +{ + PushMatrix() { push_matrix(); } + ~PushMatrix() { pop_matrix(); } +}; + +void translate(float, float, float); +void rotate(float, float, float, float); +void scale(float, float, float); +void scale_uniform(float); + } // namespace GL } // namespace Msp diff --git a/source/transform.cpp b/source/transform.cpp deleted file mode 100644 index 98932b83..00000000 --- a/source/transform.cpp +++ /dev/null @@ -1,35 +0,0 @@ -/* $Id$ - -This file is part of libmspgl -Copyright © 2007 Mikko Rasa, Mikkosoft Productions -Distributed under the LGPL -*/ - -#include "gl.h" -#include "transform.h" - -namespace Msp { -namespace GL { - -void translate(float x, float y, float z) -{ - glTranslatef(x, y, z); -} - -void rotate(float a, float x, float y, float z) -{ - glRotatef(a, x, y, z); -} - -void scale(float x, float y, float z) -{ - glScalef(x, y, z); -} - -void scale_uniform(float s) -{ - scale(s, s, s); -} - -} // namespace GL -} // namespace Msp diff --git a/source/transform.h b/source/transform.h index 35dc5631..83f190b3 100644 --- a/source/transform.h +++ b/source/transform.h @@ -5,18 +5,4 @@ Copyright © 2007 Mikko Rasa, Mikkosoft Productions Distributed under the LGPL */ -#ifndef MSP_GL_TRANSFORM_H_ -#define MSP_GL_TRANSFORM_H_ - -namespace Msp { -namespace GL { - -void translate(float, float, float); -void rotate(float, float, float, float); -void scale(float, float, float); -void scale_uniform(float); - -} // namespace GL -} // namespace Msp - -#endif +#include "matrix.h"