//*************************************************************************
void BeatDetectorApp::NextFile()
{
	roto = 0;
	if(mTrack && mTrack->isPlaying())
	{
		mTrack->enablePcmBuffering(false);
		mTrack->stop();
	}

#ifdef WIN32
	time_t now;
	time(&now);
	int time_int = (int)now;
#else
	timeval now;
	gettimeofday(&now, NULL);
	int time_int = now.tv_sec;
#endif

	Rand r;
	r.seed(time_int);
	int rand_file = r.nextInt(m_FileList.size());
	path my_path = m_FileList[rand_file].path();
	m_CurrentFile = my_path.string();
	
	if(!write_frames)
	{
		mAudioSource = audio::load(m_CurrentFile);
		mTrack = audio::Output::addTrack(mAudioSource, false);
		mTrack->enablePcmBuffering(true);
		mTrack->play();		
	}
	//rot_inc = r.nextFloat(1.5f, 30.0f);
}
void Example4App::setup()
{
    gl::clear( Color( 1, 1, 1 ) );
    gl::enableAlphaBlending();
    
    generator_.seed(randInt());
    app::setWindowSize(600, 200);
    mean_ = getWindowWidth() / 2;
}
示例#3
0
void CristalWaveApp::setup()
{
	float sizeW = getWindowWidth() * 0.5f;
	float sizeH = getWindowHeight() * 0.5f;
	float	x = 0.0f,
			z = 0.0f,
			y = 0.0f;

	/////////////////////////////////////////////////
	int numRows = PARAM_WAVE_NB_ROWS;
	int gap = PARAM_WAVE_GAP + getWindowWidth() / 2000;
	int numLines = getWindowWidth() / gap + 1;
	/////////////////////////////////////////////////

	mOpacity = 0.0f;
	mOffsetCameratH = 60; // Global amplitude

	// Init BackgroundLayer
	mBackground.setup(getWindowWidth(), getWindowHeight(), mOffsetCameratH);

	// Init Wave Model
	mWave.setup(getWindowWidth(), getWindowHeight(), numRows, numLines, -mOffsetCameratH);

	// set a random offset
	Rand rnd;
	rnd.seed((unsigned long)GetTickCount());
	mOffsetTime = rnd.nextFloat(0.0f, 100.0f);

	// Set the Shader program
	mFresnelShader.load();
	mpWaveShader = &mFresnelShader;
	mWave.setShader(mpWaveShader);

	// --------------------------------------------------------
	// Set Particule manager
	int nbParticule = PARAM_NB_PARTICULES;
	mEmitter.radius = PARAM_EMITTER_RADIUS;

	mParticuleInTheWindManager.attrPosition = Vec3f::zero();
	mParticuleInTheWindManager.attrFactor = PARAM_FORCE_FACTOR;

	ParticuleManager::PARTICULE_LIFE particule_life;
	particule_life.minTTL = 0.5f;
	particule_life.maxTTL = 3.5f;
	particule_life.minTTH = 1.0f;
	particule_life.minTTH = 4.0f;
	mParticuleInTheWindManager.init(nbParticule, particule_life, getWindowWidth());
}
void MPEBouncingBallApp::mpeReset()
{
    console() << "RESETTING\n";

    // Set the random seed to a known value so all of the clients are using the same rand values.
    mRand.seed(1);

    // Clear out the previous state
    mServerFramesProcessed = 0;
    mBalls.clear();

    // Add the first ball
    ivec2 sizeMaster = mClient->getMasterSize();
    addBallAtPosition(vec2(mRand.nextFloat(sizeMaster.x), mRand.nextFloat(sizeMaster.y)));
    
    if (mClient->isAsynchronousClient())
    {
        send3DSettings();
    }
}
void P_2_1_3_01App::draw()
{
	// clear out the window with black
	gl::clear( Color( 1, 1, 1 ) );
    
    gl::color(0, 0, 0, 0.5f);
    
    mRand.seed(mRandomSeed);
    
    gl::pushMatrices();
    gl::translate(mTileWidth / 2.0f, mTileHeight / 2.0f);
    
    mCircleCount = mMousePos.x / 30.0f + 1.0f;
    
    mEndSize = lmap(float(mMousePos.x), 0.0f, float(getWindowWidth()), mTileWidth / 2.0f, 0.0f);
    mEndOffset = lmap(float(mMousePos.y), 0.0f, float(getWindowHeight()), 0.0f, (mTileWidth - mEndSize)/2.0f);
    
    for (int gridY = 0; gridY <= mTileCountY; gridY++) {
        for (int gridX = 0; gridX <= mTileCountX; gridX++) {
            gl::pushMatrices();
            gl::translate(mTileWidth * gridX, mTileHeight * gridY);
            gl::scale(Vec2f(1.0f, mTileHeight / mTileWidth));
            
            int toggle = mRand.nextInt(4);
            if (toggle == 0) gl::rotate(-90.0f);
            if (toggle == 1) gl::rotate(0.0f);
            if (toggle == 2) gl::rotate(90.0f);
            if (toggle == 3) gl::rotate(180.0f);
            
            for (int i = 0; i < mCircleCount; i++) {
                float diameter = lmap(float(i), 0.0f, mCircleCount - 1.0f, mTileWidth, mEndSize);
                float offset = lmap(float(i), 0.0f, mCircleCount - 1.0f, 0.0f, mEndOffset);
                gl::drawStrokedCircle(Vec2f(offset, 0.0f), diameter / 2.0f);
            }
            
            gl::popMatrices();
        }
    }
    
    gl::popMatrices();
}
示例#6
0
MyCircle::MyCircle(int x, int y, int radius){
	this->x_ = x;
	this->y_ = y;
	this->child_ = NULL;
	this->anchor_x_ = x;
	this->anchor_y_ = y;
	this->bound_ = 0;
	this->alpha_level_ = 0;

	//make sure the radius isn't too large
	if(radius > 100)
		this->radius_ = 100;
	else
		this->radius_ = radius;

	//make the shape a random color:
	Rand random;
	random.seed(x*y);
	this->color_ = Color8u(random.nextInt(0,256),
		random.nextInt(0,256),random.nextInt(0,256));

	this->work_color_ = color_;
}
void StereoscopicRenderingApp::render()
{	
	float seconds = (float) getElapsedSeconds();

	// enable 3D rendering
	gl::enableDepthRead();
	gl::enableDepthWrite();

	// set 3D camera matrices
	gl::pushMatrices();
	gl::setMatrices( mCamera );

	if( mShaderPhong && mMeshTrombone && mMeshNote ) {
		// enable phong shading
		mShaderPhong.bind();	
		
		// draw trombone
		gl::pushModelView();
		{
			gl::color( Color(0.7f, 0.6f, 0.0f) );
			gl::rotate( Vec3f::yAxis() * 10.0f * seconds );
			gl::draw( mMeshTrombone );

			// reflection
			gl::scale( 1.0f, -1.0f, 1.0f );
			gl::draw( mMeshTrombone );
		}
		gl::popModelView();	

		// draw animated notes
		Rand rnd;
		for(int i=-100; i<=100; ++i) {
			rnd.seed(i);

			float t = rnd.nextFloat() * 200.0f + 2.0f * seconds;
			float r = rnd.nextFloat() * 360.0f + 60.0f * seconds;
			float z = fmodf( 5.0f * t, 200.0f ) - 100.0f;		

			gl::pushModelView();
			{
				gl::color( Color( CM_HSV, rnd.nextFloat(), 1.0f, 1.0f ) );

				gl::pushModelView();
				gl::translate( i * 0.5f, 0.15f + 1.0f * math<float>::abs( sinf(3.0f * t) ), -z );
				gl::rotate( Vec3f::yAxis() * r );
				gl::draw( mMeshNote );
				gl::popModelView();
				
				// reflection
				gl::pushModelView();
				gl::scale( 1.0f, -1.0f, 1.0f );
				gl::translate( i * 0.5f, 0.15f + 1.0f * math<float>::abs( sinf(3.0f * t) ), -z );
				gl::rotate( Vec3f::yAxis() * r );
				gl::draw( mMeshNote );
				gl::popModelView();
			}
			gl::popModelView();
		}

		mShaderPhong.unbind();
	}

	// draw grid
	gl::color( Color(0.8f, 0.8f, 0.8f) );
	for(int i=-100; i<=100; ++i) {
		gl::drawLine( Vec3f((float) i, 0, -100), Vec3f((float) i, 0, 100) );
		gl::drawLine( Vec3f(-100, 0, (float) i), Vec3f(100, 0, (float) i) );
	}

	// draw floor
	gl::enableAlphaBlending();
	gl::color( ColorA(1,1,1,0.75f) );
	gl::drawCube( Vec3f(0.0f, -0.5f, 0.0f), Vec3f(200.0f, 1.0f, 200.0f) );
	gl::disableAlphaBlending();

	// restore 2D rendering
	gl::popMatrices();
	gl::disableDepthWrite();
	gl::disableDepthRead();

	// render UI
	if( mDrawUI ) renderUI();
}