annotate CollidoscopeApp/src/Chunk.cpp @ 0:02467299402e

First import CollidoscopeApp for Raspberry Pi JackDevice Teensy code for Collidoscope
author Fiore Martin <f.martin@qmul.ac.uk>
date Thu, 30 Jun 2016 14:50:06 +0200
parents
children 75b744078d66
rev   line source
f@0 1 #include "Chunk.h"
f@0 2 #include "DrawInfo.h"
f@0 3
f@0 4
f@0 5 #include "cinder/gl/gl.h"
f@0 6
f@0 7
f@0 8 Chunk::Chunk( size_t index ) :
f@0 9 mIndex( index ),
f@0 10 mAudioTop(0.0f),
f@0 11 mAudioBottom(0.0f)
f@0 12 {}
f@0 13
f@0 14
f@0 15 void update( const DrawInfo& di )
f@0 16 {
f@0 17
f@0 18 }
f@0 19
f@0 20 void Chunk::update( const DrawInfo &di )
f@0 21 {
f@0 22 using namespace ci;
f@0 23 /* if resetting animate the chunks to shrink to 0 size */
f@0 24 if ( mResetting ){
f@0 25 if ( mAnimate > 0.0f ){
f@0 26 mAnimate -= 0.1f;
f@0 27 if ( mAnimate <= 0.0f ){
f@0 28 mAnimate = 0.0f;
f@0 29 mResetting = false;
f@0 30 mAudioTop = 0.0f;
f@0 31 mAudioBottom = 0.0f;
f@0 32 }
f@0 33 }
f@0 34 }
f@0 35 /* animate makes the chunks pop nicely when they are created */
f@0 36 else if ( mAnimate < 1.0f ){
f@0 37 mAnimate += 0.3333f; // in three (namely 1/0.333) steps
f@0 38 if ( mAnimate > 1.0f ){ // clip to one
f@0 39 mAnimate = 1.0f;
f@0 40 }
f@0 41 }
f@0 42
f@0 43 mX = di.flipX( 1 + (mIndex * (2 + kWidth)) ); // FIXME this should happen only once when resized
f@0 44 }
f@0 45
f@0 46 void Chunk::draw( const DrawInfo& di, ci::gl::BatchRef &batch ){
f@0 47 using namespace ci;
f@0 48
f@0 49 gl::pushModelMatrix();
f@0 50
f@0 51 const float chunkHeight = mAnimate * mAudioTop * di.getMaxChunkHeight();
f@0 52
f@0 53 // place the chunk in the right position brigns back the y of chunkHeight/2 so
f@0 54 // so that after scaling the wave is still centered at the wave center
f@0 55 gl::translate( mX, di.getWaveCenterY() - ( chunkHeight / 2 ) - 1 );
f@0 56
f@0 57 // FIXME todo use max between top and bottom
f@0 58 // scale according to audio amplitude
f@0 59 gl::scale( 1.0f, chunkHeight );
f@0 60 batch->draw();
f@0 61
f@0 62
f@0 63 gl::popModelMatrix();
f@0 64 }
f@0 65
f@0 66
f@0 67 void Chunk::drawBar( const DrawInfo& di, ci::gl::BatchRef &batch ){
f@0 68 using namespace ci;
f@0 69
f@0 70 gl::pushModelMatrix();
f@0 71
f@0 72 const float barHeight = di.getSelectionBarHeight();
f@0 73
f@0 74 gl::translate( mX, di.getWaveCenterY() - ( barHeight / 2 ) - 1 );
f@0 75 gl::scale( 1.0f, barHeight );
f@0 76
f@0 77 batch->draw();
f@0 78
f@0 79 gl::popModelMatrix();
f@0 80 }
f@0 81
f@0 82
f@0 83 const float Chunk::kWidth = 7.0f;
f@0 84 const float Chunk::kHalfWidth = 3.5f;