Example #1
0
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);
    }
}
glm::vec3 QuaternionDemo::randomUnitVector()
{
    glm::vec3 vec(randFloat() - 0.5f,
            randFloat() - 0.5f,
            randFloat() - 0.5f);
    return glm::normalize(vec);
}
Example #3
0
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);
    }
}
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" );
            }
        }
    }
}
Example #5
0
void TestCanvas::testLine(GiCanvas* canvas)
{
    for (int i = 0; i < 100; i++) {
        canvas->drawLine(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
                         randFloat(10.f, 400.f), randFloat(10.f, 400.f));
    }
}
Example #6
0
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++;
}
Example #7
0
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);
	}
}
Example #8
0
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);
	}
Example #9
0
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);
	}
}
Example #10
0
void ParticlePool::explodeAsteroidAt(const Position &source, float sourceRadius)
{
	int numParticles = randInt(50, 100);
	for (int i = 0; i < numParticles; i++)
	{
		float randAngle = randFloat(0.0f, M_PI * 2);
		float spawnX	= source.getX() + sourceRadius * cos(randAngle);
		float spawnY	= source.getY() + sourceRadius * sin(randAngle);
		float speed		= randFloat(10.0f, 200.0f);
		float spawnVelX = speed * cos(randAngle);
		float spawnVelY = speed * sin(randAngle);

		Position spawnPos = Position(spawnX, spawnY);
		spawnPos.setX_vel(spawnVelX);
		spawnPos.setY_vel(spawnVelY);
		int color = randInt(50, 150);
		
		Particle p = Particle(
			color, color, color,
			255, 
			randFloat(0.1, 0.6),  
			spawnPos, 
			particleFadeSpeed);

		add(p);
	}
}
Example #11
0
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();
	}
}
Example #12
0
//----------------------------------------------------------------------------------------------------------------------
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;
}
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();
		}
	}
}
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);
}
Example #15
0
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;
	}
}
Particle::Particle(vec2 l)
{
    location_ = l;
    lifespan_ = 1.0;
    acceleration_ = vec2(0,0.05);
    velocity_ = vec2(randFloat(-1,1), randFloat(-2,0));
}
Example #17
0
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);
    }
}
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;
}
Example #19
0
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;
}
Example #20
0
/*
	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;
}
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;
    }
}
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;
}
Example #23
0
void TestCanvas::testEllipse(GiCanvas* canvas)
{
    for (int i = 0; i < 100; i++) {
        canvas->drawEllipse(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
                            randFloat(10.f, 400.f), randFloat(10.f, 400.f),
                            randInt(0, 1) == 1, randInt(0, 1) == 1);
    }
}
Example #24
0
void AGWorm::complexPlus(){
    // complexify creature
    if (num < 50){
        num++;
        Vec3f p = pos + Vec3f(randFloat(-1, 1), randFloat(-1, 1), randFloat(-1, 1));
        Node n = *new Node(p, damp);
        nodes.push_back(n);
    }
}
Example #25
0
void TestCanvas::testLine(GiCanvas* canvas, int n)
{
    for (int i = 0; i < n; i++) {
        if (s_randStyle) {
            canvas->setPen(randInt(10, 0xFF) << 24 | randInt(0, 0xFFFFFF), -1.f, -1, 0);
        }
        canvas->drawLine(randFloat(10.f, 600.f), randFloat(10.f, 600.f),
                        randFloat(10.f, 400.f), randFloat(10.f, 400.f));
    }
}
void CRandomDirectionComponent::Update(CParticle* particle, float dt)
{
	if(particle->age >= 0)
	{
		float x = randFloat(m_randMax.x, m_randMin.x);
		float y = randFloat(m_randMax.y, m_randMin.y);
		float z = randFloat(m_randMax.z, m_randMin.z);
		particle->velocity == vec3(x, y, z);
	}
}
Example #27
0
void ObjectFactory::generateRandomObjects(const BoundingBox3f& region, const Duration& duration, double forceRadius, int forceNumRandomObjects) {
    Time start(Time::null());
    Time end = start + duration;
    Vector3f region_extents = region.extents();

    uint32 nobjects              = GetOptionValue<uint32>(OBJECT_NUM_RANDOM);
    if (forceNumRandomObjects)
        nobjects=forceNumRandomObjects;
    if (nobjects == 0) return;
    bool simple                  =   GetOptionValue<bool>(OBJECT_SIMPLE);
    bool only_2d                 =       GetOptionValue<bool>(OBJECT_2D);
    std::string motion_path_type = GetOptionValue<String>(OBJECT_STATIC);
    float driftX                 = GetOptionValue<float>(OBJECT_DRIFT_X);
    float driftY                 = GetOptionValue<float>(OBJECT_DRIFT_Y);
    float driftZ                 = GetOptionValue<float>(OBJECT_DRIFT_Z);

    float percent_queriers       = GetOptionValue<float>(OBJECT_QUERY_FRAC);

    Vector3f driftVecDir(driftX,driftY,driftZ);


    for(uint32 i = 0; i < nobjects; i++) {
        UUID id = randomUUID();

        ObjectInputs* inputs = new ObjectInputs;

        Vector3f startpos = region.min() + Vector3f(randFloat()*region_extents.x, randFloat()*region_extents.y, (only_2d ? 0.5 : randFloat())*region_extents.z);

        double radval = forceRadius;
        if (!radval)
            radval=10;
        float bounds_radius = (simple ? radval : (randFloat()*2*radval));
        //SILOG(oh,error,"Creating "<<id.toString()<<" radius "<<bounds_radius);
        inputs->localID = mLocalIDSource++;

        if (motion_path_type == "static")//static
            inputs->motion = new StaticMotionPath(start, startpos);
        else if (motion_path_type == "drift") //drift
        {
          //   inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, zfactor); // FIXME
          inputs->motion = new OSegTestMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, 0.5, driftVecDir); // FIXME
        }
        else //random
            inputs->motion = new RandomMotionPath(start, end, startpos, 3, Duration::milliseconds((int64)1000), region, (only_2d ? 0.0 : 1.0)); // FIXME
        inputs->bounds = BoundingSphere3f( Vector3f(0, 0, 0), bounds_radius );
        inputs->registerQuery = (randFloat() <= percent_queriers);
        inputs->queryAngle = SolidAngle(SolidAngle::Max / 900.f); // FIXME how to set this? variability by objects?
        inputs->connectAt = Duration::seconds(0.f);

        inputs->startTimer = Network::IOTimer::create(mContext->ioService);

        mObjectIDs.insert(id);
        mInputs[id] = inputs;
    }
}
Example #28
0
void TestCanvas::testQuadBezier(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(-100.f, 100.f);
        float y2 = y1 + randFloat(-100.f, 100.f);
        float x3 = x2 + randFloat(-100.f, 100.f);
        float y3 = y2 + randFloat(-100.f, 100.f);
        
        canvas->moveTo(x1, y1);
        canvas->lineTo((x1 + x2) / 2, (y1 + y2) / 2);
        
        for (int j = randInt(5, 20); j > 0; j--) {
            canvas->quadTo(x2, y2, (x3 + x2) / 2, (y3 + y2) / 2);
            
            x1 = x2; x2 = x3;
            y1 = y2; y2 = y3;
            x3 = x2 + randFloat(-100.f, 100.f);
            y3 = y2 + randFloat(-100.f, 100.f);
        }
        canvas->lineTo(x2, y2);
        
        if (s_randStyle) {
            canvas->setPen(0xFF000000 | randInt(0, 0xFFFFFF), randFloat(0, 6), randInt(0, 4), 0);
        }
        canvas->drawPath(true, false);
    }
}
float3 CGlobalSyncedStuff::randVector()
{
	float3 ret;
	do{
		ret.x=randFloat()*2-1;
		ret.y=randFloat()*2-1;
		ret.z=randFloat()*2-1;
	} while(ret.SqLength()>1);

	return ret;
}
Example #30
0
/**
 * @return synced random vector
 *
 * returns a synced random vector
 */
float3 CGlobalSynced::randVector()
{
	float3 ret;

	do {
		ret.x = randFloat() * 2.0f - 1.0f;
		ret.y = randFloat() * 2.0f - 1.0f;
		ret.z = randFloat() * 2.0f - 1.0f;
	} while (ret.SqLength() > 1.0f);

	return ret;
}