Example #1
0
void LoadTexture()
{
  static GLubyte imageData[64][64][3];
  for(int i=0;i<64;i++){
    for(int j=0;j<64;j++){
      float x= 255*fastsqrt((i-32)*(i-32)+(j-32)*(j-32))/32;

      // several formulas have been tested, the better is the "hyperbole"
      //x= 200*(sin(x/56)/(x/56)+0.23);
      //x= 35000*(1/(x+100)-0.0025);
      x=15000*(1/(x+50)-0.003);
      if(x<0)
		x=0;
      imageData[i][j][0]= (GLubyte)x;
      imageData[i][j][1]= (GLubyte)x;
      imageData[i][j][2]= (GLubyte)x;
      
    }
  }
  // Create Texture	
  glGenTextures(1, &texture[0]);
  glBindTexture(GL_TEXTURE_2D, texture[0]);   // 2d texture (x and y size)

  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MAG_FILTER,GL_LINEAR); // scale linearly when image bigger than texture
  glTexParameteri(GL_TEXTURE_2D,GL_TEXTURE_MIN_FILTER,GL_LINEAR); // scale linearly when image smalled than texture
  
  // 2d texture, level of detail 0 (normal), 3 components (red, green, blue), x size from image, y size from image, 
  // border 0 (normal), rgb color data, unsigned byte data, and finally the data itself.
  glTexImage2D(GL_TEXTURE_2D, 0, 3, 64, 64, 0, GL_RGB, GL_UNSIGNED_BYTE,&imageData[0][0][0] );

}
Example #2
0
	CandleEffect::CandleEffect(EyeCandy* _base, bool* _dead, Vec3* _pos,
		const color_t _hue_adjust, const color_t _saturation_adjust,
		const float _scale, const Uint16 _LOD)
	{
		if (EC_DEBUG)
			std::cout << "CandleEffect (" << this << ") created." << std::endl;
		base = _base;
		dead = _dead, pos = _pos;
		hue_adjust = _hue_adjust;
		saturation_adjust = _saturation_adjust;
		scale = _scale;
		sqrt_scale = fastsqrt(scale);
		LOD = base->last_forced_LOD;
		desired_LOD = _LOD;
		bounds = NULL;
		mover = new SmokeMover(this, sqrt_scale);
		spawner = new FilledSphereSpawner(0.015 * sqrt_scale);
	}
Example #3
0
void beatdetector::learnbeat(float data[3][256])
{
	filterpower=0;
	for(int i = 0; i < NUM_BANDS; i++)
	{
		float y0, y1;
		uint16_t f = i<128 ? (i-128) :0;
		f = f*f/100;
		f = f*f/30;
		y0 =  data[0][i];
		y1 =  data[1][i];
		y0*=y0;
		y1*=y1;
		y0 = (int)fastsqrt(y0+y1);

		filter[i] = (filter[i]*48 + f + ((y0)-filter2[i]))/50 ;
		filterpower+=filter[i];
	}
}
Example #4
0
	bool CloudParticle::idle(const Uint64 delta_t)
	{
		if (effect->recall)
			return false;

		if (base->particles.size() > 1)
		{
			if ((pos - base->center).magnitude_squared()
				> MAX_DRAW_DISTANCE_SQUARED)
			{
				//Find everything that sees this as a neighbor and delete the references to this.
				for (std::vector<CloudParticle*>::iterator iter =
					incoming_neighbors.begin(); iter
					!= incoming_neighbors.end(); iter++)
					(*iter)->remove_neighbor(this);
				for (std::vector<CloudParticle*>::iterator iter =
					neighbors.begin(); iter != neighbors.end(); iter++)
					(*iter)->remove_incoming_neighbor(this);
				return false;
			}
		}

		Vec3 velocity_shift;
		velocity_shift.randomize();
		velocity_shift.y /= 3;
		velocity_shift.normalize(0.00002 * fastsqrt(delta_t));
		velocity += velocity_shift;
		const coord_t magnitude = velocity.magnitude();
		if (magnitude > 0.15)
			velocity /= (magnitude / 0.15);

		if (fabs(velocity.y) > 0.1)
			velocity.y *= math_cache.powf_05_close(delta_t / 300000.0);

		if (pos.y - size / 40 < min_height)
			velocity.y += delta_t / 500000.0;

		if (pos.y + size / 40 > max_height)
			velocity.y -= delta_t / 2500000.0;

		if (effect->particles.size() <= 1)
			return true;

		if (!neighbors.size())
		{
			std::map<Particle*, bool>::iterator next_iter;
			int offset;
			CloudParticle* next;
			while (true)
			{
				next_iter = effect->particles.begin();
				offset = randint((int)effect->particles.size());
				for (int j = 0; j < offset; j++)
					next_iter++;
				next = (CloudParticle*)next_iter->first;
				if (next != this)
					break;
			}
			neighbors.push_back(next);
			next->add_incoming_neighbor(this);
		}

		// Adjust our neighbors -- try a few points to see if they're closer.
		// First, create the map

		CloudEffect* eff = (CloudEffect*)effect;
		std::map<coord_t, CloudParticle*> neighbors_map;
		for (int i = 0; i < (int)neighbors.size(); i++)
		{
			const coord_t distsquared = (neighbors[i]->pos - pos).magnitude_squared();
			neighbors_map[distsquared] = neighbors[i];
		}

		// Now, try to replace elements.
		coord_t maxdist = neighbors_map.rbegin()->first;
		for (int i = 0; (i < 1) || ((neighbors_map.size() < 20) && (i < 40)); i++)
		{
			std::map<Particle*, bool>::iterator iter;
			int offset;
			CloudParticle* neighbor;
			while (true)
			{
				iter = eff->particles.begin();
				offset = randint((int)eff->particles.size());
				for (int j = 0; j < offset; j++)
					iter++;
				neighbor = (CloudParticle*)iter->first;
				if (neighbor != this)
					break;
			}
			const coord_t distsquared = (neighbor->pos - pos).magnitude_squared();
			if (neighbors_map.size() >= 20)
			{
				if (distsquared > maxdist)
					continue;
				if (neighbors_map.count(distsquared))
					continue;
			}
			if (neighbors_map.size() >= 20)
			{
				std::map<coord_t, CloudParticle*>::iterator iter =
					neighbors_map.begin();
				for (int j = 0; j < (int)neighbors_map.size() - 1; j++)
					iter++;
				neighbors_map.erase(iter);
			}
			neighbors_map[distsquared] = neighbor;
			maxdist = neighbors_map.rbegin()->first;
		}

		// Set our color based on how deep into the cloud we are, based on our neighbors.  Also rebuild the neighbors vector.
		coord_t distsquaredsum = 0;
		Vec3 centerpoint(0.0, 0.0, 0.0);
		for (std::vector<CloudParticle*>::iterator iter = neighbors.begin(); iter
			!= neighbors.end(); iter++)
			(*iter)->remove_incoming_neighbor(this);
		neighbors.clear();

		for (std::map<coord_t, CloudParticle*>::iterator iter =
			neighbors_map.begin(); iter != neighbors_map.end(); iter++)
		{
			distsquaredsum += iter->first;
			centerpoint += iter->second->pos; //Should really be (pos - iter->second->pos); will correct this below for speed.
			neighbors.push_back(iter->second);
			iter->second->add_incoming_neighbor(this);
		}
		centerpoint = (pos * 20) - centerpoint;
		Vec3 new_normal = centerpoint;
		const coord_t magnitude_squared = centerpoint.magnitude_squared();
		const coord_t scale= fastsqrt(magnitude_squared);
		new_normal /= scale; // Normalize
		//  light_t new_brightness = 1.0 - (25.0 / (scale + 50.0));
		//  new_normal.x = (new_normal.x < 0 ? -1 : 1) * math_cache.powf_0_1_rough_close(fabs(new_normal.x), new_brightness * 2.0 - 1.0);
		//  new_normal.y = (new_normal.y < 0 ? -1 : 1) * math_cache.powf_0_1_rough_close(fabs(new_normal.y), new_brightness * 2.0 - 1.0);
		//  new_normal.z = (new_normal.z < 0 ? -1 : 1) * math_cache.powf_0_1_rough_close(fabs(new_normal.z), new_brightness * 2.0 - 1.0);
		const percent_t change_rate = math_cache.powf_05_close(delta_t
			/ 2000000.0);
		normal = normal * change_rate + new_normal * (1.0 - change_rate);
		normal.normalize();
		//  color[0] = color[0] * change_rate + new_brightness * (1.0 - change_rate);
		//  color[1] = color[0];
		//  color[2] = color[0];
		//  std::cout << "  " << centerpoint << std::endl;
		//  std::cout << "  " << normal << std::endl;
		//  std::cout << "  " << brightness << std::endl;

		return true;
	}