Example #1
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 #2
0
void Line::draw(Image& image, const Colour& colour, bool bAntialiased)
{
	if(bAntialiased)
	{
		std::vector<Point> pts;
		std::vector<float> alpha;
		lineWu(m_start.xInt(), m_start.yInt(), m_end.xInt(), m_end.yInt(), pts, alpha);

		for(uint i = 0; i < pts.size(); ++i)
			image.draw_point(pts[i].xInt(), pts[i].yInt(), 0, colour.colour(), colour.alpha()*alpha[i]);
	}
	else
	{
		std::vector<Point> pts = points();
		for(uint i = 0; i < pts.size(); ++i)
			image.draw_point(pts[i].xInt(), pts[i].yInt(), 0, colour.colour());
	}
}
Example #3
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 #4
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;
};