本文整理汇总了C++中RandFloat函数的典型用法代码示例。如果您正苦于以下问题:C++ RandFloat函数的具体用法?C++ RandFloat怎么用?C++ RandFloat使用的例子?那么, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了RandFloat函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C++代码示例。
示例1: RandFloat
void CAsteroid::Init(EAsteroidType type)
{
m_State = AS_NONE;
m_Type = type;
m_Pos.Zero();
m_Vel.Zero();
m_Rot = RandFloat(0.0f, 360.0f);
m_RotVel= RandFloat(-100.0f, 100.0f);
m_Time = 0.0f;
if (type == AT_BIG) m_Size = RandFloat(25.0f, 35.0f);
else m_Size = RandFloat(5.0f, 15.0f);
// Create the asteroid by forming a circle that we randomize a bit
f32 rot = 0.0f;
CVector2 prev(0.0f, 0.0f);
for (int lNr=0; lNr<ASTEROIDNUMLINES; lNr++)
{
CVector2 v = CVector2(0.0f, m_Size*RandFloat(0.7f, 1.0f)).Rotate((f32)(lNr+1)*(360.0f/(f32)ASTEROIDNUMLINES));
m_Lines[lNr][0] = prev;
m_Lines[lNr][1] = v;
prev = v;
}
m_Lines[0][0] = m_Lines[ASTEROIDNUMLINES-1][1];
}
示例2: SVector2D
//-------------------------------------------Reset()--------------------
//
// Resets the sweepers position, MinesGathered and rotation
//
//----------------------------------------------------------------------
void CMinesweeper::Reset(vector<CCollisionObject> &objects)
{
double threshold = (CParams::dMineScale+5)*(CParams::dMineScale+5);
boolean collision = false;
do{
//reset the sweepers positions but don't spawn on mines
m_vPosition = SVector2D((RandFloat() * CParams::WindowWidth),
(RandFloat() * CParams::WindowHeight));
collision = false;
for(int i=0; i < objects.size(); i++){
if(objects[i].getType() == CCollisionObject::SuperMine){
if(Vec2DLengthSquared(m_vPosition-objects[i].getPosition()) <= threshold){
collision = true;
break;
}
}
}
}while(collision);
//and the MinesGathered
m_dMinesGathered = 0;
m_dSuperMinesGathered = 0;
//and the rotation
m_dRotation = RandFloat()*CParams::dTwoPi;
minesLeft = minesRight = minesForwardLeft = minesForwardRight = false;
return;
}
示例3: MutateWeights
//------------------------------- MutateWeights---------------------------
// Iterates through the genes and purturbs the weights given a
// probability mut_rate.
//
// prob_new_mut is the chance that a weight may get replaced by a
// completely new weight.
//
// dMaxPertubation is the maximum perturbation to be applied.
//
// type is the type of random number algorithm we use
//------------------------------------------------------------------------
void CGenome::MutateWeights(double mut_rate,
double prob_new_mut,
double MaxPertubation)
{
for (int cGen=0; cGen<m_vecLinks.size(); ++cGen)
{
//do we mutate this gene?
if (RandFloat() < mut_rate)
{
//do we change the weight to a completely new weight?
if (RandFloat() < prob_new_mut)
{
//change the weight using the random distribtion defined by 'type'
m_vecLinks[cGen].dWeight = RandomClamped();
}
else
{
//perturb the weight
m_vecLinks[cGen].dWeight += RandomClamped() * MaxPertubation;
}
}
}
return;
}
示例4: SVector2D
void SceneController::updateSimulationOpenMP() {
// NN uses STL (it's not ported into the QTL)
auto mines = vecMines.toStdVector();
#pragma omp parallel for
for (int i = 0; i < vecSweepers.size(); ++i) {
int grabHit;
// update the NN and position
if (!vecSweepers[i].Update(mines)) {
// error in processing the neural net
gsInfo->setText("ERROR: Wrong amount of NN inputs!");
m_bInternalError = true;
continue;
}
// keep minesweepers in our viewport
vecSweepers[i].WarpWorld(0, 0, vpWidth, vpHeight);
#pragma omp critical
// see if it's found a mine
if ((grabHit = vecSweepers[i].CheckForMine(mines, MainWindow::s.dMineScale)) != -1) {
// mine found so replace the mine with another at a random position
vecMines[grabHit] = SVector2D(RandFloat() * vpWidth, RandFloat() * vpHeight);
// we have discovered a mine so increase fitness
vecSweepers[i].IncrementFitness();
}
// update the chromos fitness score
vecThePopulation[i].dFitness = vecSweepers[i].Fitness();
}
}
示例5: G_DeflectMissile
void G_DeflectMissile( gentity_t *ent, gentity_t *missile, vec3_t forward )
{
vec3_t bounce_dir;
int i;
float speed;
int isowner = 0;
vec3_t missile_dir;
//[MoreRandom]
//[/MoreRandom]
if (missile->r.ownerNum == ent->s.number)
{ //the original owner is bouncing the missile, so don't try to bounce it back at him
isowner = 1;
}
//save the original speed
speed = VectorNormalize( missile->s.pos.trDelta );
if (ent->client)
{
//VectorSubtract( ent->r.currentOrigin, missile->r.currentOrigin, missile_dir );
AngleVectors(ent->client->ps.viewangles, missile_dir, 0, 0);
VectorCopy(missile_dir, bounce_dir);
//VectorCopy( missile->s.pos.trDelta, bounce_dir );
VectorScale( bounce_dir, DotProduct( forward, missile_dir ), bounce_dir );
VectorNormalize( bounce_dir );
}
else
{
VectorCopy(forward, bounce_dir);
VectorNormalize(bounce_dir);
}
for ( i = 0; i < 3; i++ )
{ //1.3
if((ent->client->pers.cmd.buttons & BUTTON_ATTACK) && ent->client->ps.fd.saberAnimLevel != SS_FAST && ent->client->ps.fd.saberAnimLevel != SS_MEDIUM
&& ent->client->ps.fd.saberAnimLevel != SS_TAVION)
if(ent->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE]==FORCE_LEVEL_3)
bounce_dir[i] += RandFloat( -0.1f, 0.2f );
else if(ent->client->ps.fd.forcePowerLevel[FP_SABER_DEFENSE]==FORCE_LEVEL_2)
bounce_dir[i] += RandFloat( -0.2f, 0.3f );
else
bounce_dir[i] += RandFloat( -0.3f, 0.4f );
else
bounce_dir[i] += RandFloat( -1.0f, 1.0f );
}
VectorNormalize( bounce_dir );
VectorScale( bounce_dir, speed, missile->s.pos.trDelta );
missile->s.pos.trTime = level.time; // move a bit on the very first frame
VectorCopy( missile->r.currentOrigin, missile->s.pos.trBase );
if ( missile->s.weapon != WP_SABER && missile->s.weapon != G2_MODEL_PART )
{ //you are mine, now!
missile->r.ownerNum = ent->s.number;
}
if ( missile->s.weapon == WP_ROCKET_LAUNCHER )
{ //stop homing
missile->think = 0;
missile->nextthink = 0;
}
}
示例6: RandFloat
CColumn::CColumn()
{
m_NumChars = 0;
m_Chars = null;
m_Delay = m_CharDelay = RandFloat(gConfig.m_CharDelayMin, gConfig.m_CharDelayMax);
m_FadeSpeed = RandFloat(gConfig.m_FadeSpeedMin, gConfig.m_FadeSpeedMax);
m_CurChar = 0;
}
示例7: timeGetTime
//---------------------------------------:move
bool Puck::update()
{
//Update Times
float diffTime, currTime;
currTime = timeGetTime()/1000.0;
diffTime = currTime - t_lastUpdate;
t_lastUpdate = currTime;
if(goal) // if goal wait for goalsplash then countdown to start new match
{
if(--goalCountDown<= 0)
{
newMatch();
goal = false;
}
}
if(--startCountDown==0)
speed= SPEED;
else
if(startCountDown <0)
speed += 0.001;
else
speed = 0.0;
/* Update Puck Position */
position[0] += velocity[0]*speed*diffTime;
position[2] += velocity[2]*speed*diffTime;
/// calculate the reflection here...
// bounce off imaginary walls so puck is channelled nicely from player to player
// LEFT
if(position[0]-radius <= -WALLX){
position[0] = -WALLX+radius;
velocity[0] = -(velocity[0])+(0.2*RandFloat()-0.1);
velocity[2] = (velocity[2])+(0.1*RandFloat()-0.05);
}
// RIGHT
if(position[0]+radius >= WALLX){
position[0] = WALLX-radius;
velocity[0] = -(velocity[0])+(0.2*RandFloat()-0.1);
velocity[2] = (velocity[2])+(0.1*RandFloat()-0.05);
}
if(!goal && goalScored())
{
goal = true;
speed = 0.0;
startCountDown = goalCountDown = 130;
}
// adjust translation matrix appropriately
updatePosition();
return goal;
}
示例8: goalScored
bool Puck::goalScored()
{
bool result = false;
// check behind player 2
if(position[2]-radius <= -WALLZ)
{
position[2] = -WALLZ+radius;
velocity[0] = (velocity[0])+(0.2*RandFloat()-0.1);
velocity[2] = -(velocity[2])+(0.1*RandFloat()-0.05);
// check for goal
/* if(position[0] >= -2.0 && position[0] <= 2.0)
{
if(players[0]->status == ACTIVE)
{
players[0]->score++;
// otSendScoreFor(0);
if(players[1]->status == ACTIVE){
// otSendScoreAgainst(1);
}
return true;
}
}
*/
}
// check behing player 1
if(position[2]+radius >= WALLZ)
{
position[2] = WALLZ-radius;
velocity[0] = (velocity[0])+(0.2*RandFloat()-0.1);
velocity[2] = -(velocity[2])+(0.1*RandFloat()-0.05);
/*
velocity[2] = -(velocity[2]);
velocity.normalize();*/
// check for goal
/* if(position[0] >= -2.0 && position[0] <= 2.0)
{
if(players[1]->status == ACTIVE)
{
players[1]->score++;
// otSendScoreFor(1);
if(players[0]->status == ACTIVE){
// otSendScoreAgainst(0);
}
return true;
}
}*/
}
return false;
}
示例9: NudgeBall
void
NudgeBall(t_PongBall *ball, char upOrDown)
{
ball->xSpeed += RandFloat(-NUDGE_MAX, NUDGE_MAX);
if (upOrDown) // nudge up
ball->ySpeed -= RandFloat(0, NUDGE_MAX);
else // nudge down
ball->ySpeed += RandFloat(0, NUDGE_MAX);
}
示例10: initOptions
void initOptions(int n, float *price, float *strike, float *years)
{
srand(5347);
//Generate options set
for (int i = 0; i < n; i++) {
price[i] = RandFloat(5.0f, 30.0f);
strike[i] = RandFloat(1.0f, 100.0f);
years[i] = RandFloat(0.25f, 10.0f);
}
}
示例11: SVector2D
void CController::ResetEnvironment(){
m_vecSweepers.clear();
m_vecObjects.clear();
m_NumSweepers = CParams::iNumSweepers;
m_NumSuperMines = CParams::iNumSuperMines;
//let's create the mine sweepers
for (int i=0; i<m_NumSweepers; ++i)
{
m_vecSweepers.push_back(CMinesweeper());
}
//initialize super mines in random positions within the application window
// such that they aren't spawned on a sweeper
for (int i=0; i<m_NumSuperMines; ++i)
{
SVector2D position;
// don't spawn on sweepers. keep finding another location if they do.
boolean collision = false;
do{
position = SVector2D(RandFloat() * cxClient, RandFloat() * cyClient);
collision = false;
for(int i=0; i < m_vecSweepers.size(); i++){
if(Vec2DLengthSquared(position-m_vecSweepers[i].Position()) <= mineSpawnThreshold){
collision = true;
break;
}
}
}while(collision);
m_vecObjects.push_back(CCollisionObject(CCollisionObject::SuperMine, position));
}
// Spawn mines
for (int i=0; i<m_NumMines; ++i)
{
SVector2D position;
// don't spawn on super mines.
boolean collision = false;
do{
position = SVector2D(RandFloat() * cxClient, RandFloat() * cyClient);
collision = false;
for(int i=0; i < m_vecObjects.size(); i++){
if(m_vecObjects[i].getType() == CCollisionObject::SuperMine){
if(Vec2DLengthSquared(position-m_vecObjects[i].getPosition()) <= mineSpawnThreshold){
collision = true;
break;
}
}
}
}while(collision);
m_vecObjects.push_back(CCollisionObject(CCollisionObject::Mine, position));
}
}
示例12: QObject
// Initialize the sweepers, their brains and the GA factory.
SceneController::SceneController(int width, int height, QObject *parent) :
QObject(parent),
gs(new QGraphicsScene(0, 0, width, height)),
gsInfo(new QGraphicsSimpleTextItem),
gsDefaultPen(),
gsElitePen(Qt::red),
gsMinePen(Qt::green),
vpWidth(width),
vpHeight(height),
m_pGA(nullptr),
m_bInternalError(false),
m_iTicks(0),
m_iGenerations(0) {
// MSVC does not support the std::initializer_list, so this is the only way
// to create our object templates and be platform independent...
for (unsigned int i = 0; i < sizeof(objectMinePoints) / sizeof(*objectMinePoints); ++i)
objectMine.append(objectMinePoints[i]);
for (unsigned int i = 0; i < sizeof(objectSweeperPoints) / sizeof(*objectSweeperPoints); ++i)
objectSweeper.append(objectSweeperPoints[i]);
// compatibility mode with Qt5
gsDefaultPen.setCosmetic(true);
gsElitePen.setCosmetic(true);
gsMinePen.setCosmetic(true);
gs->addItem(gsInfo);
// let's create the minesweepers
for (int i = MainWindow::s.iNumSweepers; i; --i)
vecSweepers.push_back(CMinesweeper(RandFloat() * vpWidth,
RandFloat() * vpHeight, RandFloat() * 2 * M_PI));
// and initial population of mines
updateMineObjects(MainWindow::s.iNumMines);
// get the total number of weights used in the sweepers
// NN so we can initialize the GA
int m_NumWeightsInNN = vecSweepers[0].GetNumberOfWeights();
// initialize the Genetic Algorithm class
delete m_pGA;
m_pGA = new CGenAlg(vecSweepers.size(), m_NumWeightsInNN);
// get the weights from the GA and insert into the sweepers brains
vecThePopulation = QVector<SGenome>::fromStdVector(m_pGA->GetChromos());
for (int i = 0; i < vecThePopulation.size(); i++)
vecSweepers[i].PutWeights(vecThePopulation[i].vecWeights);
}
示例13: SVector2D
//-------------------------------------------Reset()--------------------
//
// Resets the sweepers position, fitness and rotation
//
//----------------------------------------------------------------------
void CMinesweeper::Reset()
{
//reset the sweepers positions
m_vPosition = SVector2D((RandFloat() * CParams::WindowWidth),
(RandFloat() * CParams::WindowHeight));
//and the fitness
m_dFitness = 0;
//and the rotation
m_dRotation = RandFloat()*CParams::dTwoPi;
return;
}
示例14: SetTime
void Reverb::SetTime(float s)
{
m_Time=s;
float t=0;
int count=0;
for (vector<Delay*>::iterator i=m_DelayVec.begin();
i!=m_DelayVec.end(); i++)
{
t=count/(float)NUM_DELAYS;
(*i)->SetLeftDelay(t*m_Time+RandFloat(-m_Randomness,m_Randomness));
(*i)->SetRightDelay(t*m_Time+RandFloat(-m_Randomness,m_Randomness));
count++;
}
}
示例15: m_dRotation
//-----------------------------------constructor-------------------------
//
//-----------------------------------------------------------------------
CMinesweeper::CMinesweeper():
m_dRotation(RandFloat()*CParams::dTwoPi),
m_lTrack(0.16),
m_rTrack(0.16),
m_dFitness(0),
m_dScale(CParams::iSweeperScale),
m_iClosestMine(0)
{
//create a random start position
m_vPosition = SVector2D((RandFloat() * CParams::WindowWidth),
(RandFloat() * CParams::WindowHeight));
}