To check out this repository please hg clone the following URL, or open the URL using EasyMercurial or your preferred Mercurial client.

Statistics Download as Zip
| Branch: | Tag: | Revision:

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

History | View | Annotate | Download (1.97 KB)

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