コード例 #1
0
ファイル: test.c プロジェクト: rmuenste/opengl-sdl
static void display(void)
{
	glClearColor(randf(), randf(), randf(), 1.0f);
	glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT);
	glutSwapBuffers();
	glutPostRedisplay();
}
コード例 #2
0
glm::mat4 randMat()
{
	float theta = randf(-PI / 2, PI / 2), phi = randf(0.0f, 2 * PI);
	glm::mat4 rotation = glm::rotate(glm::mat4(1.0), phi, glm::vec3(1.0, 0.0, 0.0));
	rotation = glm::rotate(rotation,     theta, glm::vec3(0.0, 1.0, 0.0));
	return rotation;
}
コード例 #3
0
void Server::broadcastFaultyData(const char* data, unsigned int size) {
	packetNumber++;
	// lose messages every so often
	if (randf() * 100 < m_packetlossPercentage)
		return;

	// delay messages every so often
	if (randf() * 100 < m_delayPercentage) {
		DelayedBroadcast* b = new DelayedBroadcast;
		b->stream.Write((RakNet::MessageID)GameMessages::ID_ENTITY_LIST);
		b->stream.Write(size);
		b->stream.Write(packetNumber);
		b->stream.Write(data, size);
		float delay = randf() * m_delayRange;
		b->delayMicroseconds = (double)(delay * 1000.0 * 1000.0);
		m_delayedMessages.push_back(b);
	}
	else {
		// just send the stream
		RakNet::BitStream stream;
		stream.Write((RakNet::MessageID)GameMessages::ID_ENTITY_LIST); 
		stream.Write(size);
		stream.Write(packetNumber);
		stream.Write(data, size);
		sendBitStream(&stream);
	}
}
コード例 #4
0
ファイル: FlowShower.cpp プロジェクト: kpws/Flower
void FlowShower::update()
{
	scale += (scaleb - scale) * 0.1;
	if (game->isMiddleDown() && !painting)
	{
		viewX = pressViewX + (pressX - float(game->getMouseX())
				/ float(game->getResY())) / scale;
		viewY = pressViewY - (pressY - float(game->getMouseY())
				/ float(game->getResY())) / scale;
	}
	inkNew+=0.1f;
	while(inkNew>=1.0f)
	{
		inkNew-=1.0f;
		inkRed=inkRedNew;
		inkGreen=inkGreenNew;
		inkBlue=inkBlueNew;
		inkRedNew=randf(1.0f);
		inkGreenNew=randf(1.0f);
		inkBlueNew=randf(1.0f);
	}
	clock_t curentClock = clock();
	/*if (lastClock != 0 || dt != 0)
	 dt = float(curentClock - lastClock) / 1000.0f;*/
	lastClock = curentClock;

}
コード例 #5
0
ファイル: Tile.cpp プロジェクト: reima/sep3d
void Tile::Init(float roughness) {
  // Zufallsgenerator initialisieren
  srand(static_cast<unsigned int>(time(0)));

  // x- und z-Koordinaten berechnen.
  // Das Wurzel-Tile ersteckt sich entlang der x- und z-Achse immer im Bereich
  // [-2.5, 2.5]
  int i = 0;
  for (int y = 0; y < size_; ++y) {
    for (int x = 0; x < size_; ++x, ++i) {
      vertices_[i].x = x * 5.0f / (size_ - 1) - 2.5f;
      vertices_[i].z = y * 5.0f / (size_ - 1) - 2.5f;
    }
  }

  // Ecken mit Zufallshöhenwerten initialisieren
  int block_size = size_ - 1;
  vertices_[I(0, 0)].y = randf();
  vertices_[I(0, block_size)].y = randf();
  vertices_[I(block_size, 0)].y = randf();
  vertices_[I(block_size, block_size)].y = randf();

  // Verfeinerungsschritte durchführen bis sämtliche Werte berechnet sind
  while (block_size > 1) {
    Refine(block_size, roughness);
    block_size = block_size / 2;
  }
}
コード例 #6
0
static inline float RandFloat(const float min, const float max) {
	// we work with large floats here (1e22 etc.) we cannot blend them without overflows, so do it a bit differently
	if (rand() & 1) {
		return max * randf();
	}
	return min * randf();
}
コード例 #7
0
ファイル: ising2d.c プロジェクト: nosubsgo/numericalmethods
void metro(double *m, double *T) /*Metropolitan algorithm*/
{
 	int i, x, y, xdown, xup, ydown, yup, sum;
 	double deltaE;
 
 	for (i = 0; i < LX*LY; i++)
 	{
  		x = randf()*LX;	/* Choose a random coordinate in the lattice */
  		y = randf()*LY;
  
  		xup = (x + 1)%LX;		/*determine neighbor sites, with periodic BCs */
  		xdown = (x + LX - 1)%LX;
  		yup = (y + 1)%LY;
  		ydown = (y + LY - 1)%LY;
 
  /*compute the sum of the spins of sites neighboring coordinate*/
  		sum = spin[xdown][y] + spin[xup][y] + spin[x][yup] + spin[x][ydown];
  
  /*compute change in energy if spin is flipped at coordinate*/
  		deltaE = 2.0*J*spin[x][y]*sum/(*T);
  		if (randf() < exp(-deltaE)) /* decide if flip is accepted*/
  		{
   			*m -= 2.0*spin[x][y]/(LX*LY); /*flip spin and compute m*/
   			spin[x][y] *= -1;
  		}
 	}
}
コード例 #8
0
ファイル: utils.cpp プロジェクト: Buanderie/gpufrustum
void generateRandomPyrFrustums( int n,
								float minFOV, float maxFOV,
								float minNear, float maxNear,
								float minFar, float maxFar,
								float minAspectRatio, float maxAspectRatio,
								float minPosX, float maxPosX,
								float minPosY, float maxPosY,
								float minPosZ, float maxPosZ,
								float minRotX, float maxRotX,
								float minRotY, float maxRotY,
								float minRotZ, float maxRotZ,
								std::vector<glPyramidalFrustum>& list )
{
	for(int i = 0; i < n; ++i )
	{
		float FOV = minFOV + randf()*( maxFOV - minFOV );
		float Near = minNear + randf()*( maxNear - minNear );
		float Far = minFar + randf()*( maxFar - minFar );
		float AspectRatio = minAspectRatio + randf()*( maxAspectRatio - minAspectRatio );
		float PosX = minPosX + randf()*( maxPosX - minPosX );
		float PosY = minPosY + randf()*( maxPosY - minPosY );
		float PosZ = minPosZ + randf()*( maxPosZ - minPosZ );
		float RotX = minRotX + randf()*( maxRotX - minRotX );
		float RotY = minRotY + randf()*( maxRotY - minRotY );
		float RotZ = minRotZ + randf()*( maxRotZ - minRotZ );
		glPyramidalFrustum f(FOV, Near, Far, AspectRatio, glVector4f(PosX, PosY, PosZ, 0), RotX, RotY, RotZ );
		list.push_back( f );
	}
}
コード例 #9
0
ファイル: demo.c プロジェクト: marcan/openlase
void cart_rnd_star(int id)
{
	float x = randf(2.0)-1.0;
	float y = randf(2.0)-1.0;
	stars[id][0] = sqrtf(x*x+y*y);
	stars[id][1] = atan2(y,x);
}
コード例 #10
0
ファイル: PowerUp.cpp プロジェクト: dradtke/battlechess
PowerUp::PowerUp(float x, float y, int type) :
   SPIN_SPEED(0.002f)
{
   this->x = x;
   this->y = y;
   this->type = type;

   dx = randf(0.5f, 1.2f);
   dy = randf(0.5f, 1.2f);
   radius = 16;
   isDestructable = false;
   hp = 1;

   da = (rand() % 2) ? -SPIN_SPEED : SPIN_SPEED;

   ResourceManager& rm = ResourceManager::getInstance();
   
   switch (type) {
      case POWERUP_LIFE:
         bitmap = (ALLEGRO_BITMAP *)rm.getData(RES_LIFEPOWERUP);
         break;
      default:
         type = POWERUP_WEAPON;
         bitmap = (ALLEGRO_BITMAP *)rm.getData(RES_WEAPONPOWERUP);
         break;
   }
}
コード例 #11
0
//get trigger position/volume relative to sound rects for single grain voice
void GrainClusterVis::getTriggerPos(unsigned int idx, double * playPos, double * playVol,float theDur)
{
    bool trigger = false;
    SoundRect * theRect = NULL;
    if (idx < myGrainsV->size()){
        GrainVis * theGrain = myGrainsV->at(idx);
        //TODO: motion models
        //updateGrainPosition(idx,gcX + randf()*50.0 + randf()*(-50.0),gcY + randf()*50.0 + randf()*(-50.0));
        updateGrainPosition(idx,gcX + (randf()*xRandExtent - randf()*xRandExtent),gcY + (randf()*yRandExtent - randf()*yRandExtent));
        for (int i = 0; i < theLandscape->size(); i++) {
            theRect = theLandscape->at(i);
            bool tempTrig = false;
            tempTrig = theRect->getNormedPosition(playPos,playVol,theGrain->getX(),theGrain->getY(),i);
            if (tempTrig == true)
                trigger = true;
            // cout << "playvol: " << *playPos << ", playpos: " << *playVol << endl;
            
        }
        if (trigger == true){
            theGrain->trigger(theDur);
        }
    }
    
    
}
コード例 #12
0
ファイル: main.cpp プロジェクト: ProkopHapala/cpp_arch
void setup(){

	map.init( 16, 14, 0.2 );

	printf( " %f \n", map.invStep );

/*
	Point2D* p = new Point2D( { 10.8, 13.9 } ); 
	printf( " p: %f %f \n",p->x,p->y );
	int ix,iy;
	map.boxIndex( p, ix, iy );
	printf( " ix,iy: %i %i \n",ix,iy );

*/

	for (int i=0; i<1000; i++){
		Point2D* p = new Point2D( { randf(0,2), randf(0,2) } );
		map.insert( p );
		//printf( " i:i0,ii,i0s[ii]  %i: %i %i %i \n", i, i0, ii, map.i0s[ii] );
	};

	map.makeStatic();


}
コード例 #13
0
TestApp::TestApp( int& id, int WIDTH_, int HEIGHT_ ) : AppSDL2OGL( id, WIDTH_, HEIGHT_ ) {

    //int power = 8; int nside = 5;
    //int power = 11; int nside = 20;
    int power = 16; int nside = 300;
    //int power = 20; int nside = 400;
    //int power = 24; int nside = 1500;


	npoints = 4*nside*nside;
	points  = new Vec2d[npoints];
    map.init( 0.5f, power );
	printf( "map: %i %i %i %i \n", map.power, map.mask, map.capacity, map.filled );
	int i = 0;
	for( int iy=-nside+1; iy<nside; iy++ ){
		for( int ix=-nside+1; ix<nside; ix++ ){
			i++;
			points[ i ].set( ( ix + randf() ) * map.step, ( iy + randf() ) * map.step );
			//map.insertNoTest( &(points[i]), points[i].x, points[i].y  );
			map.insertIfNew( &(points[i]), points[i].x, points[i].y  );
			//printf( " insering (%i,%i) %i (%3.3f,%3.3f) \n", ix, iy, i, points[i].x, points[i].y );
		};
	};
	printf( "map: %i %i %i %i \n", map.power, map.mask, map.capacity, map.filled );

	hist.init( 20, 0, 20 );
	for( int i=0; i<map.capacity; i++ ){
		hist.insert( map.fields[i].n + 0.5 );
	}
	printf( "now comes printHistogram( hist );\n" );
	printHistogram( hist );
}
コード例 #14
0
ファイル: main.cpp プロジェクト: BichengLUO/random_room
void random_points(point ps[], int count, double min, double max, bool integer)
{
	std::set<std::pair<int, int>> points_set;
	if (integer)
	{
		for (int i = 0; i < count; i++)
		{
			bool unique = true;
			int x, y;
			do
			{
				x = (int)round(min + (max - min) * randf());
				y = (int)round(min + (max - min) * randf());
				if (points_set.find(std::make_pair(x, y)) != points_set.end())
					unique = false;
			} while (!unique);
			ps[i] = point(x, y);
			points_set.insert(std::make_pair(x, y));
		}
	}
	else
	{
		for (int i = 0; i < count; i++)
			ps[i] = point(min + (max - min) * randf(), min + (max - min) * randf());
	}
}
コード例 #15
0
Path SplineGenerator::makeBezier(int points, int nodes, int seed)
{
    srand(seed);
    Path path;
    int minDist = 0.35355;
    std::cout << "MinDist: " << minDist << std::endl;
    Vector2d start(randf(),0);
    Vector2d end(randf(),1);

    for (int node=0 ; node < nodes ; ++node)
    {

        Vector2d p0 = start;
        Vector2d p1(randf(), randf());
//        Vector2d p1(rand()%w,rand()%h);
        Vector2d p2(randf(), randf());
        Vector2d p3(randf(), randf());
        while(p3.getDistance(p1)<minDist)
        {
            p3.x = randf();
            p3.y = randf();
        }

        int pointsPerNode = points / nodes;
        for (int x=0; x<pointsPerNode;++x)
        {
            float t = x/float(pointsPerNode);
            Vector2d res= calculateBezierPoint(t,p0,p1,p2,p3);
            path.push_back(res);
        }

        start = p3;
    }

    //do last link
//    Vector2d p0 = start;
//    Vector2d p1(rand()%w,rand()%h);
//    Vector2d p2(rand()%w,rand()%h);
//    Vector2d p3 = end;
//    for (int x=0; x<steps;++x)
//    {
//        float t = x/float(steps);
//        Vector2d res= calculateBezierPoint(t,p0,p1,p2,p3);
//        if (x!=0)
//        {
//            out << t << "\t" << res.x <<"\t" << res.y << std::endl;
//        }
//        else
//        {
//            out << t << "\t" << res.x <<"\t" << res.y << "\t" << start.x << "\t" << start.y << std::endl;
//        }
//    }




    //end test for bezier curving
    return path;
}
コード例 #16
0
ファイル: sample.cpp プロジェクト: morankim/midtermProject
static void startup_scene()
{
    // generate random starfield
    for ( int i=0; i < NUM_STARS; ++i )
    {
        star[i] = vec( randf(), randf(), randf() ).unit() * 2.0f;
    }
}
コード例 #17
0
void shake(void)
{
   shakeUpdateCount = SHAKE_TIME;
   bgx = randf(0.0f, 8.0f);
   bgy = randf(0.0f, 8.0f);
   if (rand() % 2) bgx = -bgx;
   if (rand() % 2) bgy = -bgy;
}
コード例 #18
0
ファイル: Mine.cpp プロジェクト: Mimoja/HookWars
glm::vec3 spawn() {
    glm::vec3 cand;
    do {
        cand = glm::vec3(randf(-10.0f, 10.0f), 2.0f, randf(-10.0f, 10.0f));
    } while (glm::length(circleCollision(cand, MINE_RADIUS, 4, true, true)) > 0.0f);

    return cand;
}
コード例 #19
0
ファイル: namibang.cpp プロジェクト: xuhao1/Rand_Walk
void collision(vector2f & vel,double&omega,double theta)
{
    double alpha=randf();
    double beta=randf()*M_PI;
    double v=water.mk().abs();
    omega+=12*(alpha-0.5)*v*beta/1000;
    vel+=v*cos(beta)/1000000*vector2f(cos(theta),sin(theta));
}
コード例 #20
0
ファイル: Gene.cpp プロジェクト: bog2k3/bugs
Gene Gene::createRandomSynapseGene(int nNeurons) {
	GeneSynapse g;
	g.from.set(randi(nNeurons-1));
	g.to.set(randi(nNeurons-1));
	g.weight.set(randf()*0.2f);
	g.priority.set(randf()*10);
	return g;
}
コード例 #21
0
void matrices2quats( int n ){
    glBegin   ( GL_POINTS   );
    for( int i=0; i<n; i++ ){
        Mat3f  M;   M.fromRand( {randf(),randf(),randf()} );
        Quat4f q;   q.fromMatrix(M);
        glVertex3f( (float)q.x, (float)q.y, (float)q.z );
    }
    glEnd();
}
コード例 #22
0
ファイル: ParticleDefines.cpp プロジェクト: carussell/nvvg
/// Returns a random vector within a cube
/// \return Random vector distributed within a cube
Vector3 ParticleUtil::getRandVecSolidCube()
{
  float
    x = 2.0f * (randf() - 0.5f),
    y = 2.0f * (randf() - 0.5f),
    z = 2.0f * (randf() - 0.5f);

  return Vector3(x, y, z);
}
コード例 #23
0
void MathInterface::functionRnd(void) {
	float high = cb->popValue().toFloat();
	float low = cb->popValue().toFloat();
	if (high < low) {
		cb->pushValue(randf() * low);
		return;
	}
	cb->pushValue(low + (randf() * (high - low)));
}
コード例 #24
0
void MultiFight3DWorld::fireProjectile( Warrior3D * w ) {
    Projectile3D * p = new Projectile3D();
    p->vel.set_mul( w->gun_rot, 10.0 );
    p->vel.add( w->vel );
    p->vel.add( { randf(-0.1,0.1), randf(-0.1,0.1), randf(-0.1,0.1) } );
    p->pos.set( w->pos );
    p->pos.add_mul( w->gun_rot, 5.0 );
    projectiles.push_back( p );
};
コード例 #25
0
ファイル: Tile.cpp プロジェクト: reima/sep3d
void Tile::Refine(int block_size, float roughness) {
  int block_size_h = block_size/2;
  float offset_factor = roughness * block_size / size_;

  for (int y = block_size_h; y < size_; y += block_size) {
    for (int x = block_size_h; x < size_; x += block_size) {
      // Lookup der umliegenden Höhenwerte (-); o ist Position (x, y)
      // -   -
      //   o
      // -   -
      float nw = vertices_[I(x - block_size_h, y - block_size_h)].y;
      float ne = vertices_[I(x + block_size_h, y - block_size_h)].y;
      float sw = vertices_[I(x - block_size_h, y + block_size_h)].y;
      float se = vertices_[I(x + block_size_h, y + block_size_h)].y;
      
      // Berechnung der neuen Höhenwerte (+)
      // - + -
      // + +
      // -   -
      float center = (nw + ne + sw + se) / 4 + offset_factor * randf();
      vertices_[I(x, y)].y = center;
      
      float n = nw + ne + center;
      if (y > block_size_h) {
        n += vertices_[I(x, y - block_size)].y;
        n /= 4;
      } else {
        n /= 3;
      }
      vertices_[I(x, y - block_size_h)].y = n + offset_factor * randf();

      float w = nw + sw + center;
      if (x > block_size_h) {
        w += vertices_[I(x - block_size, y)].y;
        w /= 4;
      } else {
        w /= 3;
      }
      vertices_[I(x - block_size_h, y)].y = w + offset_factor * randf();

      // Edge cases: Berechnung neuer Höhenwerte am rechten bzw. unteren Rand
      // -   -
      //     +
      // - + - 
      if (x == size_ - 1 - block_size_h) {
        vertices_[I(x + block_size_h, y)].y =
            (ne + se + center) / 3 + offset_factor * randf();
      }
      if (y == size_ - 1 - block_size_h) {
        vertices_[I(x, y + block_size_h)].y =
            (sw + se + center) / 3 + offset_factor * randf();
      }
    }
  } 
}
コード例 #26
0
ファイル: Tests.cpp プロジェクト: cielo523/tsp-pso
	void params_test() {
		float bestScore = MAX_FLOAT;
		float bestC1 = 0.0f;
		float bestC2 = 0.0f;
		float bestOMEGA = 0.0f;
		int bestREHOPE = 0;
		int bestIndex = -1;

		const int CHECKS = 20;
		const int MEAN = 20;
		// i sprawdzen losowych wartosci
		for(int i=0; i<CHECKS; i++) {
			std::cout << "Check " << i + 1 << " of " << CHECKS << std::endl;
			float C1 = randf(-1.9f, 1.9f);
			float C2 = randf(-1.9f, 1.9f);
			float OMEGA = randf(-1.9f, 1.9f);
			int REHOPE = ((rand() % 50) + 1) * 10;
			float avScore = 0.0f;
			float avScoreSA = 0.0f;
			float avScoreRS = 0.0f;
			// usrednienie dla j grafow
			for(int j=0; j<MEAN; j++) {
				Graph g(20, 1.0f, 10.0f);
				PSO::TspSwarm swarm(&g, g.V(), C1, C2, OMEGA, REHOPE);
				SA::SimulatedAnnealing sa(&g);
				RS::RandomSearch rnd(&g);
				swarm.compute(false);
				sa.compute(false);
				rnd.compute(false);
				avScore += swarm.getBestCost();
				avScoreSA += sa.getBestCost();
				avScoreRS += rnd.getBestCost();
			}
			avScore /= static_cast<float>(MEAN);
			avScoreSA /= static_cast<float>(MEAN);
			avScoreRS /= static_cast<float>(MEAN);
			std::cout << "Average score (" << MEAN << " checks): " << avScore << " (SA: " << avScoreSA 
				<< ", RS: " << avScoreRS << ")" << std::endl;
			if(avScore - avScoreSA < bestScore) {
				bestIndex = i + 1;
				bestScore = avScore - avScoreSA;
				bestC1 = C1;
				bestC2 = C2;
				bestOMEGA = OMEGA;
				bestREHOPE = REHOPE;
			}
		}
		std::cout << "Best index: " << bestIndex << std::endl;
		std::cout << "Best C1: " << bestC1 << std::endl;
		std::cout << "Best C2: " << bestC2 << std::endl;
		std::cout << "Best OMEGA: " << bestOMEGA << std::endl;
		std::cout << "Best REHOPE: " << bestREHOPE << std::endl;

		same_graphs_test(bestC1, bestC2, bestOMEGA, bestREHOPE);
	}
コード例 #27
0
// Helper function to keep code base small
void smatrixf_mul_bench(struct rusage *     _start,
                        struct rusage *     _finish,
                        unsigned long int * _num_iterations,
                        unsigned int        _n)
{
    // normalize number of iterations
    // time ~ _n ^ 3
    *_num_iterations /= _n * _n * _n;
    if (*_num_iterations < 1) *_num_iterations = 1;

    unsigned long int i;

    // generate random matrices
    smatrixf a = smatrixf_create(_n, _n);
    smatrixf b = smatrixf_create(_n, _n);
    smatrixf c = smatrixf_create(_n, _n);

    // number of random non-zero entries
    unsigned int nnz = _n / 20 < 4 ? 4 : _n / 20;

    // initialize _a
    for (i=0; i<nnz; i++) {
        unsigned int row = rand() % _n;
        unsigned int col = rand() % _n;
        float value      = randf();
        smatrixf_set(a, row, col, value);
    }
    
    // initialize _b
    for (i=0; i<nnz; i++) {
        unsigned int row = rand() % _n;
        unsigned int col = rand() % _n;
        float value      = randf();
        smatrixf_set(b, row, col, value);
    }

    // initialize c with first multiplication
    smatrixf_mul(a,b,c);

    // start trials
    getrusage(RUSAGE_SELF, _start);
    for (i=0; i<(*_num_iterations); i++) {
        smatrixf_mul(a,b,c);
        smatrixf_mul(a,b,c);
        smatrixf_mul(a,b,c);
        smatrixf_mul(a,b,c);
    }
    getrusage(RUSAGE_SELF, _finish);
    *_num_iterations *= 4;

    // free smatrix objects
    smatrixf_destroy(a);
    smatrixf_destroy(b);
    smatrixf_destroy(c);
}
コード例 #28
0
ファイル: _interface.cpp プロジェクト: Dzshiftt/Gnomescroll
//call after type or subtype changes
static bool update_mech(struct Mech &m)
{
    class MechAttribute* ma = get_mech_attributes(m.type);
    m.render_type = ma->render_type;

    float size = get_mech_size(m.type);

    m.rotation = 0.0f;
    m.offset = 0;
    m.offset_x = 0.0f;
    m.offset_y = 0.0f;

    switch (ma->class_type)
    {
        case MECH_CRYSTAL:
            //do something
            //m.render_type = ma->render_type;
            m.rotation = 0.25f*(rand()%4) + 0.25f*randf()/3;

            //m.rotation = 0.0f;
            m.offset = rand()%255;
            //m.subtype = rand()%6;

            m.offset_x = (randf()-0.5f)* (1.0f-size);
            m.offset_y = (randf()-0.5f)* (1.0f-size);

            m.offset_x = 0.0f;
            m.offset_y = 0.0f;
            break;

        case MECH_CROP:
        case MECH_MYCELIUM:
            break;

        case MECH_SIGN:
            break;

        case MECH_WALL_OBJECT:
            m.rotation = 0.0f;
            m.offset = 0;
            m.offset_x = 0.0f;
            m.offset_y = 0.0f;
            break;

        case MECH_WIRE:
        case MECH_SWITCH:
        case NULL_MECH_CLASS:
            GS_ASSERT(false);
            return false;
    }

    m.center = get_mech_center(m);

    return true;
}
コード例 #29
0
void SimulationManager::createMarkerParticles() {
	ASSERT(SIMULATION->markerParticles.size() == 0, "No particles have been created already");
	for (unsigned int i = 0; i < NUMBER_OF_MARKER_PARTICLES; ++i) {
		MarkerParticle* markerParticle = new MarkerParticle();
		markerParticle->position = glm::vec3(randf() * g_initialCubeSize, 2.0f + randf() * g_initialCubeSize, randf() * g_initialCubeSize);

		SIMULATION->markerParticles.push_back(markerParticle);
	}

	this->initShaderAttributeVectors();
}
コード例 #30
0
int Test(std::vector<int>& testMap, CRectangleOptimizer& ro)
{
	//! clear testMap
	testMap.resize(size * size, 0);

	//! create random rectangles
	ro.clear();
	for (int i=0; i<count_rects; ++i) {
		SRectangle r(0,0,0,0);
		r.x1 = randf() * (size-1);
		r.z1 = randf() * (size-1);
		r.x2 = randf() * (size-1);
		r.z2 = randf() * (size-1);
		if (r.x1 > r.x2) std::swap(r.x1, r.x2);
		if (r.z1 > r.z2) std::swap(r.z1, r.z2);
		ro.push_back(r);
	}

	//! fill testMap with original areas
	for (CRectangleOptimizer::iterator it = ro.begin(); it != ro.end(); ++it) {
		const SRectangle& rect = *it;
		for (int z=rect.z1; z<rect.z2; ++z) { //FIXME <=
			for (int x=rect.x1; x<rect.x2; ++x) { //FIXME <=
				testMap[z * size + x] = 1;
			}
		}
	}

	//! optimize
	ro.Optimize();

	//! fill testMap with optimized
	for (CRectangleOptimizer::iterator it = ro.begin(); it != ro.end(); ++it) {
		const SRectangle& rect = *it;
		for (int z=rect.z1; z<rect.z2; ++z) { //FIXME <=
			for (int x=rect.x1; x<rect.x2; ++x) { //FIXME <=
				testMap[z * size + x] -= 1;
			}
		}
	}

	//! check if we have overlapping or missing areas
	int sum = 0;
	for (int y=0; y<size; ++y) {
		for (int x=0; x<size; ++x) {
			sum += testMap[y * size + x];
		}
	}

	//! sum should be zero
	//! in case of <0: the optimized rectangles still overlap
	//! in case of >0: the optimized rectangles don't cover the same area as the unoptimized did
	return sum;
}