Example #1
0
inline Colour 
operator +(const Colour& a, 
           const Colour& b)
{
   return Colour(min(a.red() + b.red(), 1.0),
                 min(a.green() + b.green(), 1.0),
                 min(a.blue() + b.blue(), 1.0));
};
Example #2
0
inline Colour
operator *(double s, 
           const Colour& a)
{
   return Colour(min(s * a.red(), 1.0),
                 min(s * a.green(), 1.0),
                 min(s * a.blue(), 1.0));
};
Example #3
0
Colour::Colour(const Colour& colour)
{
	m_colour.resize(4);
	m_colour[0] = colour.red();
	m_colour[1] = colour.green();
	m_colour[2] = colour.blue();
	m_colour[3] = uint(255 * colour.alpha() + 0.5f);
}
Example #4
0
// boundColour: Colour Int Int -> Colour
// Bounds a colour to be values between the min and max. If less than the
// min, it makes the value the min, and likewise if it's more than the
// max, it makes the value max.
Colour boundColour(Colour col, int min, int max) {
   int tred = col.red();
   int tgreen = col.green();
   int tblue = col.blue();

   if (tred < min)                 tred = min;
   else if (tred > max)    tred = max;
        
   if (tgreen < min)               tgreen = min;
   else if (tgreen > max)  tgreen = max;

   if (tblue < min)                tblue = min;
   else if (tblue > max)   tblue = max;

   return Colour(tred,tgreen,tblue);
}
Example #5
0
void Evaluate_Density_Pigment(const PIGMENT *pigm, const Vector3d& p, RGBColour& c, TraceThreadData *ttd)
{
	Colour lc;

	c.set(1.0);

	while(pigm != NULL)
	{
		lc.clear();

		Compute_Pigment(lc, pigm, *p, NULL, NULL, ttd);

		c.red()   *= lc.red();
		c.green() *= lc.green();
		c.blue()  *= lc.blue();

		pigm = reinterpret_cast<const PIGMENT *>(pigm->Next);
	}
}
Example #6
0
std::vector<Vertex>	GlassGlobe::_create_vertices( const float radius , const unsigned int slices , const unsigned int stacks , const Colour& colour )
{
	unsigned int	counter = 0;
	Vertex			vertex;
	vector<Vertex>	returnValue( (slices+1) * (stacks+1) + 1 );
	

	
	vertex._position[0] = 0.0f;
	vertex._position[1] = radius;
	vertex._position[2] = 0.0f;
	vertex._normal[0] = 0.0f;
	vertex._normal[1] = 1.0f;
	vertex._normal[2] = 0.0f;
	vertex._colour[0] = colour.red();
	vertex._colour[1] = colour.green();
	vertex._colour[2] = colour.blue();
	vertex._colour[3] = colour.alpha();
	vertex._texture[0] = 0.0f;
	vertex._texture[1] = 1.0f;
	vertex._texture[2] = 0.0f;
	returnValue[counter++] = vertex;

	
	for ( unsigned int i = 1;  i <= (stacks);  ++i )
	{
		float	angle = GlassGlobe::_PI * 0.5f* (1.0f - static_cast<float>(i)/static_cast<float>(stacks));
		float	y = sin(angle);
		float	rad = cos(angle);
		float	tex = 1.0f - static_cast<float>(i)/static_cast<float>(stacks+1);



		for ( unsigned int j = 0;  j <= slices;  ++j )
		{
			float		ang =  GlassGlobe::_PI * 2.0f * static_cast<float>(j) / static_cast<float>(slices);
			float		x  = cos(ang);
			float		z = -sin(ang);
			Vector3f	normal(rad*x,y,rad*z);



			
			vertex._position[0] = radius*normal.x();
			vertex._position[1] = radius*normal.y();
			vertex._position[2] = radius*normal.z();
			normal.normalize();
			vertex._normal[0] = normal.x();
			vertex._normal[1] = normal.y();
			vertex._normal[2] = normal.z();
			vertex._texture[0] = static_cast<float>(j) / static_cast<float>(slices);
			vertex._texture[1] = tex;
			vertex._texture[2] = 0.0f;
			returnValue[counter++] = vertex;
		}
	}
	
	for ( unsigned int j = 0;  j <= slices;  ++j )
	{
		float		ang =  GlassGlobe::_PI * 2.0f * static_cast<float>(j) / static_cast<float>(slices);
		float		x  = cos(ang);
		float		z = -sin(ang);
		Vector3f	normal(x,0.0f,z);



		normal.normalize();
		vertex._position[0] = radius*x;
		vertex._position[1] = -radius*0.1f;
		vertex._position[2] = radius*z;
		vertex._normal[0] = normal.x();
		vertex._normal[1] = normal.y();
		vertex._normal[2] = normal.z();
		vertex._texture[0] = static_cast<float>(j) / static_cast<float>(slices);
		vertex._texture[1] = 0.0f;
		vertex._texture[2] = 0.0f;
		returnValue[counter++] = vertex;
	}


	return returnValue;
};
Example #7
0
vector<Vertex>	Pool::_create_vertices(  const unsigned int stacks , const unsigned int slices , const unsigned int height_stacks , const float a , const float b , const float height , const Vector3f& position , const Vector3f& terrain_position , const float radius , const Colour& colour )
{
	unsigned int	counter = 0;
	unsigned int	side_offset = height_stacks*((slices+1)*stacks+1) /*+ 1*/;
	Vertex			vertex;
	vector<Vertex>	returnValue( height_stacks * ((slices+1)*stacks + 1 + (slices+1))/* + 1*/ );



	for ( unsigned int k = 0;  k < height_stacks;  ++k )
	{
		float	angle = Pool::_PI * 0.5f* static_cast<float>(k)/static_cast<float>(height_stacks);
		float	y = sin(angle);
		float	rad = 1.0f - static_cast<float>(k)/static_cast<float>(height_stacks); //cos(angle);




		vertex._position[0] = 0.0f;
		vertex._position[1] = -height * y;
		vertex._position[2] = 0.0f;
		vertex._normal[0] = 0.0f;
		vertex._normal[1] = 1.0f;
		vertex._normal[2] = 0.0f;
		vertex._colour[0] = colour.red();
		vertex._colour[1] = colour.green();
		vertex._colour[2] = colour.blue();
		vertex._colour[3] = colour.alpha();
		vertex._texture[0] = 0.5f;
		vertex._texture[1] = 0.5f;
		vertex._texture[2] = 0.0f;
		returnValue[counter++] = vertex;


		for ( unsigned int i = 1;  i <= stacks;  ++i )
		{
			float	temp_a = a * static_cast<float>(i) / static_cast<float>(stacks);
			float	temp_b = b * static_cast<float>(i) / static_cast<float>(stacks);



			for( unsigned int j = 0;  j <= slices;  ++j )
			{
				float	angle = Pool::_PI * 2.0f * static_cast<float>(j)/static_cast<float>(slices);
				float	x = cos(angle);
				float	z = -sin(angle);
				float	x_coef = rad*temp_a*x;
				float	z_coef = rad*temp_b*z;



				if ( sqrt( pow( (position.x() + x_coef) - terrain_position.x(),2) + pow( (position.z() + z_coef) - terrain_position.z(),2) ) < (radius+_EPSILON) )
				{
					vertex._position[0] = x_coef;
					vertex._position[2] = z_coef;
				}
				else
				{
					Vector3f	x_axis(radius,0,0);
					Vector3f	temp_position(position.x() + x_coef - terrain_position.x(),0,position.z() + z_coef - terrain_position.z());
					float		dot_product = temp_position * x_axis;



					vertex._position[0] = radius*dot_product;
					vertex._position[2] = radius*(sqrt(1-pow(dot_product,2)));
				}

				
				vertex._position[1] = -height * y;
				vertex._normal[0] = 0.0f;
				vertex._normal[1] = 1.0f;
				vertex._normal[2] = 0.0f;
				vertex._texture[0] = 0.5f * (1 + x*static_cast<float>(i)/static_cast<float>(stacks));
				vertex._texture[1] = 0.5f * (1 + z*static_cast<float>(i)/static_cast<float>(stacks));
				returnValue[counter++] = vertex;

				if ( i == stacks )
				{
					vertex._normal[0] = x;
					vertex._normal[1] = 0.0f;
					vertex._normal[2] = z;
					vertex._texture[0] = static_cast<float>(j)/static_cast<float>(slices);
					vertex._texture[1] = y;
					returnValue[side_offset + k*(slices+1) + j] = vertex;
				}
			}
		}
	}

	/*vertex._position[0] = 0.0f;
	vertex._position[1] = -height;
	vertex._position[2] = 0.0f;
	vertex._normal[0] = 0.0f;
	vertex._normal[1] = -1.0f;
	vertex._normal[2] = 0.0f;
	vertex._texture[0] = 0.5f;
	vertex._texture[1] = 0.5f;
	vertex._texture[2] = 1.0f;
	returnValue[counter] = vertex;*/


	return returnValue;
};