当前位置: 首页>>代码示例>>C++>>正文


C++ Rand::nextFloat方法代码示例

本文整理汇总了C++中Rand::nextFloat方法的典型用法代码示例。如果您正苦于以下问题:C++ Rand::nextFloat方法的具体用法?C++ Rand::nextFloat怎么用?C++ Rand::nextFloat使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在Rand的用法示例。


在下文中一共展示了Rand::nextFloat方法的10个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。

示例1: position

Particle::Particle( const Vec2f& origin, Rand& r )
: position( origin ),
  lifespan( 1.0f ),
  velocity( r.nextFloat( -1.0f, 1.0f ), r.nextFloat( -1.0f, 1.0f ) ),
  acceleration( 0.0f, r.nextFloat( 0.01f, 0.03f ) ),
  aging( r.nextFloat( ( 1.0f / 64 ), ( 1.0f / 128 ) ) ),
  sizeRadius( r.nextFloat( 3.0f, 9.0f ) )
{ }
开发者ID:ilzxc,项目名称:The-Nature-of-Cinder,代码行数:8,代码来源:Particle.cpp

示例2: loseScore

	void loseScore(Vec2f impact, int num)
	{
		vel -= impact;
		
		closestPlanet = 0;
		
		for(int i = 0; i < num; i++)
			losing.push_back(new Particle(pos, Vec2f(rand->nextFloat(20.5f), rand->nextFloat(20.5f)), 5.0f, color));
	}
开发者ID:pholz,项目名称:grav,代码行数:9,代码来源:gravApp.cpp

示例3:

	Particle(vector<Tile*> *_tiles, Tile *_tile, Vec2f _pos, float _lifetime, Rand* _r)
	{
		tiles = _tiles;
		tile = _tile;
		lifetime = _lifetime;
		pos = _pos;
		expired = .0f;
		rand = _r;
		vel = Vec2f(rand->nextFloat(-PSPEED, PSPEED), rand->nextFloat(-PSPEED, PSPEED));
	}
开发者ID:pholz,项目名称:hex,代码行数:10,代码来源:hexApp.cpp

示例4: update

	void update(float dt)
	{
		Vec2f newpos = pos + vel;
		
		if(insidePolygon(newpos - tile->pos, (*tile->hex)))
		{
			pos = newpos;
			
		}
		else 
		{
			Vec2f newpos2 = pos + vel * 15.0f;
			
			Vec2f exitdir = newpos2 - tile->pos;
			
			bool wander = false;
			vector<Tile*>::iterator tileit;
			
			int idx = Tile::getIndexForAngle(math<float>::atan2(exitdir.x, exitdir.y));
			console() << idx << endl;
			
			for(tileit = tiles->begin(); tileit < tiles->end(); tileit++)
			{
				if(insidePolygon(newpos2 - (*tileit)->pos, *(*tileit)->hex) &&
				   tile->connections[idx] &&
				   !tile->state[idx] &&
				   !(*tileit)->state[(idx+3) % 6])
				{
					pos = newpos;
					wander = true;
					tile = tile->connections[idx];
				}
			}

			if(!wander)
			{
				Rand r;
				vel = Vec2f(rand->nextFloat(-PSPEED, PSPEED), rand->nextFloat(-PSPEED, PSPEED));
			}
		}
		
		
		expired += dt;
	}
开发者ID:pholz,项目名称:hex,代码行数:44,代码来源:hexApp.cpp

示例5: setup

void RendererTestApp::setup()
{
  mRenderFunctions = {
    { "Batch 2d", [=](){ mRenderer2dStrip.update(); mRenderer2dStrip.render(); } },
    { "VBO 2d", [=](){ mRenderer2dStripVbo.update(); mRenderer2dStripVbo.render(); } },
    { "Simple", [=](){ mSimpleRenderer.render(); } },
    { "Batch 2d (no updates)", [=](){ mRenderer2dStrip.render(); } },
    { "VBO 2d (no updates)", [=](){ mRenderer2dStripVbo.render(); } },
  };
  mRenderFn = mRenderFunctions.begin();
  gl::enableVerticalSync();

  Rand r;
  for( auto &box : mBoxes )
  {
    box.setColor( ColorA{ CM_HSV, r.nextFloat( 1.0f ), 0.9f, 0.9f, 1.0f } );
    box.setPos( Vec2f{ r.nextFloat(getWindowWidth()), r.nextFloat(getWindowHeight()) } );
    box.setRotation( r.nextFloat( M_PI * 2 ) );
    mRenderer2dStrip.add( &box );
    mSimpleRenderer.add( &box );
    mRenderer2dStripVbo.add( &box );
  }

  // We perform the cast since we know what type of things we stored in each renderer
  // A type-safe way could be to assign y to each objects layer and then sort by layer
  Vec2f center = getWindowCenter();
  auto vortex_simple = [center]( const SimpleRenderer::Renderable *lhs, const SimpleRenderer::Renderable *rhs )
  {
    return static_cast<const Box*>( lhs )->getPos().distance(center) <
    static_cast<const Box*>( rhs )->getPos().distance(center);
  };
  auto vortex_triangle = [center]( const BatchRenderer2d::Renderable *lhs, const BatchRenderer2d::Renderable *rhs )
  {
    return  static_cast<const Box*>( lhs )->getPos().distance(center) <
    static_cast<const Box*>( rhs )->getPos().distance(center);
  };
  mSimpleRenderer.sort( vortex_simple );
  mRenderer2dStrip.sort( vortex_triangle );
  mRenderer2dStripVbo.sort( vortex_triangle );

  getWindow()->getSignalKeyUp().connect( [this](KeyEvent &event){ if( event.getCode() == KeyEvent::KEY_SPACE ){ swapRenderer(); } } );
  getWindow()->getSignalTouchesEnded().connect( [this](TouchEvent &event){ swapRenderer(); } );
}
开发者ID:pourpluie,项目名称:Pockets,代码行数:43,代码来源:RendererTestApp.cpp

示例6: mpeReset

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();
    }
}
开发者ID:indefinit,项目名称:Most-Pixels-Ever-Cinder,代码行数:20,代码来源:MPEBouncingBallApp.cpp

示例7: setup

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());
}
开发者ID:NeKoFu,项目名称:CristalWave,代码行数:48,代码来源:CristalWaveApp.cpp

示例8: position

Particle::Particle( const Vec2f& origin, Rand& random )
: position( origin ),
  velocity( random.nextFloat( -1.0f, 1.0f ), random.nextFloat( -1.0f, 1.0f ) ),
  acceleration( Vec2f::zero() ),
  lifespan( 1.0f ),
  aging( random.nextFloat( ( 1.0f / 100 ), ( 1.0f / 200 ) ) ),
  sizeRadius( random.nextFloat( 2.0f, 7.0f ) ),
  rotation( random.nextFloat( 0.0f, 360.0f ) ),
  rotationSpeed( random.nextFloat( -5.0f, 5.0f ) ),
  bounds( -sizeRadius, -sizeRadius, sizeRadius, sizeRadius )
{
    sizeRadius /= 2.0f; // since the bounds are set, we update sizeRadius for drawing circles on our particles - see draw()
}
开发者ID:ilzxc,项目名称:The-Nature-of-Cinder,代码行数:13,代码来源:Particle.cpp

示例9: addBallAtPosition

void MPEBouncingBallApp::addBallAtPosition(const vec2 & posBall)
{
    ivec2 sizeMaster = mClient->getMasterSize();
    vec2 velBall = vec2(mRand.nextFloat(-5,5), mRand.nextFloat(-5,5));
    mBalls.push_back(Ball(posBall, velBall, sizeMaster));
}
开发者ID:indefinit,项目名称:Most-Pixels-Ever-Cinder,代码行数:6,代码来源:MPEBouncingBallApp.cpp

示例10: render

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();
}
开发者ID:AKS2346,项目名称:Cinder,代码行数:83,代码来源:StereoscopicRenderingApp.cpp


注:本文中的Rand::nextFloat方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。