本文整理汇总了C++中randFloat函数的典型用法代码示例。如果您正苦于以下问题:C++ randFloat函数的具体用法?C++ randFloat怎么用?C++ randFloat使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了randFloat函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。
示例1: randFloat
void TestCanvas::testCubicBezier(GiCanvas* canvas)
{
for (int i = 0; i < 100; i++) {
canvas->beginPath();
float x1 = randFloat(10.f, 600.f);
float y1 = randFloat(10.f, 600.f);
float x2 = x1 + randFloat(-50.f, 50.f);
float y2 = y1 + randFloat(-50.f, 50.f);
float x3 = x2 + randFloat(-50.f, 50.f);
float y3 = y2 + randFloat(-50.f, 50.f);
float x4 = x3 + randFloat(-50.f, 50.f);
float y4 = y3 + randFloat(-50.f, 50.f);
canvas->moveTo(x1, y1);
for (int j = randInt(1, 10); j > 0; j--) {
canvas->bezierTo(x2, y2, x3, y3, x4, y4);
x1 = x2; y1 = y2;
x2 = 2 * x4 - x3;
y2 = 2 * y4 - y3;
x3 = 4 * (x4 - x3) + x1;
y3 = 4 * (y4 - y3) + y1;
x4 = x3 + randFloat(-50.f, 50.f);
y4 = y3 + randFloat(-50.f, 50.f);
}
canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), -1.f, -1);
canvas->drawPath(true, false);
}
}
开发者ID:huangzongwu,项目名称:vglite,代码行数:32,代码来源:testcanvas.cpp
示例2: vec
glm::vec3 QuaternionDemo::randomUnitVector()
{
glm::vec3 vec(randFloat() - 0.5f,
randFloat() - 0.5f,
randFloat() - 0.5f);
return glm::normalize(vec);
}
开发者ID:filkry,项目名称:quaternion_demo,代码行数:7,代码来源:quaternion_demo.cpp
示例3: drawBomb
void drawBomb(void* ptr){
Bomb *b = ptr;
glColor4f(1.0f, 0.0f, 0.0f, 1.0f);
if(b->isDeleted || b->cnt > 100){
b->isDeleted = 1;
return;
}
float rate = 1.0f - (float)b->cnt / 100.0f;
glEnableClientState(GL_VERTEX_ARRAY);
for(int i = 0; i < FIRES; i++){
GLfloat point[] = {
b->fires[i].x, b->fires[i].y, b->fires[i].z
};
glColor4f(
randFloat() * rate,
randFloat() * rate,
randFloat() * rate,
1.0f //
);
glVertexPointer(3, GL_FLOAT, 0, point);
glDrawArrays(GL_POINTS, 0, 1);
}
}
开发者ID:hiratara,项目名称:danmakuiphone,代码行数:26,代码来源:cube.c
示例4: train_test
static void train_test( void ) {
float hiddenWeights[2][3] = {{0, 0, 0}, {0, 0, 0}};
float outputWeights[1][3] = {{0, 0, 0}};
Node inputNodes[2] = {{NULL, randFloat() * 2 -1}, {NULL, randFloat() * 2 - 1}};
Node hiddenNodes[2] = {{hiddenWeights[0]}, {hiddenWeights[1]}};
Node outputNodes[1] = {{outputWeights[0]}};
Node desiredOutputNodes[1] = {{NULL, randFloat() - 0.5}};
Layer inputLayer = {inputNodes, 2};
Layer hiddenLayer = {hiddenNodes, 2};
Layer outputLayer = {outputNodes, 1};
Layer desiredOutputLayer = {desiredOutputNodes, 1};
TestCase testCase = {&inputLayer, &desiredOutputLayer};
int i, j;
for( i = 0; i < 1000; ++i ) {
j = 0;
desiredOutputNodes[0].output = randFloat() - 0.5;
while( fabs( outputLayer.nodes[0].output - desiredOutputNodes[0].output ) > 0.01 ) {
train( &testCase, &hiddenLayer, &outputLayer );
if( j++ > 1000 ) {
printf( "Converged %d sets so far.\n", i -1 );
printf( "Desired Output: %f, Current Output: %f\n", desiredOutputNodes[0].output, outputLayer.nodes[0].output );
assert ( 1 == 0 && "Did not converge in a timely manner" );
}
}
}
}
开发者ID:chessami92,项目名称:ceen4920-backpropagation,代码行数:27,代码来源:backprop_test.c
示例5: randIntInRange
void Endpoint::sendDatagram(const QByteArray& datagram) {
datagramsSent++;
// some datagrams are dropped
const float DROP_PROBABILITY = 0.1f;
if (randFloat() < DROP_PROBABILITY) {
return;
}
// some are received out of order
const float REORDER_PROBABILITY = 0.1f;
if (randFloat() < REORDER_PROBABILITY) {
const int MIN_DELAY = 1;
const int MAX_DELAY = 5;
// have to copy the datagram; the one we're passed is a reference to a shared buffer
_delayedDatagrams.append(QPair<QByteArray, int>(QByteArray(datagram.constData(), datagram.size()),
randIntInRange(MIN_DELAY, MAX_DELAY)));
// and some are duplicated
const float DUPLICATE_PROBABILITY = 0.01f;
if (randFloat() > DUPLICATE_PROBABILITY) {
return;
}
}
_other->_sequencer->receivedDatagram(datagram);
datagramsReceived++;
}
开发者ID:dv8eve,项目名称:hifi,代码行数:28,代码来源:MetavoxelTests.cpp
示例6: randFloat
void ParticlePool::missileTrail(const Position &pos, float radius)
{
radius *= 0.5;
float entspeed = pos.getVelocityMagnitude();
for (int i = 0; i < 6; i++)
{
float randAngle = randFloat(M_PI-M_PI/60, M_PI+M_PI/60);
float speed = randFloat(1000.0, 1700.0);
float offset_time = randFloat(0, getDt()) * (entspeed-speed);
float spawnX = pos.getX() - (radius + offset_time) * -cos(pos.getR() + M_PI);
float spawnY = pos.getY() - (radius + offset_time) * sin(pos.getR() + M_PI);
float spawnVelX = speed * ( cos(pos.getR() + randAngle)) + pos.getX_vel();
float spawnVelY = speed * (-sin(pos.getR() + randAngle)) + pos.getY_vel();
Position spawnPos = Position(spawnX, spawnY);
spawnPos.setX_vel(spawnVelX);
spawnPos.setY_vel(spawnVelY);
Particle p = Particle(
255,
randInt(64, 215),
0,
randInt(128,255),
randFloat(0.16, 0.24),
spawnPos,
900);
add(p);
}
}
开发者ID:yixu34,项目名称:Mastrix,代码行数:31,代码来源:particlepool.cpp
示例7: colorFromString
Color colorFromString(string s)
{
static Color s_cLastCol;
Color c;
if(s == "random_pastel") //Some random pastel color (good for parasprites)
{
float h, s, v;
h = randFloat(0.0, 360.0);
s = randFloat(40.0, 100.0);
v = 100.0;
c = HsvToRgb(h,s,v);
c.r /= 100;
c.g /= 100;
c.b /= 100;
s_cLastCol = c;
return c;
}
else if(s == "last") //Last color we got from this function
return s_cLastCol;
s = stripCommas(s);
//Now, parse
istringstream iss(s);
int r, g, b, a;
if(iss >> r >> g >> b)
{
if(!(iss >> a))
c.from256(r,g,b);
else
c.from256(r,g,b,a);
}
开发者ID:meh2481,项目名称:pony48,代码行数:33,代码来源:globaldefs.cpp
示例8: randInt
void ParticlePool::explodeMineAt(const Position &source, float sourceRadius)
{
int numParticles = randInt(300, 400);
for (int i = 0; i < numParticles; i++)
{
float randAngle = randFloat(0.0f, M_PI * 2);
float randDist = randFloat(0, sourceRadius);
float spawnX = source.getX() + randDist * cos(randAngle);
float spawnY = source.getY() + randDist * sin(randAngle);
float speed = randFloat(-100.0f, 30.0f);
float spawnVelX = speed * cos(randAngle);
float spawnVelY = speed * sin(randAngle);
Position spawnPos = Position(spawnX, spawnY);
spawnPos.setX_vel(spawnVelX);
spawnPos.setY_vel(spawnVelY);
Particle p = Particle(
255, randInt(100,200), 255, randInt(170, 255),
randFloat(0.5, 1.2),
spawnPos,
400);
add(p);
}
}
开发者ID:yixu34,项目名称:Mastrix,代码行数:26,代码来源:particlepool.cpp
示例9: while
void Crack::findStart()
{
// shift until crack is found
bool bFound = false;
int timeout = 0;
uint px, py;
while ((!bFound) || (timeout++>1000))
{
// pick random point
px = randInt(0, m_image.width()-1);
py = randInt(0, m_image.height()-1);
if(m_cgrid[py*m_image.width() + px] < UNCRACKED)
bFound=true;
}
if (bFound)
{
// start crack
int angle = m_cgrid[py*m_image.width() + px];
if (randInt(0, 100) < 50)
angle -= 90 + int(randFloat(-m_degreesFromPerpendicular, m_degreesFromPerpendicular));
else
angle += 90 + int(randFloat(-m_degreesFromPerpendicular, m_degreesFromPerpendicular));
m_line.setLine(Point(px, py), angle, m_image.width(), m_image.height());
m_pts = m_line.points();
m_ptIndex = 0;
startCrack();
}
}
开发者ID:dparks1134,项目名称:Art,代码行数:33,代码来源:Crack.cpp
示例10: CHECK_STATUS_AND_RETURN_IF_FAIL
//----------------------------------------------------------------------------------------------------------------------
MStatus CustomSphere::redoIt()
{
// loop for the number of arguments passed in and create some random spheres
for( unsigned int i = 0; i < m_count; ++i )
{
// fist I'm going to create a maya command as follows
// sphere -name "sphere[n]" where n is the value of i
std::string cmd;
float rad=randFloat(m_minRadius,m_maxRadius);
cmd=boost::str(boost::format("sphere -name \"sphere%d\" -r %f") %i %rad) ;
// now execute the command
MStatus status = MGlobal::executeCommand( cmd.c_str() );
// and check that is was succesfull
CHECK_STATUS_AND_RETURN_IF_FAIL(status,"Unable to execute sphere command");
// now move to a random position first grab some positions
float x=randFloat(-m_xExtent,m_xExtent);
float y=randFloat(-m_yExtent,m_yExtent);
float z=randFloat(-m_zExtent,m_zExtent);
// build the command string
// move x y z "sphere[n]"
cmd=boost::str(boost::format("move %f %f %f \"sphere%d\"") %x %y %z %i) ;
// execute
status=MGlobal::executeCommand(cmd.c_str());
CHECK_STATUS_AND_RETURN_IF_FAIL(status,"unable to move object");
}
std::string mesg=boost::str(boost::format("%d Spheres created") %m_count) ;
MGlobal::displayInfo( mesg.c_str() );
return MStatus::kSuccess;
}
开发者ID:Qaanaaq,项目名称:MayaAPICode,代码行数:32,代码来源:CustomSphere.cpp
示例11: randomizeScene
void randomizeScene(void)
{
for (int i = 0; i < (int) randFloat(50,100); i++) { // 50 to 100 objects
float decideShape = randFloat(0, 1);
if (decideShape < 0.7) { // 70% point
makeVertex();
finishedShapes.push_back(currentVertices);
finishedShapes.back().type = GL_POINTS;
clearCurrentVertex();
}
else if (decideShape > 0.9) { // 10% polygon
for (int i = 0; i < (int)randFloat(3, 7); i++) { // 3 to 7 vertices in a polygon
makeVertex();
}
finishedShapes.push_back(currentVertices);
finishedShapes.back().type = GL_POLYGON;
clearCurrentVertex();
}
else { // 20% line
makeVertex();
makeVertex();
finishedShapes.push_back(currentVertices);
finishedShapes.back().type = GL_LINES;
clearCurrentVertex();
}
}
}
开发者ID:phamd,项目名称:OpenGL-Interactive-Screensaver,代码行数:27,代码来源:main.cpp
示例12: makeVertex
void makeVertex(void)
{
currentVertex.position = Vector2d(randFloat(0, gWidth), randFloat(0, gHeight));
currentVertex.direction = Vector2d(randFloat(-1, 1), randFloat(-1, 1));
currentVertex.colour = getColour(gColour);
currentVertices.push_back(currentVertex);
}
开发者ID:phamd,项目名称:OpenGL-Interactive-Screensaver,代码行数:7,代码来源:main.cpp
示例13: spawnTroops
static void spawnTroops( int side, int minCnt, int maxCnt )
{
int numToSpawn = minCnt + ( rand( ) % ( maxCnt - minCnt ) );
float baseX;
if( introMode ) {
baseX = 500.0f + randFloat( 200.0f, 480.0f ) * sign( randFloat( -1.0f, 1.0f ) );
} else {
baseX = randFloat( 20.0f, 980.0f );
}
float baseY = ( side == 0 ) ? 650.0f : -60.0f;
Vector2 spawnPos;
spawnPos.x = baseX;
float stepX = ( baseX < 500.0f ) ? 25.0f : -25.0f;
float signY = ( side == 0 ) ? 1.0f : -1.0f;
while( numToSpawn > 0 ) {
spawnPos.y = baseY + ( randFloat( 0.0f, 30.0f ) * signY );
spawnTroop( spawnPos, side );
spawnPos.x += stepX + randFloat( -10.0f, 10.0f );
--numToSpawn;
}
}
开发者ID:JesseRahikainen,项目名称:LD32_Ezrtel,代码行数:25,代码来源:gameScreen.c
示例14: vec2
Particle::Particle(vec2 l)
{
location_ = l;
lifespan_ = 1.0;
acceleration_ = vec2(0,0.05);
velocity_ = vec2(randFloat(-1,1), randFloat(-2,0));
}
开发者ID:jefarrell,项目名称:NatureOfCode_Cinder,代码行数:7,代码来源:Particle.cpp
示例15: randFloat
void TestCanvas::testCubicBezier(GiCanvas* canvas, int n)
{
float x1 = randFloat(100.f, 400.f);
float y1 = randFloat(100.f, 400.f);
for (int i = 0; i < n; i++) {
canvas->beginPath();
float x2 = x1 + randFloat(-50.f, 50.f);
float y2 = y1 + randFloat(-50.f, 50.f);
float x3 = x2 + randFloat(-50.f, 50.f);
float y3 = y2 + randFloat(-50.f, 50.f);
float x4 = x3 + randFloat(-50.f, 50.f);
float y4 = y3 + randFloat(-50.f, 50.f);
canvas->moveTo(x1, y1);
for (int j = randInt(1, 10); j > 0; j--) {
canvas->bezierTo(x2, y2, x3, y3, x4, y4);
x1 = x2; y1 = y2; // P2
x2 = 2 * x4 - x3; // Q2=2P4-P3
y2 = 2 * y4 - y3;
x3 = 4 * (x4 - x3) + x1; // Q3=4(P4-P3)+P2
y3 = 4 * (y4 - y3) + y1;
x4 = x3 + randFloat(-50.f, 50.f);
y4 = y3 + randFloat(-50.f, 50.f);
}
if (s_randStyle) {
canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), -1.f, -1, 0);
}
canvas->drawPath(true, false);
}
}
开发者ID:rhcad,项目名称:vglite,代码行数:35,代码来源:testcanvas.cpp
示例16: randFloat
Milestone* Milestone::makeRandomMilestone(Map& map) {
for (int i = 0; i < MAX_BRANCH_CREATION_ATTEMPS; ++i) {
// TODO: normal distribution?
float speed = randFloat(-0.05, 0.3);
// float speed = randFloat(0.1, 0.3);
// float speed = randFloat(-0.2, 0.2);
float turnRateRange = 1 - fabs(speed*2);
float turnRate = randFloat(-turnRateRange, turnRateRange);
int numCycles = (rand() % 70) + 30;
Pose endPose = getEndPose();
bool failed = false;
for (int cycle = 0; cycle < numCycles; ++cycle) {
endPose = propogateDynamics(endPose, speed, turnRate);
if (map.robotAreaOccupied(endPose)) {
// this motion path wasn't possible
failed = true;
break;
}
}
if (!failed) {
return new Milestone(this, endPose, speed, turnRate, numCycles);
}
// try another set of values
}
return NULL;
}
开发者ID:velveteenrobot,项目名称:turtlebot_example_lab_2,代码行数:27,代码来源:RRT.cpp
示例17: Vector3
cParticle::cParticle(const POINT &pos)
{
// (-30,-30) ----------------- (+30, -30)
// | |
// | + |
// | |
// (-30,+30) ----------------- (+30, +30)
const float w = 15.f;
m_vertices.push_back( Vector3(-w,-w,1) );
m_vertices.push_back( Vector3(w,-w,1) );
m_vertices.push_back( Vector3(w,w,1) );
m_vertices.push_back( Vector3(-w,w,1) );
m_vertices.push_back( Vector3(-w,-w,1) );
m_localTm.SetIdentity();
m_tm.SetIdentity();
m_tm.Translate(Vector3((float)pos.x, (float)pos.y, 0));
const float x = randFloat() * 1000.f;
const float y = randFloat() * 1000.f;
m_Velocity = Vector3(x,y,0);
m_Pos = Vector3((float)pos.x, (float)pos.y, 0);
m_Torq = randFloat() * 30.f;
}
开发者ID:butilities,项目名称:API-Lecture,代码行数:25,代码来源:particle.cpp
示例18: randFloat
/*
Name SimplexNoise::createRandomTexture
Syntax SimplexNoise::createRandomTexture(ID3D10ShaderResourceView* _texRV)
Param ID3D10ShaderResourceView* _texRV - The texture resource view
Brief Builds a random 1D texture used for generating
random values in effect files
*/
ID3D10ShaderResourceView* SimplexNoise::createRandomTexture()
{
// Create random data
D3DXVECTOR4 randomValues[1024];
for (int i = 0; i < 1024; ++i)
{
randomValues[i].x = randFloat(-1.0f, 1.0f);
randomValues[i].y = randFloat(-1.0f, 1.0f);
randomValues[i].z = randFloat(-1.0f, 1.0f);
randomValues[i].w = randFloat(-1.0f, 1.0f);
}
D3D10_SUBRESOURCE_DATA initData;
initData.pSysMem = randomValues;
initData.SysMemPitch = 1024 * sizeof(D3DXVECTOR4);
initData.SysMemSlicePitch = 1024 * sizeof(D3DXVECTOR4);
// Create the texture
D3D10_TEXTURE1D_DESC texDesc;
texDesc.Width = 1024;
texDesc.MipLevels = 1;
texDesc.Format = DXGI_FORMAT_R32G32B32A32_FLOAT;
texDesc.Usage = D3D10_USAGE_IMMUTABLE;
texDesc.BindFlags = D3D10_BIND_SHADER_RESOURCE;
texDesc.CPUAccessFlags = 0;
texDesc.MiscFlags = 0;
texDesc.ArraySize = 1;
ID3D10Texture1D* randomTex = 0;
ID3D10Device* d3dDevice = Scene::instance()->getDevice();
HRESULT hr = d3dDevice->CreateTexture1D(&texDesc, &initData, &randomTex);
if (FAILED(hr))
{
MessageBox(0, "Create random texture - Failed", "Error", MB_OK);
return 0;
}
// Create the resource view
D3D10_SHADER_RESOURCE_VIEW_DESC viewDesc;
viewDesc.Format = texDesc.Format;
viewDesc.ViewDimension = D3D10_SRV_DIMENSION_TEXTURE1D;
viewDesc.Texture1D.MipLevels = texDesc.MipLevels;
viewDesc.Texture1D.MostDetailedMip = 0;
ID3D10ShaderResourceView* texRV;
hr = d3dDevice->CreateShaderResourceView(randomTex, &viewDesc, &texRV);
if (FAILED(hr))
{
MessageBox(0, "Create random tex RV - Failed", "Error", MB_OK);
return 0;
}
randomTex->Release();
randomTex = 0;
return texRV;
}
开发者ID:NoSilentWonder,项目名称:Mordor,代码行数:66,代码来源:SimplexNoise.cpp
示例19: integrateParticle
void ParticleEffectEntityItem::stepSimulation(float deltaTime) {
_particleMinBound = glm::vec3(-1.0f, -1.0f, -1.0f);
_particleMaxBound = glm::vec3(1.0f, 1.0f, 1.0f);
// update particles between head and tail
for (quint32 i = _particleHeadIndex; i != _particleTailIndex; i = (i + 1) % _maxParticles) {
_particleLifetimes[i] -= deltaTime;
// if particle has died.
if (_particleLifetimes[i] <= 0.0f) {
// move head forward
_particleHeadIndex = (_particleHeadIndex + 1) % _maxParticles;
}
else {
integrateParticle(i, deltaTime);
extendBounds(_particlePositions[i]);
}
}
// emit new particles, but only if animaiton is playing
if (getAnimationIsPlaying()) {
float timeLeftInFrame = deltaTime;
while (_timeUntilNextEmit < timeLeftInFrame) {
timeLeftInFrame -= _timeUntilNextEmit;
_timeUntilNextEmit = 1.0f / _emitRate;
// emit a new particle at tail index.
quint32 i = _particleTailIndex;
_particleLifetimes[i] = _lifespan;
// jitter the _emitDirection by a random offset
glm::vec3 randOffset;
randOffset.x = (randFloat() - 0.5f) * 0.25f * _emitStrength;
randOffset.y = (randFloat() - 0.5f) * 0.25f * _emitStrength;
randOffset.z = (randFloat() - 0.5f) * 0.25f * _emitStrength;
// set initial conditions
_particlePositions[i] = glm::vec3(0.0f, 0.0f, 0.0f);
_particleVelocities[i] = _emitDirection * _emitStrength + randOffset;
integrateParticle(i, timeLeftInFrame);
extendBounds(_particlePositions[i]);
_particleTailIndex = (_particleTailIndex + 1) % _maxParticles;
// overflow! move head forward by one.
// because the case of head == tail indicates an empty array, not a full one.
// This can drop an existing older particle, but this is by design, newer particles are a higher priority.
if (_particleTailIndex == _particleHeadIndex) {
_particleHeadIndex = (_particleHeadIndex + 1) % _maxParticles;
}
}
_timeUntilNextEmit -= timeLeftInFrame;
}
}
开发者ID:MarcelEdward,项目名称:hifi,代码行数:59,代码来源:ParticleEffectEntityItem.cpp
示例20: randVertices
std::vector<glm::vec3> randVertices(size_t num) {
std::vector<glm::vec3> result(num);
srand((unsigned)time(0));
for (size_t i = 0; i < result.size(); i++) {
result[i] = glm::vec3(randFloat(), randFloat(), randFloat());
}
return result;
}
开发者ID:georgy-schukin,项目名称:opengl-examples,代码行数:8,代码来源:helpers.cpp
注:本文中的randFloat函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论