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 @ 5:75b744078d66
History | View | Annotate | Download (2.74 KB)
| 1 | 5:75b744078d66 | f | /*
|
|---|---|---|---|
| 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 | 0:02467299402e | f | #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 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 this should happen only once when resized |
||
| 68 | } |
||
| 69 | |||
| 70 | void Chunk::draw( const DrawInfo& di, ci::gl::BatchRef &batch ){ |
||
| 71 | using namespace ci; |
||
| 72 | 5:75b744078d66 | f | |
| 73 | 0:02467299402e | f | gl::pushModelMatrix(); |
| 74 | |||
| 75 | const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight(); |
||
| 76 | |||
| 77 | // place the chunk in the right position brigns 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 | // FIXME todo use max between top and bottom
|
||
| 82 | // scale according to audio amplitude
|
||
| 83 | gl::scale( 1.0f, chunkHeight ); |
||
| 84 | batch->draw(); |
||
| 85 | |||
| 86 | |||
| 87 | gl::popModelMatrix(); |
||
| 88 | } |
||
| 89 | |||
| 90 | |||
| 91 | void Chunk::drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ){ |
||
| 92 | 5:75b744078d66 | f | using namespace ci; |
| 93 | 0:02467299402e | f | |
| 94 | gl::pushModelMatrix(); |
||
| 95 | |||
| 96 | const float barHeight = di.getSelectionBarHeight(); |
||
| 97 | |||
| 98 | gl::translate( mX, di.getWaveCenterY() - ( barHeight / 2 ) - 1 ); |
||
| 99 | gl::scale( 1.0f, barHeight ); |
||
| 100 | |||
| 101 | batch->draw(); |
||
| 102 | |||
| 103 | gl::popModelMatrix(); |
||
| 104 | } |
||
| 105 | |||
| 106 | |||
| 107 | const float Chunk::kWidth = 7.0f; |
||
| 108 | 5:75b744078d66 | f | const float Chunk::kHalfWidth = 3.5f; |