void drawAudioBuffer( const audio::Buffer &buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color )
{
	gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) );

	gl::color( color );

	const float waveHeight = bounds.getHeight() / (float)buffer.getNumChannels();
	const float xScale = bounds.getWidth() / (float)buffer.getNumFrames();

	float yOffset = bounds.y1;
	for( size_t ch = 0; ch < buffer.getNumChannels(); ch++ ) {
		PolyLine2f waveform;
		const float *channel = buffer.getChannel( ch );
		float x = bounds.x1;
		for( size_t i = 0; i < buffer.getNumFrames(); i++ ) {
			x += xScale;
			float y = ( 1 - ( channel[i] * 0.5f + 0.5f ) ) * waveHeight + yOffset;
			waveform.push_back( vec2( x, y ) );
		}

		if( ! waveform.getPoints().empty() )
			gl::draw( waveform );

		yOffset += waveHeight;
	}

	if( drawFrame ) {
		gl::color( color.r, color.g, color.b, color.a * 0.6f );
		gl::drawStrokedRect( bounds );
	}
}
void drawBuffer(const std::deque<int8_t>& buffer, const Rectf &bounds, bool drawFrame, const ci::ColorA &color, float scaleFactor )
{
  gl::ScopedGlslProg glslScope( getStockShader( gl::ShaderDef().color() ) );
  
  gl::color( color );
  
  const float waveHeight = bounds.getHeight();
  const float xScale = bounds.getWidth() / (float)buffer.size();
  
  float yOffset = bounds.y1;
  PolyLine2f waveform;
  float x = bounds.x1;
  for( size_t i = 0; i < buffer.size(); i++ ) {
    x += xScale;
    float y = ( 1.0f - ( buffer[i] * scaleFactor + 0.5f) ) * waveHeight + yOffset;
    waveform.push_back( vec2( x, y ) );
  }
  
  if( ! waveform.getPoints().empty() )
    gl::draw( waveform );
  
  if( drawFrame ) {
    gl::color( color.r, color.g, color.b, color.a * 0.6f );
    gl::drawStrokedRect( bounds );
  }
}
void CinderBoxFunApp::addTriangle(ConstVec &pos)
{
    PolyLine2f *points = new PolyLine2f();
    points->push_back(Vec2f(TRIANGLE_EDGE_LENGTH * 0.5f, 0));
    points->push_back(Vec2f(TRIANGLE_EDGE_LENGTH, TRIANGLE_EDGE_LENGTH));
    points->push_back(Vec2f( 0, TRIANGLE_EDGE_LENGTH));

    
    Physics::Polygon *triangle = new Physics::Polygon(pos, points);
    addBody(triangle);
}
Exemple #4
0
PolyLine2f calcConvexHull( const PolyLine2f &polyLine )
{
    polygon poly;
    for( auto ptIt = polyLine.begin(); ptIt != polyLine.end(); ++ptIt )
        poly.outer().push_back( boost::geometry::make<boost::geometry::model::d2::point_xy<double> >( ptIt->x, ptIt->y ) );

    polygon result;
    boost::geometry::convex_hull( poly, result );

    return toPolyLine<float>( result );
}
Exemple #5
0
void DeviceTestApp::draw()
{
    gl::clear();
    gl::color( 0, 0.9f, 0 );

    gl::pushMatrices();
    gl::translate( 0, mViewYOffset );

    if( mMonitor && mMonitor->isEnabled() ) {
        const audio::Buffer &buffer = mMonitor->getBuffer();

        float padding = 20;
        float waveHeight = ((float)getWindowHeight() - padding * 3.0f ) / (float)buffer.getNumChannels();

        float yOffset = padding;
        float xScale = (float)getWindowWidth() / (float)buffer.getNumFrames();
        for( size_t ch = 0; ch < buffer.getNumChannels(); ch++ ) {
            PolyLine2f waveform;
            const float *channel = buffer.getChannel( ch );
            for( size_t i = 0; i < buffer.getNumFrames(); i++ ) {
                float x = i * xScale;
                float y = ( channel[i] * 0.5f + 0.5f ) * waveHeight + yOffset;
                waveform.push_back( vec2( x, y ) );
            }
            gl::draw( waveform );
            yOffset += waveHeight + padding;
        }

        float volume = mMonitor->getVolume();
        Rectf volumeRect( mGainSlider.mBounds.x1, mGainSlider.mBounds.y2 + padding, mGainSlider.mBounds.x1 + mGainSlider.mBounds.getWidth() * volume, mGainSlider.mBounds.y2 + padding + 20 );
        gl::drawSolidRect( volumeRect );
    }

    drawWidgets( mWidgets );

    if( mInputDeviceNodeUnderrunFade > 0.0001f ) {
        gl::color( ColorA( 0.8f, 0.2f, 0, mInputDeviceNodeUnderrunFade ) );
        gl::drawSolidRect( mUnderrunRect );
        gl::drawStringCentered( "in underrun", mUnderrunRect.getCenter(), Color::black() );
    }
    if( mInputDeviceNodeOverrunFade > 0.0001f ) {
        gl::color( ColorA( 0.8f, 0.2f, 0, mInputDeviceNodeOverrunFade ) );
        gl::drawSolidRect( mOverrunRect );
        gl::drawStringCentered( "in overrun", mOverrunRect.getCenter(), Color::black() );
    }
    if( mOutputDeviceNodeClipFade > 0.0001f ) {
        gl::color( ColorA( 0.8f, 0.2f, 0, mOutputDeviceNodeClipFade ) );
        gl::drawSolidRect( mClipRect );
        gl::drawStringCentered( "out clip", mClipRect.getCenter(), Color::black() );
    }

    gl::popMatrices();
}
void auMidiApp::draw()
{
	// clear out the window with black
	gl::clear( Color( 0, 0, 0 ) );
	
	tap.getSamples(sampleBuffer);
	PolyLine2f waveform;
	for(int i = 0; i < sampleBuffer.size(); i++) {
		float x = i / (float)sampleBuffer.size() * (float)getWindowWidth();
		float y = ((sampleBuffer[i] + 1) / 2.) * (float)getWindowHeight();
		waveform.push_back(Vec2f(x,y));
	}
	
	gl::draw(waveform);
}
void HelloWorldApp::setup() {
  // We return a value from nvg::createContextGL() in order to remain
  // agnostic to how your app is managing memory. Most of the time you'll want
  // to either store this value or create a unique/shared_ptr. A unique_ptr
  // would be more appropriate here, but we're using make_shared for brevity.
  mNanoVG = std::make_shared<nvg::Context>(nvg::createContextGL());

  // Load a font
  mNanoVG->createFont("roboto", getAssetPath("Roboto-Regular.ttf").string());

  // Create triangle PolyLine
  int numPts = 3;
  for (size_t i = 0; i < numPts; ++i) {
    float u = static_cast<float>(i) / static_cast<float>(numPts);
    float t = u * M_PI * 2.0f;
    mTriangle.push_back({cosf(t), sinf(t)});
  }
  mTriangle.setClosed();
}
Exemple #8
0
void RetinaSampleApp::mouseDrag( MouseEvent event )
{
	mPoints.push_back( event.getPos() );
}
void Triangulator::addPolyLine( const PolyLine2f &polyLine )
{
	if( polyLine.size() > 0 )
		tessAddContour( mTess.get(), 2, &polyLine.getPoints()[0], sizeof(float) * 2, (int)polyLine.size() );
}