|
From: Tapio V. <aa...@us...> - 2010-01-19 20:35:57
|
Module: performous
Branch: master
Commit: b912f6ca65a8dad51a770bcdfda13e667056428c
Author: Tapio Vierros <tap...@gm...>
Date: Tue Jan 19 22:22:05 2010 +0200
Get rid of auto-reversing matrix operations in favor of PushMatrix.
---
game/3dobject.hh | 3 +--
game/dancegraph.cc | 9 ++++-----
game/glutil.hh | 27 ---------------------------
game/guitargraph.cc | 20 +++++++-------------
game/notegraph.cc | 5 +++--
5 files changed, 15 insertions(+), 49 deletions(-)
diff --git a/game/3dobject.hh b/game/3dobject.hh
index 11f3840..ecb7b56 100644
--- a/game/3dobject.hh
+++ b/game/3dobject.hh
@@ -64,13 +64,12 @@ class Object3d: boost::noncopyable {
}
/// draws the object
void draw(float x = 0, float y = 0, float z = 0, float s = 1.0) const {
+ glutil::PushMatrix pm;
glTranslatef(x, y, z);
if (s != 1.0) glScalef(s,s,s);
if (m_texture) {
UseTexture tex(*m_texture);
glCallList(m_displist);
} else glCallList(m_displist);
- if (s != 1.0) { float ss = 1.0/s; glScalef(ss,ss,ss); }
- glTranslatef(-x, -y, -z);
}
};
diff --git a/game/dancegraph.cc b/game/dancegraph.cc
index baa27e1..3192726 100644
--- a/game/dancegraph.cc
+++ b/game/dancegraph.cc
@@ -313,7 +313,8 @@ namespace {
/// Draw a dance pad icon using the given texture
void DanceGraph::drawArrow(int arrow_i, Texture& tex, float x, float y, float scale, float ty1, float ty2) {
- glutil::Translation tr(x, y, 0.0f);
+ glutil::PushMatrix pm;
+ glTranslatef(x, y, 0.0f);
if (scale != 1.0f) glScalef(scale, scale, scale);
{
UseTexture tblock(tex);
@@ -321,17 +322,15 @@ void DanceGraph::drawArrow(int arrow_i, Texture& tex, float x, float y, float sc
vertexPair(arrow_i, 0.0f, -arrowSize, ty1);
vertexPair(arrow_i, 0.0f, arrowSize, ty2);
}
- if (scale != 1.0f) glScalef(1.0f/scale, 1.0f/scale, 1.0f/scale);
}
/// Draw a mine note
void DanceGraph::drawMine(float x, float y, float rot, float scale) {
- glutil::Translation tr(x, y, 0.0f);
+ glutil::PushMatrix pm;
+ glTranslatef(x, y, 0.0f);
if (scale != 1.0f) glScalef(scale, scale, scale);
if (rot != 0.0f) glRotatef(rot, 0.0f, 0.0f, 1.0f);
m_mine.draw();
- if (rot != 0.0f) glRotatef(-rot, 0.0f, 0.0f, 1.0f);
- if (scale != 1.0f) glScalef(1.0f/scale, 1.0f/scale, 1.0f/scale);
}
/// Draws the dance graph
diff --git a/game/glutil.hh b/game/glutil.hh
index 2d20d83..ad7f309 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -56,33 +56,6 @@ namespace glutil {
}
};
- /// auto-reversing translation
- struct Translation {
- Translation(float _x, float _y, float _z = 0.0f): m_x(_x), m_y(_y), m_z(_z)
- { glTranslatef(m_x, m_y, m_z); }
- ~Translation() { glTranslatef(-m_x, -m_y, -m_z); }
- private:
- float m_x, m_y, m_z;
- };
-
- /// auto-reversing rotation
- struct Rotation {
- Rotation(float _a, float _x, float _y, float _z): m_a(_a), m_x(_x), m_y(_y), m_z(_z)
- { glRotatef(m_a, m_x, m_y, m_z); }
- ~Rotation() { glRotatef(-m_a, m_x, m_y, m_z); }
- private:
- float m_a, m_x, m_y, m_z;
- };
-
- /// auto-reversing scaling
- struct Scale {
- Scale(float _x, float _y, float _z): m_x(_x), m_y(_y), m_z(_z)
- { glScalef(m_x, m_y, m_z); }
- ~Scale() { glScalef(1.0/m_x, 1.0/m_y, 1.0/m_z); }
- private:
- float m_x, m_y, m_z;
- };
-
/// struct to store color information
struct Color {
float r, ///< red component
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 9cc0163..150805d 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -492,14 +492,13 @@ void GuitarGraph::draw(double time) {
float ng_r = 0, ng_g = 0, ng_b = 0; // neck glow color components
int ng_ccnt = 0; // neck glow color count
{ // Translate, rotate and scale to place
- // The scope blocks are there so that the actions are automatically reversed
- glutil::PushMatrixMode pmm(GL_PROJECTION); {
- glutil::Translation tr1(frac * 2.0 * offsetX, 0.0f, 0.0f); {
- glutil::PushMatrixMode pmb(GL_MODELVIEW); {
- glutil::Translation tr2((1.0 - frac) * offsetX, dimensions.y2(), 0.0f); {
- glutil::Rotation rot1(g_angle, 1.0f, 0.0f, 0.0f); {
+ glutil::PushMatrixMode pmm(GL_PROJECTION);
+ glTranslatef(frac * 2.0 * offsetX, 0.0f, 0.0f);
+ glutil::PushMatrixMode pmb(GL_MODELVIEW);
+ glTranslatef((1.0 - frac) * offsetX, dimensions.y2(), 0.0f);
+ glRotatef(g_angle, 1.0f, 0.0f, 0.0f);
float temp_s = dimensions.w() / 5.0f;
- glutil::Scale sc1(temp_s, temp_s, temp_s);
+ glScalef(temp_s, temp_s, temp_s);
// Draw the neck
{
@@ -606,12 +605,7 @@ void GuitarGraph::draw(double time) {
++it;
}
}
- } //< reverse scale sc1
- } //< reverse rot rot1
- } //< reverse trans tr2
- } //< reverse push pmb
- } //< reverse trans tr1
- } //< reverse push pmm
+ }
// Bottom neck glow
if (ng_ccnt > 0) {
diff --git a/game/notegraph.cc b/game/notegraph.cc
index c9afd9c..7ae5fad 100644
--- a/game/notegraph.cc
+++ b/game/notegraph.cc
@@ -114,8 +114,9 @@ void NoteGraph::draw(double time, Database const& database, Position position) {
float centerx = x + w - 1.2 * hh; // Star is 1.2 units from end
float rot = fmod(time * 360, 360); // They rotate!
float zoom = (std::abs((rot-180) / 360.0f) * 0.8f + 0.6f) * (position == NoteGraph::TOP ? 2.3 : 2.0) * hh;
- glutil::Translation tr(centerx, centery);
- glutil::Rotation rt(rot, 0.0f, 0.0f, 1.0f);
+ glutil::PushMatrix pm;
+ glTranslatef(centerx, centery, 0.0f);
+ glRotatef(rot, 0.0f, 0.0f, 1.0f);
m_star.draw(Dimensions().stretch(zoom, zoom).center().middle(), TexCoords());
}
|