|
From: Tapio V. <aa...@us...> - 2009-12-11 12:43:47
|
Module: performous
Branch: dance
Commit: a3d822fb5a6e2f634babf8d4623a6fb388810bbe
Author: Tapio Vierros <tap...@gm...>
Date: Tue Dec 1 14:11:19 2009 +0200
Some new glutils.
---
game/glutil.hh | 27 +++++++++++++++++++++++++++
game/guitargraph.cc | 26 +++++++++++++-------------
2 files changed, 40 insertions(+), 13 deletions(-)
diff --git a/game/glutil.hh b/game/glutil.hh
index ad7f309..2d20d83 100644
--- a/game/glutil.hh
+++ b/game/glutil.hh
@@ -56,6 +56,33 @@ 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 663d3c8..b95092d 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -428,13 +428,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
{
- 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 s = dimensions.w() / 5.0f; glScalef(s, s, s); }
+ 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); {
+ float temp_s = dimensions.w() / 5.0f;
+ glutil::Scale sc1(temp_s, temp_s, temp_s);
// Draw the neck
{
UseTexture tex(*m_neck);
@@ -499,12 +499,12 @@ void GuitarGraph::draw(double time) {
drawNote(fret, c, tBeg, tEnd, whammy, it->tappable);
}
}
- glRotatef(-g_angle, 1.0f, 0.0f, 0.0f);
- glTranslatef(-(1.0 - frac) * offsetX, -dimensions.y2(), 0.0f);
- glScalef(5.0f, 5.0f, 5.0f);
- }
- glTranslatef(-frac * 2.0 * offsetX, 0.0f, 0.0f);
- }
+ } // 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) {
if (m_neckglowColor.r > 0 || m_neckglowColor.g > 0 || m_neckglowColor.b > 0) {
|