|
From: Tapio V. <aa...@us...> - 2009-10-27 20:00:42
|
Module: performous
Branch: master
Commit: c6b7c94d3950f4748b3e60f6ae11cbc2d90ab302
Author: Tapio Vierros <tap...@gm...>
Date: Tue Oct 27 21:57:08 2009 +0200
Simple graphical effect for guitar's whammy bar (use with hold notes).
Keyboard binding is backspace.
---
game/guitargraph.cc | 27 ++++++++++++++++++++++-----
game/guitargraph.hh | 5 +++--
game/joystick.cc | 25 +++++++++++++++++++++++--
game/joystick.hh | 2 +-
4 files changed, 49 insertions(+), 10 deletions(-)
diff --git a/game/guitargraph.cc b/game/guitargraph.cc
index 93fac15..f8dfc74 100644
--- a/game/guitargraph.cc
+++ b/game/guitargraph.cc
@@ -104,12 +104,14 @@ void GuitarGraph::engine() {
if (m_input.pressed(i)) m_hit[i + 1].setValue(1.0);
}
}
+ double whammy = 0;
// Handle all events
for (input::Event ev; m_input.tryPoll(ev);) {
m_dead = false;
if (!m_drums && ev.type == input::Event::RELEASE) {
endHold(ev.button);
}
+ if (!m_drums && ev.type == input::Event::WHAMMY) whammy = (1.0 + ev.button) / 2.0;
if (ev.type == input::Event::PRESS) m_hit[!m_drums + ev.button].setValue(1.0);
else if (ev.type == input::Event::PICK) m_hit[0].setValue(1.0);
if (time < -0.5) {
@@ -154,6 +156,11 @@ void GuitarGraph::engine() {
if (!m_holds[fret]) continue;
Event& ev = m_events[m_holds[fret] - 1];
ev.glow.setTarget(1.0, true);
+ ev.whammy.setTarget(whammy);
+ if (whammy > 0) {
+ ev.whammy.move(0.5);
+ if (ev.whammy.get() > 1.0) ev.whammy.setValue(1.0);
+ }
double last = std::min(time, ev.dur->end);
double t = last - ev.holdTime;
if (t > 0) {
@@ -168,6 +175,7 @@ void GuitarGraph::engine() {
void GuitarGraph::endHold(int fret) {
if (!m_holds[fret]) return;
m_events[m_holds[fret] - 1].glow.setTarget(0.0);
+ m_events[m_holds[fret] - 1].whammy.setTarget(0.0, true);
m_holds[fret] = 0;
}
@@ -384,7 +392,11 @@ void GuitarGraph::draw(double time) {
//drawNote(fret, color(fret), tBeg, tEnd);
unsigned event = m_notes[it->dur[fret]];
float glow = 0.0f;
- if (event > 0) glow = m_events[event - 1].glow.get();
+ float whammy = 0.0f;
+ if (event > 0) {
+ glow = m_events[event - 1].glow.get();
+ whammy = m_events[event - 1].whammy.get();
+ }
/*
if (glow > 0.0f) {
glBlendFunc(GL_ONE, GL_ONE);
@@ -396,7 +408,7 @@ void GuitarGraph::draw(double time) {
c.r += glow;
c.g += glow;
c.b += glow;
- drawNote(fret, c, tBeg, tEnd);
+ drawNote(fret, c, tBeg, tEnd, whammy);
if (it->tappable) {
float l = std::max(0.5, m_correctness.get());
@@ -434,7 +446,7 @@ namespace {
}
}
-void GuitarGraph::drawNote(int fret, glutil::Color c, float tBeg, float tEnd) {
+void GuitarGraph::drawNote(int fret, glutil::Color c, float tBeg, float tEnd, float whammy) {
float x = -2.0f + fret;
if (m_drums) x -= 0.5f;
if (m_drums && fret == 0) {
@@ -454,8 +466,13 @@ void GuitarGraph::drawNote(int fret, glutil::Color c, float tBeg, float tEnd) {
y -= 2 * fretWid;
vertexPair(x, y, c, 0.5f);
// Render the middle
- while ((y -= 10.0) > yEnd + fretWid) {
- vertexPair(x, y, c, 0.5f);
+ while ((y -= fretWid) > yEnd + fretWid) {
+ if (whammy < 0.1) {
+ vertexPair(x, y, c, 0.5f);
+ } else {
+ // The sin formula is pure magic
+ vertexPair(x+sin((whammy-0.75)*6.0 + (yBeg-tEnd)/y)/3.0, y, c, 0.5f);
+ }
}
// Render the end
y = yEnd + fretWid;
diff --git a/game/guitargraph.hh b/game/guitargraph.hh
index 288aed4..e0c007b 100644
--- a/game/guitargraph.hh
+++ b/game/guitargraph.hh
@@ -84,11 +84,12 @@ class GuitarGraph {
struct Event {
double time;
AnimValue glow;
+ AnimValue whammy;
int type; // 0 = miss (pick), 1 = tap, 2 = pick
int fret;
Duration const* dur;
double holdTime;
- Event(double t, int ty, int f = -1, Duration const* d = NULL): time(t), glow(0.0, 5.0), type(ty), fret(f), dur(d), holdTime(d ? d->begin : getNaN()) { if (type > 0) glow.setValue(1.0); }
+ Event(double t, int ty, int f = -1, Duration const* d = NULL): time(t), glow(0.0, 5.0), whammy(0.0, 0.4), type(ty), fret(f), dur(d), holdTime(d ? d->begin : getNaN()) { if (type > 0) glow.setValue(1.0); }
};
typedef std::vector<Event> Events;
Events m_events;
@@ -96,7 +97,7 @@ class GuitarGraph {
int m_dead;
glutil::Color const& color(int fret) const;
void drawBar(double time, float h);
- void drawNote(int fret, glutil::Color, float tBeg, float tEnd);
+ void drawNote(int fret, glutil::Color, float tBeg, float tEnd, float whammy = 0);
void difficultyAuto();
bool difficulty(Difficulty level);
SvgTxtTheme m_text;
diff --git a/game/joystick.cc b/game/joystick.cc
index d79396e..afbca00 100644
--- a/game/joystick.cc
+++ b/game/joystick.cc
@@ -198,6 +198,14 @@ bool input::SDL::pushEvent(SDL_Event _e) {
}
devices[joy_id].addEvent(event);
return true;
+ case SDLK_BACKSPACE:
+ event.type = input::Event::WHAMMY;
+ event.button = 1;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ devices[joy_id].addEvent(event);
+ return true;
case SDLK_F5: case SDLK_5:
button++;
case SDLK_F4: case SDLK_4:
@@ -229,6 +237,14 @@ bool input::SDL::pushEvent(SDL_Event _e) {
switch(_e.key.keysym.sym) {
case SDLK_RETURN: pickPressed[0] = false; return true;
case SDLK_RSHIFT: pickPressed[1] = false; return true;
+ case SDLK_BACKSPACE:
+ event.type = input::Event::WHAMMY;
+ event.button = 0;
+ for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
+ event.pressed[i] = devices[joy_id].pressed(i);
+ }
+ devices[joy_id].addEvent(event);
+ return true;
case SDLK_F5: case SDLK_5:
button++;
case SDLK_F4: case SDLK_4:
@@ -254,8 +270,13 @@ bool input::SDL::pushEvent(SDL_Event _e) {
case SDL_JOYAXISMOTION:
joy_id = _e.jaxis.which;
if(!devices[joy_id].assigned()) return false;
- if (_e.jaxis.axis != 5 && _e.jaxis.axis != 6) return false;
- event.type = input::Event::PICK;
+ if (_e.jaxis.axis == 5 || _e.jaxis.axis == 6) {
+ event.type = input::Event::PICK;
+ } else if (_e.jaxis.axis == 2) {
+ event.type = input::Event::WHAMMY;
+ } else {
+ return false;
+ }
for( unsigned int i = 0 ; i < BUTTONS ; ++i ) {
event.pressed[i] = devices[joy_id].pressed(i);
}
diff --git a/game/joystick.hh b/game/joystick.hh
index 7499232..f3ee06b 100644
--- a/game/joystick.hh
+++ b/game/joystick.hh
@@ -21,7 +21,7 @@ namespace input {
static const std::size_t BUTTONS = 6;
struct Event {
- enum Type { PRESS, RELEASE, PICK };
+ enum Type { PRESS, RELEASE, PICK, WHAMMY };
Type type;
int button; // Translated button number for press/release events. 0 for pick down, 1 for pick up (NOTE: these are NOT pick press/release events but rather different directions)
bool pressed[BUTTONS]; // All events tell the button state right after the event happened
|