To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.
root / CollidoscopeApp / src / Chunk.cpp @ 18:f1ff1a81be20
History | View | Annotate | Download (2.71 KB)
| 1 |
/*
|
|---|---|
| 2 |
|
| 3 |
Copyright (C) 2015 Fiore Martin
|
| 4 |
Copyright (C) 2016 Queen Mary University of London
|
| 5 |
Author: Fiore Martin
|
| 6 |
|
| 7 |
This file is part of Collidoscope.
|
| 8 |
|
| 9 |
Collidoscope is free software: you can redistribute it and/or modify
|
| 10 |
it under the terms of the GNU General Public License as published by
|
| 11 |
the Free Software Foundation, either version 3 of the License, or
|
| 12 |
(at your option) any later version.
|
| 13 |
|
| 14 |
This program is distributed in the hope that it will be useful,
|
| 15 |
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
| 16 |
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
| 17 |
GNU General Public License for more details.
|
| 18 |
|
| 19 |
You should have received a copy of the GNU General Public License
|
| 20 |
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
| 21 |
|
| 22 |
*/
|
| 23 |
|
| 24 |
|
| 25 |
#include "Chunk.h" |
| 26 |
#include "DrawInfo.h" |
| 27 |
|
| 28 |
|
| 29 |
#include "cinder/gl/gl.h" |
| 30 |
|
| 31 |
|
| 32 |
Chunk::Chunk( size_t index ) : |
| 33 |
mIndex( index ), |
| 34 |
mAudioTop(0.0f), |
| 35 |
mAudioBottom(0.0f) |
| 36 |
{}
|
| 37 |
|
| 38 |
|
| 39 |
void update( const DrawInfo& di ) |
| 40 |
{
|
| 41 |
|
| 42 |
} |
| 43 |
|
| 44 |
void Chunk::update( const DrawInfo &di ) |
| 45 |
{
|
| 46 |
using namespace ci; |
| 47 |
/* if resetting animate the chunks to nicely shrink to 0 size */
|
| 48 |
if ( mResetting ){
|
| 49 |
if ( mAnimate > 0.0f ){ |
| 50 |
mAnimate -= 0.1f; |
| 51 |
if ( mAnimate <= 0.0f ){ |
| 52 |
mAnimate = 0.0f; |
| 53 |
mResetting = false;
|
| 54 |
mAudioTop = 0.0f; |
| 55 |
mAudioBottom = 0.0f; |
| 56 |
} |
| 57 |
} |
| 58 |
} |
| 59 |
/* animate makes the chunks pop nicely when they are created */
|
| 60 |
else if ( mAnimate < 1.0f ){ |
| 61 |
mAnimate += 0.3333f; // in three (namely 1/0.333) steps |
| 62 |
if ( mAnimate > 1.0f ){ // clip to one |
| 63 |
mAnimate = 1.0f; |
| 64 |
} |
| 65 |
} |
| 66 |
|
| 67 |
mX = di.flipX( 1 + (mIndex * (2 + kWidth)) ); // FIXME more efficient if it happens only once when resized |
| 68 |
} |
| 69 |
|
| 70 |
void Chunk::draw( const DrawInfo& di, ci::gl::BatchRef &batch ){ |
| 71 |
using namespace ci; |
| 72 |
|
| 73 |
gl::pushModelMatrix(); |
| 74 |
|
| 75 |
const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight(); |
| 76 |
|
| 77 |
// place the chunk in the right position brings back the y of chunkHeight/2 so
|
| 78 |
// so that after scaling the wave is still centered at the wave center
|
| 79 |
gl::translate( mX, di.getWaveCenterY() - ( chunkHeight / 2 ) - 1 ); |
| 80 |
|
| 81 |
// scale according to audio amplitude
|
| 82 |
gl::scale( 1.0f, chunkHeight ); |
| 83 |
batch->draw(); |
| 84 |
|
| 85 |
|
| 86 |
gl::popModelMatrix(); |
| 87 |
} |
| 88 |
|
| 89 |
|
| 90 |
void Chunk::drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ){ |
| 91 |
using namespace ci; |
| 92 |
|
| 93 |
gl::pushModelMatrix(); |
| 94 |
|
| 95 |
const float barHeight = di.getSelectionBarHeight(); |
| 96 |
|
| 97 |
gl::translate( mX, di.getWaveCenterY() - ( barHeight / 2 ) - 1 ); |
| 98 |
gl::scale( 1.0f, barHeight ); |
| 99 |
|
| 100 |
batch->draw(); |
| 101 |
|
| 102 |
gl::popModelMatrix(); |
| 103 |
} |
| 104 |
|
| 105 |
|
| 106 |
const float Chunk::kWidth = 7.0f; |
| 107 |
const float Chunk::kHalfWidth = 3.5f; |