Пример #1
0
void get_cloud_3d_sector ( float x, float z, int *sectorx, int *sectorz )
{

	convert_float_to_int ( ( x / CLOUD_3D_SECTOR_SIDE_LENGTH ), sectorx );

	convert_float_to_int ( ( z / CLOUD_3D_SECTOR_SIDE_LENGTH ), sectorz );
}
Пример #2
0
void get_2d_int_screen_coordinates (const float wx, const float wy, int *x, int *y)
{
	float
		xt,
		yt;

	int
		xi,
		yi;

	ASSERT (active_2d_environment);

	validate_2d_composite_transformation_matrix (active_2d_environment);

	xt = (wx * active_2d_environment->composite_transformation[0][0]) +
		  (wy * active_2d_environment->composite_transformation[1][0]) +
		  active_2d_environment->composite_transformation[2][0];

	yt = (wx * active_2d_environment->composite_transformation[0][1]) +
		  (wy * active_2d_environment->composite_transformation[1][1]) +
		  active_2d_environment->composite_transformation[2][1];

	convert_float_to_int (xt, &xi);
	convert_float_to_int (yt, &yi);

	*x = xi;

	*y = yi;
}
Пример #3
0
void set_2d_pixel (float x, float y, const rgb_colour col)
{
	float
		xt,
		yt;

	int
		xi,
		yi;

	ASSERT (active_2d_environment);

	validate_2d_composite_transformation_matrix (active_2d_environment);

	xt = (x * active_2d_environment->composite_transformation[0][0]) +
		  (y * active_2d_environment->composite_transformation[1][0]) +
		  active_2d_environment->composite_transformation[2][0];

	yt = (x * active_2d_environment->composite_transformation[0][1]) +
		  (y * active_2d_environment->composite_transformation[1][1]) +
		  active_2d_environment->composite_transformation[2][1];

	xt += active_2d_environment->offset_x * active_2d_environment->window_scaling[0][0] * 0.9;
	yt -= active_2d_environment->offset_y * active_2d_environment->window_scaling[1][1] * 0.9;

	convert_float_to_int (xt, &xi);
	convert_float_to_int (yt, &yi);

	set_clipped_pixel (xi, yi, col);
}
Пример #4
0
static void light_missile_approaching_lamps (float time_to_impact)
{
	int
		segment;

	if (time_to_impact < 15.0)
	{
		convert_float_to_int (15.0 - time_to_impact, &segment);

		ASSERT ((segment >= 0) && (segment <= 14));

		switch (segment)
		{
			case 14: hind_lamps.threat_warning_close_range_15 = 1;
			case 13: hind_lamps.threat_warning_close_range_14 = 1;
			case 12: hind_lamps.threat_warning_close_range_13 = 1;
			case 11: hind_lamps.threat_warning_close_range_12 = 1;
			case 10: hind_lamps.threat_warning_close_range_11 = 1;
			case  9: hind_lamps.threat_warning_close_range_10 = 1;
			case  8: hind_lamps.threat_warning_close_range_9 = 1;
			case  7: hind_lamps.threat_warning_close_range_8 = 1;
			case  6: hind_lamps.threat_warning_close_range_7 = 1;
			case  5: hind_lamps.threat_warning_close_range_6 = 1;
			case  4: hind_lamps.threat_warning_close_range_5 = 1;
			case  3: hind_lamps.threat_warning_close_range_4 = 1;
			case  2: hind_lamps.threat_warning_close_range_3 = 1;
			case  1: hind_lamps.threat_warning_close_range_2 = 1;
			case  0: hind_lamps.threat_warning_close_range_1 = 1;
		}
	}
}
Пример #5
0
int get_integer_screen_height (void)
{
	int
		result;

	convert_float_to_int (full_screen_height, &result);

	return result;
}
Пример #6
0
int get_integer_screen_x_mid (void)
{
	int
		result;

	convert_float_to_int (full_screen_x_mid, &result);

	return result;
}
Пример #7
0
int get_integer_screen_y_max (void)
{
	int
		result;

	convert_float_to_int (full_screen_y_max, &result);

	return result;
}
Пример #8
0
int get_integer_screen_width (void)
{
	int
		result;

	convert_float_to_int (full_screen_width, &result);

	return result;
}
Пример #9
0
float fast_modf ( float value, float *iptr )
{

	int
		whole_value;

	convert_float_to_int ( value, &whole_value );

	value -= whole_value;

	*iptr = ( float ) whole_value;

	return ( value );
}
Пример #10
0
void get_digital_clock_int_values (float time_of_day, int *hours, int *minutes, int *seconds)
{
	int
		seconds_past_midnight,
		minutes_past_midnight,
		hours_past_midnight;

//	time_of_day = bound (time_of_day, 0.0, ONE_DAY - 1.0);

	convert_float_to_int (time_of_day, &seconds_past_midnight);

	hours_past_midnight = seconds_past_midnight / ONE_HOUR;

	minutes_past_midnight = seconds_past_midnight / ONE_MINUTE;

	*hours = hours_past_midnight;

	*minutes = (minutes_past_midnight - (hours_past_midnight * MINUTES_IN_AN_HOUR));

	*seconds = (seconds_past_midnight - (minutes_past_midnight * SECONDS_IN_A_MINUTE));
}
Пример #11
0
void get_digital_countdown_values (float time_remaining, int *days, int *hours, int *minutes, int *seconds)
{
	int
		d, h, m, s;

	convert_float_to_int (time_remaining, &s);

	d = s / ONE_DAY;

	h = s / ONE_HOUR;

	m = s / ONE_MINUTE;

	if (days) *days = d;

	if (hours) *hours = h - (d * HOURS_IN_A_DAY);

	if (minutes) *minutes = m - (h * MINUTES_IN_AN_HOUR);

	if (seconds) *seconds = s - (m * SECONDS_IN_A_MINUTE);
}
Пример #12
0
void draw_3d_lightning_cloud_burst ( lightning_strike *strike )
{

	vertex
		*polygon,
		*vert,
		quad[4];

	float
		width,
		depth,
		intensity;

	vec3d
		relative_position;

	int
		int_intensity,
		outcode,
		outcode2;

	screen
		*texture;

	texture = system_textures[lightning_cloud_texture];

	width = 30000;
	depth = 30000;

	if ( !strike->current_frame_number )
	{

		intensity = 0.5;
	}
	else
	{

		intensity = 1.0 / ( ( float ) strike->current_frame_number );
	}

	intensity /= 3;

	quad[0].next_vertex = &quad[1];
	quad[1].next_vertex = &quad[2];
	quad[2].next_vertex = &quad[3];
	quad[3].next_vertex = NULL;

	quad[0].x = -width/2;
	quad[0].y = 0;
	quad[0].z = -depth/2;
	quad[0].u = 0;
	quad[0].v = 0;

	quad[1].x = width/2;
	quad[1].y = 0;
	quad[1].z = -depth/2;
	quad[1].u = 1;
	quad[1].v = 0;

	quad[2].x = width/2;
	quad[2].y = 0;
	quad[2].z = depth/2;
	quad[2].u = 1;
	quad[2].v = 1;

	quad[3].x = -width/2;
	quad[3].y = 0;
	quad[3].z = depth/2;
	quad[3].u = 0;
	quad[3].v = 1;

	polygon = quad;

	//
	// Calculate the relative position of the lightning strike
	//

	relative_position.x = (	( strike->position.x - visual_3d_vp->x ) * visual_3d_vp->xv.x +
									( strike->position.y - visual_3d_vp->y ) * visual_3d_vp->xv.y +
									( strike->position.z - visual_3d_vp->z ) * visual_3d_vp->xv.z );

	relative_position.y = (	( strike->position.x - visual_3d_vp->x ) * visual_3d_vp->yv.x +
									( strike->position.y - visual_3d_vp->y ) * visual_3d_vp->yv.y +
									( strike->position.z - visual_3d_vp->z ) * visual_3d_vp->yv.z );

	relative_position.z = (	( strike->position.x - visual_3d_vp->x ) * visual_3d_vp->zv.x +
									( strike->position.y - visual_3d_vp->y ) * visual_3d_vp->zv.y +
									( strike->position.z - visual_3d_vp->z ) * visual_3d_vp->zv.z );

	{

		//
		// Rotate the polygon around to the users viewpoint
		//
	
		vert = polygon;
	
		rotation_3d[0][0] = ( visual_3d_vp->xv.x );
		rotation_3d[0][1] = ( visual_3d_vp->yv.x );
		rotation_3d[0][2] = ( visual_3d_vp->zv.x );
	
		rotation_3d[1][0] = ( visual_3d_vp->xv.y );
		rotation_3d[1][1] = ( visual_3d_vp->yv.y );
		rotation_3d[1][2] = ( visual_3d_vp->zv.y );
	
		rotation_3d[2][0] = ( visual_3d_vp->xv.z );
		rotation_3d[2][1] = ( visual_3d_vp->yv.z );
		rotation_3d[2][2] = ( visual_3d_vp->zv.z );

		outcode = 0;

		outcode2 = CLIP_LEFT | CLIP_RIGHT | CLIP_TOP | CLIP_BOTTOM | CLIP_HITHER | CLIP_YONDER;

		clip_3d_coord = 0;

		while ( vert )
		{
	
			float
				x,
				y,
				z;
	
			x = vert->x * rotation_3d[0][0] + vert->y * rotation_3d[1][0] + vert->z * rotation_3d[2][0] + relative_position.x;
			y = vert->x * rotation_3d[0][1] + vert->y * rotation_3d[1][1] + vert->z * rotation_3d[2][1] + relative_position.y;
			z = vert->x * rotation_3d[0][2] + vert->y * rotation_3d[1][2] + vert->z * rotation_3d[2][2] + relative_position.z;

			x *= active_3d_environment->screen_i_scale;
			y *= active_3d_environment->screen_j_scale;

			if ( *( ( int * ) &z ) >= *( ( int * ) &clip_hither ) )
			{
	
				float
					q,
					i,
					j;
	
				float
					oxmax,
					oxmin,
					oymax,
					oymin;
			
				int
					ixmax,
					ixmin,
					iymax,
					iymin;
			
				q = 1.0 / z;
	
				vert->x = x;
				vert->y = y;
				vert->z = z;
				vert->q = q;
	
				i = ( x * q );
				j = ( y * q );
	
				vert->j = active_3d_environment->y_origin - j;
				vert->i = active_3d_environment->x_origin + i;
	
				oxmax = active_viewport.x_max - vert->i;
				oxmin = vert->i - active_viewport.x_min;
				oymax = active_viewport.y_max - vert->j;
				oymin = vert->j - active_viewport.y_min;
			
				ixmax = *( ( int * ) &oxmax );
				ixmin = *( ( int * ) &oxmin );
				iymax = *( ( int * ) &oymax );
				iymin = *( ( int * ) &oymin );
			
				vert->outcode = generate_lookup_outcode ( ixmin, iymin, ixmax, iymax );

				outcode |= vert->outcode;
				outcode2 &= vert->outcode;
			}
			else
			{
	
				vert->outcode = CLIP_HITHER;
				vert->z = z;
				vert->x = x;
				vert->y = y;

				outcode |= vert->outcode;
				outcode2 &= vert->outcode;
			}
	
			vert = vert->next_vertex;
		}

		if ( outcode2 )
		{

			return;
		}


		if ( outcode & CLIP_HITHER )
		{
	
			polygon = hither_clip_3d_polygon ( polygon, &outcode );

			if ( !polygon )
			{

				return;
			}
		}
	
		if ( outcode )
		{

			apply_perspective_to_polygon_texture ( polygon );
			
			polygon = clip_3d_polygon ( polygon, outcode );

			if ( !polygon )
			{

				return;
			}

			remove_perspective_from_polygon_texture ( polygon );
		}

		{

			real_colour
				colour,
				specular;

			set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, TRUE, FALSE );

			convert_float_to_int ( intensity * 255, &int_intensity );

			colour.red = int_intensity;
			colour.green = int_intensity;
			colour.blue = int_intensity;
			colour.alpha = int_intensity;

			set_d3d_texture ( 0, texture );
			set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );
			set_d3d_texture_stage_state ( 1, D3DTSS_COLOROP, D3DTOP_DISABLE );
	
			set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE );
			set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE );
			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSU, D3DTADDRESS_CLAMP );
			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSV, D3DTADDRESS_CLAMP );
			set_d3d_texture_stage_state ( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
			set_d3d_texture_stage_state ( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
			set_d3d_texture_stage_state ( 0, D3DTSS_MIPFILTER, D3DTFP_POINT );

			specular.colour = 0;
	
			draw_wbuffered_flat_shaded_textured_polygon ( polygon, colour, specular );
		}
	}
}
Пример #13
0
void draw_software_plain_line ( vertex *line, unsigned int whole_colour, float red, float green, float blue )
{

	int
		x1,
		y1,
		x2,
		y2,
		dx,
		dy,
		error;

	unsigned short int
		colour;

	ASSERT ( active_screen );

	ASSERT ( get_screen_locked ( active_screen ) );

	colour = whole_colour;

	convert_float_to_int ( line->i, &x1 );

	convert_float_to_int ( line->j, &y1 );

	convert_float_to_int ( line->next_vertex->i, &x2 );

	convert_float_to_int ( line->next_vertex->j, &y2 );

	dx = x2 - x1;

	if ( dx < 0 )
	{

		dx = -dx;

		dy = y2 - y1;

		if ( dy < 0 )
		{

			dy = -dy;

			if ( dx > dy )
			{

				error = ( ( dx + 1 ) >> 1 );
			
				for ( ; x1 > x2; x1-- )
				{

					set_software_pixel ( x1, y1, colour );
			
					if ( ( error -= dy ) < 0 )
					{

						error += dx;
			
						y1--;
					}
				}
			}
Пример #14
0
void draw_3d_polyline ( struct OBJECT_3D_POLYLINE *polyline )
{

	int
		segment,
		outcode;

	float
		average_distance;

	polyline_point
		*points;

	vertex
		*line;

	real_colour
		colour;

	//
	// Connect the two vertices up
	//

	points = polyline->polyline->points;

	segment = polyline->segment;

	points[segment].transformed_point.next_vertex = &points[segment+1].transformed_point;

	points[segment+1].transformed_point.next_vertex = NULL;

	outcode = points[segment].transformed_point.outcode;
	outcode |= points[segment+1].transformed_point.outcode;

	//
	// Calculate the average distance of the polyline
	//

	average_distance = ( points[segment].transformed_point.z + points[segment+1].transformed_point.z ) / 2.0;

	//
	// Set the fog value for this polyline
	//

	{

		float
			fog_intensity;

		int
			ifog_intensity;

		fog_intensity = get_fog_distance_value ( average_distance );

		convert_float_to_int ( fog_intensity, &ifog_intensity );

		set_d3d_fog_face_intensity ( ifog_intensity );
	}

	//
	// Calculate the lighting if required
	//

	if ( polyline->polyline->lit )
	{

		vec3d
			point1,
			point2,
			plane_normal,
			line_normal;

		float
			red,
			green,
			blue,
			ndotn,
			ndotp1,
			ndotcamera,
			direction_factor;

		light_3d_source
			*this_light;

		int
			ired,
			igreen,
			iblue;
	
		//
		// This bit is a work of a genius matey!
		//

		point1 = points[segment].world_point;
		point2 = points[segment+1].world_point;

		point1.x = ( ( point2.x - point1.x ) / 2 ) + point1.x;
		point1.y = ( ( point2.y - point1.y ) / 2 ) + point1.y;
		point1.z = ( ( point2.z - point1.z ) / 2 ) + point1.z;

		plane_normal.x = point2.x - point1.x;
		plane_normal.y = point2.y - point1.y;
		plane_normal.z = point2.z - point1.z;

		ndotn = ( ( plane_normal.x * plane_normal.x ) + ( plane_normal.y * plane_normal.y ) + ( plane_normal.z * plane_normal.z ) );
		ndotp1 = ( ( point1.x * plane_normal.x ) + ( point1.y * plane_normal.y ) + ( point1.z * plane_normal.z ) );

		ndotcamera = (	( visual_3d_vp->x * plane_normal.x ) + ( visual_3d_vp->y * plane_normal.y ) + ( visual_3d_vp->z * plane_normal.z ) );

		direction_factor = ( ( ndotp1 - ndotcamera ) / ndotn );

		line_normal.x = visual_3d_vp->x + direction_factor * ( plane_normal.x );
		line_normal.y = visual_3d_vp->y + direction_factor * ( plane_normal.y );
		line_normal.z = visual_3d_vp->z + direction_factor * ( plane_normal.z );

		line_normal.x = line_normal.x - point1.x;
		line_normal.y = line_normal.y - point1.y;
		line_normal.z = line_normal.z - point1.z;

		normalise_any_3d_vector ( &line_normal );

		this_light = current_3d_lights;

		red = ambient_3d_light.colour.red;
		green = ambient_3d_light.colour.green;
		blue = ambient_3d_light.colour.blue;

		while ( this_light )
		{

			float
				intensity;

			intensity = ( ( line_normal.x * this_light->lx ) + ( line_normal.y * this_light->ly ) + ( line_normal.z * this_light->lz ) );

			if ( ( *( int * ) &intensity ) > ( *( int * ) &float_value_zero ) )
			{

				red += intensity * this_light->colour.red;
				green += intensity * this_light->colour.green;
				blue += intensity * this_light->colour.blue;
			}

			this_light = this_light->succ;
		}
	
		red = bound ( red, 0, 1 );
		green = bound ( green, 0, 1 );
		blue = bound ( blue, 0, 1 );

		red *= polyline->polyline->colour.red;
		green *= polyline->polyline->colour.green;
		blue *= polyline->polyline->colour.blue;

		red += FLOAT_FLOAT_FACTOR;
		green += FLOAT_FLOAT_FACTOR;
		blue += FLOAT_FLOAT_FACTOR;

		ired = ( *( int * ) &red ) - INTEGER_FLOAT_FACTOR;
		igreen = ( *( int * ) &green ) - INTEGER_FLOAT_FACTOR;
		iblue = ( *( int * ) &blue ) - INTEGER_FLOAT_FACTOR;

		colour.red = ired;
		colour.green = igreen;
		colour.blue = iblue;
		colour.alpha = 0;
	}
	else
	{

		colour = polyline->polyline->colour;
	}

	//
	// Go through all the vertices, creating lines to draw, then render them.
	//

	line = &points[segment].transformed_point;

	clip_3d_coord = 0;

	if ( outcode & CLIP_HITHER )
	{

		line = hither_clip_3d_polygon ( line, &outcode );
	}

	if ( line )
	{

		if ( outcode )
		{

			line = clip_3d_polygon ( line, outcode );
		}

		if ( line )
		{

			set_d3d_plain_renderstate ();

			draw_wbuffered_plain_line ( line, colour );
		}
	}
}
Пример #15
0
void draw_3d_terrain_tree ( object_3d_instance *obj )
{

	int
		object_number;

	object_3d_info
		*this_object_3d_info;

	light_3d_source
		*this_light,
		*prev_light,
		*light_ptr,
		*light;

	vec3d
		*pos;
	
	vec3d
		object_camera_position,
		object_pos;

	//
	// Set up the object drawing global variables
	//

	object_3d_points_current_base = 0;

	object_3d_object_current_base = 0;

	object_3d_light_3d_current_base = 0;

	//
	// Calculate the object's position relative to the view.
	//

	pos = &obj->rel_vp.position;

	{

		float
			fog_intensity;

		int
			ifog_intensity;

		fog_intensity = get_fog_distance_value ( pos->z );

		convert_float_to_int ( fog_intensity, &ifog_intensity );

		set_d3d_fog_face_intensity ( ifog_intensity );
	}

	//
	// Set the main objects' scaling values
	//

	object_3d_scale.x = obj->relative_scale.x;
	object_3d_scale.y = obj->relative_scale.y;
	object_3d_scale.z = obj->relative_scale.z;

	//
	// Calculate the object's rotation matrix, to transform its 3d points relative to the view.
	//

	rotation_3d[0][0] = ( obj->vp.xv.x * visual_3d_vp->xv.x + obj->vp.xv.y * visual_3d_vp->xv.y + obj->vp.xv.z * visual_3d_vp->xv.z );
	rotation_3d[0][1] = ( obj->vp.xv.x * visual_3d_vp->yv.x + obj->vp.xv.y * visual_3d_vp->yv.y + obj->vp.xv.z * visual_3d_vp->yv.z );
	rotation_3d[0][2] = ( obj->vp.xv.x * visual_3d_vp->zv.x + obj->vp.xv.y * visual_3d_vp->zv.y + obj->vp.xv.z * visual_3d_vp->zv.z );

	rotation_3d[1][0] = ( obj->vp.yv.x * visual_3d_vp->xv.x + obj->vp.yv.y * visual_3d_vp->xv.y + obj->vp.yv.z * visual_3d_vp->xv.z );
	rotation_3d[1][1] = ( obj->vp.yv.x * visual_3d_vp->yv.x + obj->vp.yv.y * visual_3d_vp->yv.y + obj->vp.yv.z * visual_3d_vp->yv.z );
	rotation_3d[1][2] = ( obj->vp.yv.x * visual_3d_vp->zv.x + obj->vp.yv.y * visual_3d_vp->zv.y + obj->vp.yv.z * visual_3d_vp->zv.z );

	rotation_3d[2][0] = ( obj->vp.zv.x * visual_3d_vp->xv.x + obj->vp.zv.y * visual_3d_vp->xv.y + obj->vp.zv.z * visual_3d_vp->xv.z );
	rotation_3d[2][1] = ( obj->vp.zv.x * visual_3d_vp->yv.x + obj->vp.zv.y * visual_3d_vp->yv.y + obj->vp.zv.z * visual_3d_vp->yv.z );
	rotation_3d[2][2] = ( obj->vp.zv.x * visual_3d_vp->zv.x + obj->vp.zv.y * visual_3d_vp->zv.y + obj->vp.zv.z * visual_3d_vp->zv.z );

	rotation_3d[0][0] *= object_3d_scale.x;
	rotation_3d[1][0] *= object_3d_scale.y;
	rotation_3d[2][0] *= object_3d_scale.z;

	rotation_3d[0][1] *= object_3d_scale.x;
	rotation_3d[1][1] *= object_3d_scale.y;
	rotation_3d[2][1] *= object_3d_scale.z;

	rotation_3d[0][2] *= object_3d_scale.x;
	rotation_3d[1][2] *= object_3d_scale.y;
	rotation_3d[2][2] *= object_3d_scale.z;

	//
	// Calculate the vector from the object to the viewpoint, in the object's view system
	//

	{

		float
			x,
			y,
			z;

		x = ( ( visual_3d_vp->x - obj->vp.x ) * obj->vp.xv.x );
		x += ( ( visual_3d_vp->y - obj->vp.y ) *  obj->vp.xv.y );
		x += ( ( visual_3d_vp->z - obj->vp.z ) *  obj->vp.xv.z );

		y = ( ( visual_3d_vp->x - obj->vp.x ) * obj->vp.yv.x );
		y += ( ( visual_3d_vp->y - obj->vp.y ) *  obj->vp.yv.y );
		y += ( ( visual_3d_vp->z - obj->vp.z ) *  obj->vp.yv.z );

		z = ( ( visual_3d_vp->x - obj->vp.x ) * obj->vp.zv.x );
		z += ( ( visual_3d_vp->y - obj->vp.y ) *  obj->vp.zv.y );
		z += ( ( visual_3d_vp->z - obj->vp.z ) *  obj->vp.zv.z );

		object_pos.x = x;
		object_pos.y = y;
		object_pos.z = z;
	}

	//
	// Get the object number
	//

	object_number = get_object_approximation_number ( obj->object_number, pos->z, &object_3d_approximation_level );

	//
	// Rotate the light source vector to be relative to the object.
	//

	light_ptr = current_3d_lights;

	prev_light = NULL;

	light = NULL;

	if ( light_ptr )
	{

		light = &light_3d_array[object_3d_light_3d_current_base];

		while ( light_ptr )
		{

			float
				lx,
				ly,
				lz;

			if ( light_ptr->type == LIGHT_3D_TYPE_POINT )
			{

				vec3d
					vector;

				float
					distance;

				//
				// Work out the distance from object to light source
				//

				vector.x = - light_ptr->light_position.x + obj->vp.x;
				vector.y = - light_ptr->light_position.y + obj->vp.y;
				vector.z = - light_ptr->light_position.z + obj->vp.z;

				lx = vector.x * vector.x;
				ly = vector.y * vector.y;
				lz = vector.z * vector.z;

				distance = ( lx + ly + lz );

				if ( distance < light_ptr->radius )
				{

					distance = 1 - ( distance / light_ptr->radius );

					this_light = &light_3d_array[object_3d_light_3d_current_base];
			
					object_3d_light_3d_current_base++;
		
					if ( prev_light )
					{
		
						prev_light->succ = this_light;
					}
		
					this_light->pred = prev_light;
					this_light->succ = NULL;
		
					this_light->type = light_ptr->type;

					this_light->colour.red = light_ptr->colour.red * distance;
					this_light->colour.green = light_ptr->colour.green * distance;
					this_light->colour.blue = light_ptr->colour.blue * distance;
//					this_light->colour.intensity = light_ptr->colour.intensity * distance;

					normalise_3d_vector ( &vector );

					lx = ( vector.x * obj->vp.attitude[0][0] );
					lx += ( vector.y * obj->vp.attitude[0][1] );
					lx += ( vector.z * obj->vp.attitude[0][2] );
		
					ly = ( vector.x * obj->vp.attitude[1][0] );
					ly += ( vector.y * obj->vp.attitude[1][1] );
					ly += ( vector.z * obj->vp.attitude[1][2] );
		
					lz = ( vector.x * obj->vp.attitude[2][0] );
					lz += ( vector.y * obj->vp.attitude[2][1] );
					lz += ( vector.z * obj->vp.attitude[2][2] );
		
					this_light->lx = lx;
					this_light->ly = ly;
					this_light->lz = lz;
		
					prev_light = this_light;
				}
			}
			else
			{
	
				this_light = &light_3d_array[object_3d_light_3d_current_base];
		
				object_3d_light_3d_current_base++;
	
				if ( prev_light )
				{
	
					prev_light->succ = this_light;
				}
	
				this_light->pred = prev_light;
				this_light->succ = NULL;
	
				this_light->type = light_ptr->type;

				this_light->colour.red = light_ptr->colour.red;
				this_light->colour.green = light_ptr->colour.green;
				this_light->colour.blue = light_ptr->colour.blue;
//				this_light->colour.intensity = light_ptr->colour.intensity;
	
				lx = ( light_ptr->lx * obj->vp.attitude[0][0] );
				lx +=  ( light_ptr->ly * obj->vp.attitude[0][1] );
				lx += ( light_ptr->lz * obj->vp.attitude[0][2] );
	
				ly = ( light_ptr->lx * obj->vp.attitude[1][0] );
				ly += ( light_ptr->ly * obj->vp.attitude[1][1] );
				ly += ( light_ptr->lz * obj->vp.attitude[1][2] );
	
	
				lz = ( light_ptr->lx * obj->vp.attitude[2][0] );
				lz += ( light_ptr->ly * obj->vp.attitude[2][1] );
				lz += ( light_ptr->lz * obj->vp.attitude[2][2] );
	
				this_light->lx = lx;
				this_light->ly = ly;
				this_light->lz = lz;
	
				prev_light = this_light;
			}
	
			light_ptr = light_ptr->succ;
		}
	}

	{

		vec3d
			rel_pos;

		//
		// Calculate the relative camera position in the object viewspace
		//

		rel_pos.x = visual_3d_vp->x - obj->vp.x;
		rel_pos.y = visual_3d_vp->y - obj->vp.y;
		rel_pos.z = visual_3d_vp->z - obj->vp.z;

		object_camera_position.x = ( rel_pos.x * obj->vp.attitude[0][0] + rel_pos.y * obj->vp.attitude[1][0] + rel_pos.z * obj->vp.attitude[2][0] );
		object_camera_position.y = ( rel_pos.x * obj->vp.attitude[0][1] + rel_pos.y * obj->vp.attitude[1][1] + rel_pos.z * obj->vp.attitude[2][1] );
		object_camera_position.z = ( rel_pos.x * obj->vp.attitude[0][2] + rel_pos.y * obj->vp.attitude[1][2] + rel_pos.z * obj->vp.attitude[2][2] );
	}

	//
	//	Set up this objects' object info structure
	//

	object_3d_object_base[object_3d_object_current_base].lights = light;

	object_3d_object_base[object_3d_object_current_base].camera_position = object_camera_position;

	object_3d_object_base[object_3d_object_current_base].points_base = object_3d_points_current_base;

	object_3d_object_base[object_3d_object_current_base].object_number = object_number;

	this_object_3d_info = &object_3d_object_base[object_3d_object_current_base];

	global_object_3d_info = this_object_3d_info;

	//
	// Transform the object's shape data
	//

	//
	// Setup the objects scaling information
	//

	{

		float
			xdistance,
			ydistance,
			zdistance;

		xdistance = ( objects_3d_data[object_number].bounding_box.xmax - objects_3d_data[object_number].bounding_box.xmin ) / 2;
		ydistance = ( objects_3d_data[object_number].bounding_box.ymax - objects_3d_data[object_number].bounding_box.ymin ) / 2;
		zdistance = ( objects_3d_data[object_number].bounding_box.zmax - objects_3d_data[object_number].bounding_box.zmin ) / 2;

		object_3d_x_middle = objects_3d_data[object_number].bounding_box.xmin + xdistance;
		object_3d_y_middle = objects_3d_data[object_number].bounding_box.ymin + ydistance;
		object_3d_z_middle = objects_3d_data[object_number].bounding_box.zmin + zdistance;

		object_3d_x_scale = xdistance / 32767.0;
		object_3d_y_scale = ydistance / 32767.0;
		object_3d_z_scale = zdistance / 32767.0;
	}
/*
	if ( objects_3d_data[object_number].number_of_points )
	{

		int
			object_outcode;

		object_outcode = get_object_3d_outcode ( object_number, pos );

		if ( object_outcode )
		{

			transform_3d_object ( &objects_3d_data[object_number], pos, light, object_3d_points_current_base);
		}
		else
		{

			transform_unclipped_3d_object ( &objects_3d_data[object_number], pos, light, object_3d_points_current_base);
		}


		polygon_zdistance_bias = POLYGON_ZDISTANCE_NORMAL_BIAS;

		set_d3d_int_state ( D3DRENDERSTATE_CULLMODE, D3DCULL_CW );

		if ( object_outcode )
		{

			draw_3d_terrain_tree_clipped_faces ( object_number, this_object_3d_info );
		}
		else
		{

			draw_3d_terrain_tree_unclipped_faces ( object_number, this_object_3d_info );
		}

		set_d3d_int_state ( D3DRENDERSTATE_CULLMODE, D3DCULL_CCW );

		if ( object_outcode )
		{

			draw_3d_terrain_tree_clipped_faces ( object_number, this_object_3d_info );
		}
		else
		{

			draw_3d_terrain_tree_unclipped_faces ( object_number, this_object_3d_info );
		}
	}
	*/
}
Пример #16
0
void render_unclipped_3d_terrain_tree_textured_diffuse_lit_polygon ( object_3d_face *this_face, struct OBJECT_3D_INFO *object_base )
{

	texture_map
		*texture;

	real_colour
		colour;

	int
		ired,
		igreen,
		iblue,
		count;

	float
		red,
		green,
		blue;

	object_transformed_2d_point
		*vert,
		*transformed_points;

	LPD3DTLVERTEX
		destination_vertices;

	object_3d_short_textured_point
		*texture_list;

	texture = &system_textures[current_object_3d_surface->texture_index];

	//
	// Look up the colour of the face normal
	//

	red = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].r;
	green = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].g;
	blue = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].b;

	red *= current_tree_colour_red;
	green *= current_tree_colour_green;
	blue *= current_tree_colour_blue;

	convert_float_to_int ( red, &ired );
	convert_float_to_int ( green, &igreen );
	convert_float_to_int ( blue, &iblue );

	colour.red = ired;
	colour.green = igreen;
	colour.blue = iblue;
	colour.alpha = current_tree_colour_alpha;

//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMAG, current_object_3d_texture_filter );
//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMIN, current_object_3d_texture_mipmap );
//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREADDRESS, current_object_3d_texture_address );

	//
	// Should draw a flat shaded polygon
	//

	set_d3d_flat_shaded_textured_renderstate ( texture );

	transformed_points = transformed_3d_2d_points + object_base->points_base;

	destination_vertices = get_d3d_vertices_points_address ( this_face->number_of_points );

	texture_list = NULL;	//current_object_3d_texture_list;

	for ( count = 0; count < this_face->number_of_points; count++ )
	{

		vert = NULL;	//transformed_points + current_object_3d_point_list[count].point;
	
		*( ( int * ) &destination_vertices[count].sx ) = *( ( int * ) &vert->i );
		*( ( int * ) &destination_vertices[count].sy ) = *( ( int * ) &vert->j );
		destination_vertices[count].sz = vert->q;
		destination_vertices[count].rhw = vert->q;
		destination_vertices[count].tu = ( ( float ) texture_list->u ) / OBJECT_3D_TEXTURE_UV_SCALE;
		destination_vertices[count].tv = ( ( float ) texture_list->v ) / OBJECT_3D_TEXTURE_UV_SCALE;
		destination_vertices[count].color = colour.colour;
		destination_vertices[count].specular = d3d_fog_intensity;

		texture_list++;
	}

	draw_fan_primitive ( this_face->number_of_points, destination_vertices );
}
Пример #17
0
void render_unclipped_3d_terrain_tree_gouraud_textured_diffuse_lit_polygon ( object_3d_face *this_face, struct OBJECT_3D_INFO *object_base )
{

	texture_map
		*texture;

	int
		count;

	object_transformed_2d_point
		*vert,
		*transformed_points;

	LPD3DTLVERTEX
		destination_vertices;

	object_3d_short_textured_point
		*texture_list;

	point_3d_plain_reference
		*gouraud_list;

	texture = &system_textures[current_object_3d_surface->texture_index];

	transformed_points = transformed_3d_2d_points + object_base->points_base;

	texture_list = NULL;	//current_object_3d_texture_list;

	gouraud_list = NULL;	//current_object_3d_gouraud_list;

	//
	// Should draw a gouraud shaded polygon
	//

	set_d3d_gouraud_shaded_textured_renderstate ( texture );

//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMAG, current_object_3d_texture_filter );
//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMIN, current_object_3d_texture_mipmap );
//	set_d3d_int_state ( D3DRENDERSTATE_TEXTUREADDRESS, current_object_3d_texture_address );

	destination_vertices = get_d3d_vertices_points_address ( this_face->number_of_points );

	for ( count = 0; count < this_face->number_of_points; count++ )
	{

		int
			ir,
			ig,
			ib;
	
		float
			r,
			g,
			b;

		real_colour
			colour;

		vert = NULL;	//transformed_points + current_object_3d_point_list[count].point;
	
		*( ( int * ) &destination_vertices[count].sx ) = *( ( int * ) &vert->i );
		*( ( int * ) &destination_vertices[count].sy ) = *( ( int * ) &vert->j );
		destination_vertices[count].sz = vert->q;
		destination_vertices[count].rhw = vert->q;
		destination_vertices[count].tu = ( ( float ) texture_list->u ) / OBJECT_3D_TEXTURE_UV_SCALE;
		destination_vertices[count].tv = ( ( float ) texture_list->v ) / OBJECT_3D_TEXTURE_UV_SCALE;
		r = current_object_3d_transformed_normals[gouraud_list->point].r;
		g = current_object_3d_transformed_normals[gouraud_list->point].g;
		b = current_object_3d_transformed_normals[gouraud_list->point].b;
		convert_float_to_int ( ( r * current_tree_colour_red ), &ir );
		convert_float_to_int ( ( g * current_tree_colour_green ), &ig );
		convert_float_to_int ( ( b * current_tree_colour_blue ), &ib );
		colour.red = ir;
		colour.green = ig;
		colour.blue = ib;
		colour.alpha = current_tree_colour_alpha;
		destination_vertices[count].color = colour.colour;
		destination_vertices[count].specular = d3d_fog_intensity;

		gouraud_list++;
		texture_list++;
	}

	draw_fan_primitive ( this_face->number_of_points, destination_vertices );
}
Пример #18
0
int store_session (session_list_data_type *game_session, const char *filename)
{
	#if !DEMO_VERSION

	entity
		*force;

	int
		count;

	char
		limited_filename [32],
		title [128],
		extension [5],
		data_filename [256],
		script_filename [256];

	FILE
		*file_ptr;

	count = 0;

	strncpy (limited_filename, filename, sizeof (limited_filename) - 2);
	limited_filename [31] = '\0';

	sprintf (data_filename, "%s\\%s\\%s", game_session->data_path, game_session->campaign_directory, limited_filename);

	strcat (data_filename, ".sav");

	sprintf (script_filename, "%s\\%s\\%s.", game_session->data_path, game_session->campaign_directory, limited_filename);

	sprintf (extension, "%s", game_type_extensions [get_game_type ()]);
	extension [2] = extension [1];
	extension [1] = extension [0];
	extension [0] = 'S';

	strcat(script_filename, extension);

	//
	// Create scripting file
	//

	file_ptr = fopen (script_filename, "w");

	if (!file_ptr)
	{

		debug_log ("SESSION: failed to open file %s", script_filename);

		return FALSE;
	}

	ASSERT (file_ptr);

	// Start

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_START);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	// Campaign title

	set_file_new_line (file_ptr, 1);

	sprintf (title, "%s", game_session->title);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_TITLE);
	set_file_string (file_ptr, title);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_new_line (file_ptr, 1);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SHORT_TEXT_START);

	// campaign title

	set_file_string (file_ptr, game_session->title);

	set_file_new_line (file_ptr, 2);

	// elapsed campaign time
	{
		float
			elapsed_time;

		int
			hours,
			minutes,
			seconds,
			elapsed_days;

		elapsed_time = get_local_entity_float_value (get_session_entity (), FLOAT_TYPE_ELAPSED_TIME);

		convert_float_to_int (elapsed_time / ONE_DAY, &elapsed_days);

		elapsed_time = fmod (elapsed_time, ONE_DAY);

		get_digital_clock_int_values (elapsed_time, &hours, &minutes, &seconds);

		sprintf (script_filename, "%s %d %s, %02d.%02d.%02d",
						get_trans ("Elapsed Time"),
						elapsed_days,
						get_trans ("days"),
						hours, minutes, seconds);



		set_file_string (file_ptr, script_filename);

		set_file_new_line (file_ptr, 1);
	}
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_TEXT_END);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_new_line (file_ptr, 1);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_CAMPAIGN_DATA);

	if (side_data_filename)
	{

		// side data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, side_data_filename);
	}

	if (population_placement_filename)
	{

		// population data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, population_placement_filename);
	}

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_X_SIZE);
	set_file_int (file_ptr, world_map.num_map_x_sectors);
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_Z_SIZE);
	set_file_int (file_ptr, world_map.num_map_z_sectors);
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_MAP_SECTOR_SIZE);
	set_file_int (file_ptr, world_map.sector_side_length);

	if (campaign_population_filename)
	{

		// population data
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
		set_file_string (file_ptr, campaign_population_filename);
	}

	//
	// save force in reverse order to list (so that they are read_in in the correct order)
	//

	force = get_local_entity_first_child (get_session_entity (), LIST_TYPE_FORCE);

	ASSERT (force);

	while (get_local_entity_child_succ (force, LIST_TYPE_FORCE))
	{

		force = get_local_entity_child_succ (force, LIST_TYPE_FORCE);
	}

	while (force)
	{

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FACTION);
		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SIDE);
		set_file_enum (file_ptr, entity_side_names, get_local_entity_int_value (force, INT_TYPE_SIDE));

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_COLOUR);
		set_file_enum (file_ptr, sys_colour_names, get_local_entity_int_value (force, INT_TYPE_COLOUR));

		force = get_local_entity_child_pred (force, LIST_TYPE_FORCE);
	}

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_END);

	// Campaign saved filename

	set_file_new_line (file_ptr, 1);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SAVED_CAMPAIGN);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_PATH);
	set_file_string (file_ptr, game_session->data_path);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_PATH);
	set_file_string (file_ptr, game_session->campaign_directory);

	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_FILENAME);
	set_file_string (file_ptr, game_session->campaign_filename);

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_new_line (file_ptr, 1);

	//
	// Version number
	//

	{

		int
			value;
		set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

		set_file_tag (file_ptr, application_tag_strings, FILE_TAG_VERSION_NUMBER);
		value = get_local_entity_int_value ( get_session_entity (), INT_TYPE_VERSION_NUMBER );
		set_file_int (file_ptr, value);

		set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	}

	// End

	//VJ 051202 add season (camo) info to file description
	//use set and get_global_season
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_SEASON);
	set_file_int (file_ptr, (int) get_global_season() );
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");
	set_file_tag (file_ptr, application_tag_strings, FILE_TAG_END);
	set_file_comment (file_ptr, "/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////");

	fclose (file_ptr);

	//
	// Save entity data
	//

	file_ptr = fopen (data_filename, "wb");

	if (file_ptr)
	{

		unsigned char
			*save_ptr,
			*buffer;

		int
			extra_data,
			server_version_number,
			buffer_size;

		buffer_size = 1024 * 1024;

		buffer = (unsigned char *) malloc_heap_mem (buffer_size);

		save_ptr = buffer;

		extra_data = 0;

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// write out version number
		server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

		quick_set_list_item (save_ptr, int, server_version_number);

		buffer_size -= sizeof (int);
		extra_data += sizeof (int);
		//
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		// write out session
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		while (pack_session (save_ptr, &buffer_size, PACK_MODE_SERVER_SESSION))
		{

			debug_log ("SESSION: mallocing store pack buffer from %d to %d", buffer_size, buffer_size * 2);

			free_mem (buffer);

			buffer_size *= 2;

			buffer = (unsigned char *) malloc_heap_mem (buffer_size);

			save_ptr = buffer;

			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
			// write out version number
			server_version_number = get_local_entity_int_value (get_session_entity (), INT_TYPE_VERSION_NUMBER);

			quick_set_list_item (save_ptr, int, server_version_number);

			buffer_size -= sizeof (int);
			//
			/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		}

		fwrite (buffer, buffer_size + extra_data, 1, file_ptr);

		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
		//
		/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////

		free_mem (buffer);
	}

	fclose (file_ptr);

	//
	//
	//

	// arneh feb 2009 - this call shouldn't be necessary, and it will double initialise things which confuses EECH
	//	set_current_game_session (game_session);

	#endif

	return TRUE;
}
Пример #19
0
void ui_draw_area (float x1, float y1, float x2, float y2, ui_object *obj)
{

	float
		new_x1,
		new_y1,
		new_x2,
		new_y2;

	int
		state,
		int_x1,
		int_y1,
		int_x2,
		int_y2;

	rgb_colour
		background_colour,
		top_line_colour,
		bottom_line_colour,
		left_line_colour,
		right_line_colour;

	state = get_ui_object_state (obj);

	new_x1 = x1;

	new_y1 = y1;

	new_x2 = x2;

	new_y2 = y2;

	// clip area to ui viewport

	ui_clip_area (&new_x1, &new_y1, &new_x2, &new_y2);
	ui_clip_area (&x1, &y1, &x2, &y2);

	// button coords should be in viewport coords,
	// so add ui_origin to convert into screen coords

	x1 += ui_x_origin;

	y1 += ui_y_origin;

	x2 += ui_x_origin;

	y2 += ui_y_origin;

	new_x1 += ui_x_origin;

	new_y1 += ui_y_origin;

	new_x2 += ui_x_origin;

	new_y2 += ui_y_origin;

	// check if possible to draw

	if ((new_x2 - new_x1 < 2) || (new_y2 - new_y1 <= 2))
	{

		return;
	}

	// convert variabless to ints to save crap conversion

	convert_float_to_int (new_x1, &int_x1);
	convert_float_to_int (new_y1, &int_y1);
	convert_float_to_int (new_x2, &int_x2);
	convert_float_to_int (new_y2, &int_y2);

	// assign correct colours

	switch (state)
	{

		case UI_OBJECT_STATE_ON:
		case UI_OBJECT_STATE_OFF:
		{
			
			background_colour = get_ui_object_colour (obj); //ui_area_background;
			top_line_colour = ui_area_light_edge;
			bottom_line_colour = ui_area_dark_edge;
			left_line_colour = ui_area_light_edge;
			right_line_colour = ui_area_dark_edge;
			
			break;
		}

		case UI_OBJECT_STATE_HIGHLIGHTED:
		{
			
			background_colour = get_ui_object_highlighted_colour (obj); // ui_area_highlighted_background;
			top_line_colour = ui_area_highlighted_light_edge;
			bottom_line_colour = ui_area_highlighted_dark_edge;
			left_line_colour = ui_area_highlighted_light_edge;
			right_line_colour = ui_area_highlighted_dark_edge;

			break;
		}
	}

	// draw background

	if (x1 != new_x1)
	{

		if (y1 != new_y1)
		{
			
			set_block (int_x1, int_y1, int_x2, int_y2, background_colour);
		}
		else
		{

			set_block (int_x1, int_y1 + 1, int_x2, int_y2, background_colour);
		}
	}
	else if (y1 != new_y1)
	{

		set_block (int_x1 + 1 , int_y1, int_x2, int_y2, background_colour);
	}
	else
	{

		set_block (int_x1 + 1 , int_y1 + 1, int_x2, int_y2, background_colour);
	}

	// draw top line

	if (y1 == new_y1)
	{
		
	  	if ((x1 == new_x1) && (x2 == new_x2))
		{
			
			draw_line (new_x1 + 1, new_y1, new_x2 - 1, new_y1, top_line_colour);
		}
	  	else if (x1 == new_x1)
		{
			
			draw_line (new_x1 + 1, new_y1, new_x2, new_y1, top_line_colour);
		}
	  	else if (x2 == new_x2)
		{
			
			draw_line (new_x1, new_y1, new_x2 - 1, new_y1, top_line_colour);
		}
	  	else
		{
			
			draw_line (new_x1, new_y1, new_x2, new_y1, top_line_colour);
		}
	}

	// draw botton line

	if (y2 == new_y2)
	{

	  	if ((x1 == new_x1) && (x2 == new_x2))
		{
			
			draw_line (new_x1 + 1, new_y2, new_x2 - 1, new_y2, bottom_line_colour);
		}
	  	else if (x1 == new_x1)
		{

			draw_line (new_x1 + 1, new_y2, new_x2, new_y2, bottom_line_colour);
		}
	  	else if (x2 == new_x2)
		{
			
			draw_line (new_x1, new_y2, new_x2 - 1, new_y2, bottom_line_colour);
		}
	  	else
		{
			
			draw_line (new_x1, new_y2, new_x2, new_y2, bottom_line_colour);
		}
	}

	// draw left side

	if (x1 == new_x1)
	{
		
	  	if ((y1 == new_y1) && (y2 == new_y2))
		{
			
			draw_line (new_x1, new_y1 + 1, new_x1, new_y2 - 1, left_line_colour);
		}
	  	else if (y1 == new_y1)
		{

			draw_line (new_x1, new_y1 + 1, new_x1, new_y2, left_line_colour);
		}
	  	else if (y2 == new_y2)
		{
			
			draw_line (new_x1, new_y1, new_x1, new_y2 - 1, left_line_colour);
		}
	  	else
		{
			
			draw_line (new_x1, new_y1, new_x1, new_y2, left_line_colour);
		}
	}

	// draw right side

	if (x2 == new_x2)
	{

	  	if ((y1 == new_y1) && (y2 == new_y2))
		{
			
			draw_line (new_x2, new_y1 + 1, new_x2, new_y2 - 1, right_line_colour);
		}
	  	else if (y1 == new_y1)
		{

			draw_line (new_x2, new_y1 + 1, new_x2, new_y2, right_line_colour);
		}
	  	else if (y2 == new_y2)
		{
			
			draw_line (new_x2, new_y1, new_x2, new_y2 - 1, right_line_colour);
		}
	  	else
		{
			
			draw_line (new_x2, new_y1, new_x2, new_y2, right_line_colour);
		}
	}
}
Пример #20
0
void scan_plain_line ( vertex *point1, vertex *point2 )
{

	int
		x,
		y,
		x2,
		y2,
		dx,
		dy,
		error;

	convert_float_to_int ( point1->i, &x );

	convert_float_to_int ( point1->j, &y );

	convert_float_to_int ( point2->i, &x2 );

	convert_float_to_int ( point2->j, &y2 );

//	x = point1->i;
//	y = point1->j;
//	x2 = point2->i;
//	y2 = point2->j;
//
	if ( y2 < y_min )
	{

		y_min = y2;
	}
	else if ( y2 > y_max )
	{

		y_max = y2;
	}

	if ( y > y2 )
	{

		//
		// Write to the RHS buffer
		//

		dy = ( y - y2 );

		dx = ( x2 - x );

		if ( dx < 0 )
		{

			dx = -dx;
	
			if ( dx > dy )
			{

				error = ( ( dx  ) >> 1 );
			
				while ( x > x2 )
				{

					if ( ( error -= dy ) < 0 )
					{

						error += dx;
			
						lhs_x[y] = x;

						y--;
					}

					x--;
				}

				lhs_x[y] = x;
			}
Пример #21
0
void render_cloud_polygon ( int number_of_points, cloud_3d_textured_reference *point_references, vertex *transformed_points, cloud_3d_point *source_points, float alpha_blend, screen *texture )
{

	int
		count,
		alpha,
		first_point,
		this_point,
		previous_point,
		outcode,
		outcode2;

	vertex
		*polygon;

	first_point = point_references->point;

	this_point = first_point;

	outcode = transformed_points[this_point].outcode;
	outcode2 = transformed_points[this_point].outcode;
	convert_float_to_int ( ( source_points[this_point].a * alpha_blend * 255 ), &alpha );
	transformed_points[this_point].u = point_references->u;
	transformed_points[this_point].v = point_references->v;
	transformed_points[this_point].alpha = alpha;

	point_references++;

	for ( count = 1; count < number_of_points; count++ )
	{

		previous_point = this_point;

		this_point = point_references->point;

		outcode |= transformed_points[this_point].outcode;
		outcode2 &= transformed_points[this_point].outcode;

		convert_float_to_int ( ( source_points[this_point].a * alpha_blend * 255 ), &alpha );

		transformed_points[this_point].u = point_references->u;
		transformed_points[this_point].v = point_references->v;
		transformed_points[this_point].alpha = alpha;

		cloud_transformed_3d_points[previous_point].next_vertex = &cloud_transformed_3d_points[this_point];

		point_references++;
	}

	cloud_transformed_3d_points[this_point].next_vertex = NULL;

	if ( !outcode2 )
	{

		polygon = &cloud_transformed_3d_points[first_point];

		clip_3d_coord = 0;

		if ( outcode & CLIP_HITHER )
		{

			polygon = hither_clip_3d_polygon ( polygon, &outcode );

			if ( !polygon )
			{

				return;
			}
		}

		if ( outcode )
		{

			apply_perspective_to_polygon_texture ( polygon );

			polygon = clip_3d_polygon ( polygon, outcode );

			if ( !polygon )
			{

				return;
			}

			remove_perspective_from_polygon_texture ( polygon );
		}

		if ( polygon )
		{
			set_d3d_int_state ( D3DRENDERSTATE_SPECULARENABLE, FALSE );
			set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
			set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );
			set_d3d_gouraud_shaded_textured_renderstate ( texture );

			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSU, D3DTADDRESS_WRAP );
			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSV, D3DTADDRESS_WRAP );
			set_d3d_texture_stage_state ( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
			set_d3d_texture_stage_state ( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
			{

				int
					number_of_vertices;

				vertex
					*vert;

				LPD3DTLVERTEX vertices, vptr;

				vert = polygon;

				vertices = get_d3d_vertices_address ( polygon, &number_of_vertices );

				vptr = vertices;

				while ( vert )
				{

					real_colour
						specular;

					specular.colour = d3d_fog_intensity;
					specular.red = vert->specular;
					specular.green = vert->specular;
					specular.blue = vert->specular;

					*( ( int * ) &vptr->sx ) = *( ( int * ) &vert->i );
					*( ( int * ) &vptr->sy ) = *( ( int * ) &vert->j );
					*( ( int * ) &vptr->tu ) = *( ( int * ) &vert->u );
					*( ( int * ) &vptr->tv ) = *( ( int * ) &vert->v );
					*( ( int * ) &vptr->rhw ) = *( ( int * ) &vert->q );
					vptr->sz = ( vert->q * zbuffer_factor ) + zbuffer_constant;

					vptr->r = vert->red;
					vptr->g = vert->green;
					vptr->b = vert->blue;
					vptr->a = vert->alpha;

					vptr->color = vert->colour;
					vptr->specular = specular.colour;

					if ( vptr->sz >= 1.0 )
					{

						vptr->sz = 0.999;
					}

					vptr++;

					vert = vert->next_vertex;
				}

				draw_fan_primitive ( number_of_vertices, vertices );
			}

//			draw_wbuffered_gouraud_shaded_textured_polygon ( polygon );
		}
	}
}
Пример #22
0
void draw_3d_sprite ( object_3d_sprite *sprite )
{

	float
		x,
		y,
		z,
		q,
		i,
		j,
		radius,
		roll,
		sin_roll,
		cos_roll,
		width,
		height;

	vertex
		*poly,
		sprite_quad[4];

	vec2d
		point1,
		point2,
		point3,
		point4;

	int
		outcode;

	number_of_sprites_in_3d_scene++;

	x = sprite->position.x;
	y = sprite->position.y;
	z = sprite->position.z;

	radius = sprite->radius;

	roll = sprite->roll;
	sin_roll = sin ( roll );
	cos_roll = cos ( roll );

	point1.x = ( -0.5 * ( +cos_roll ) ) + ( +0.5 * ( +sin_roll ) );
	point1.y = ( -0.5 * ( -sin_roll ) ) + ( +0.5 * ( +cos_roll ) );

	point2.x = ( -0.5 * ( +cos_roll ) ) + ( -0.5 * ( +sin_roll ) );
	point2.y = ( -0.5 * ( -sin_roll ) ) + ( -0.5 * ( +cos_roll ) );

	point3.x = ( +0.5 * ( +cos_roll ) ) + ( -0.5 * ( +sin_roll ) );
	point3.y = ( +0.5 * ( -sin_roll ) ) + ( -0.5 * ( +cos_roll ) );

	point4.x = ( +0.5 * ( +cos_roll ) ) + ( +0.5 * ( +sin_roll ) );
	point4.y = ( +0.5 * ( -sin_roll ) ) + ( +0.5 * ( +cos_roll ) );
	
	q = 1.0 / z;

	i = ( active_3d_environment->screen_i_scale * x * q );
	j = ( active_3d_environment->screen_j_scale * y * q );
	
	i = active_3d_environment->x_origin + i;
	j = active_3d_environment->y_origin - j;
	
	width = active_3d_environment->screen_i_scale * radius * q;
	height = active_3d_environment->screen_j_scale * radius * q;

	sprite_quad[0].q = q;
	sprite_quad[0].i = i + ( point1.x * width );
	sprite_quad[0].j = j + ( point1.y * height );
	sprite_quad[0].u = 0;
	sprite_quad[0].v = 0;
	sprite_quad[0].outcode = generate_3d_outcode ( sprite_quad[0].i, sprite_quad[0].j );
	sprite_quad[0].next_vertex = &sprite_quad[1];

	sprite_quad[1].q = q;
	sprite_quad[1].i = i + ( point2.x * width );
	sprite_quad[1].j = j + ( point2.y * height );
	sprite_quad[1].u = 1;
	sprite_quad[1].v = 0;
	sprite_quad[1].outcode = generate_3d_outcode ( sprite_quad[1].i, sprite_quad[1].j );
	sprite_quad[1].next_vertex = &sprite_quad[2];

	sprite_quad[2].q = q;
	sprite_quad[2].i = i + ( point3.x * width );
	sprite_quad[2].j = j + ( point3.y * height );
	sprite_quad[2].u = 1;
	sprite_quad[2].v = 1;
	sprite_quad[2].outcode = generate_3d_outcode ( sprite_quad[2].i, sprite_quad[2].j );
	sprite_quad[2].next_vertex = &sprite_quad[3];

	sprite_quad[3].q = q;
	sprite_quad[3].i = i + ( point4.x * width );
	sprite_quad[3].j = j + ( point4.y * height );
	sprite_quad[3].u = 0;
	sprite_quad[3].v = 1;
	sprite_quad[3].outcode = generate_3d_outcode ( sprite_quad[3].i, sprite_quad[3].j );
	sprite_quad[3].next_vertex = NULL;

	outcode = sprite_quad[0].outcode;
	outcode |= sprite_quad[1].outcode;
	outcode |= sprite_quad[2].outcode;
	outcode |= sprite_quad[3].outcode;

	poly = sprite_quad;

	if ( outcode )
	{

		clip_3d_coord = 0;

		poly = clip_3d_polygon ( poly, outcode );
	}

	if ( poly )
	{

		real_colour
			specular_colour;

		specular_colour.colour = 0;
		specular_colour.alpha = 255;

		set_d3d_texture_stage_state ( 0, D3DTSS_MAGFILTER, D3DTFG_LINEAR );
		set_d3d_texture_stage_state ( 0, D3DTSS_MINFILTER, D3DTFN_LINEAR );
		set_d3d_texture_stage_state ( 0, D3DTSS_MIPFILTER, D3DTFP_POINT );

		if (active_3d_environment->render_filter != RENDER_CLEAR )
		{

			float
				r,
				g,
				b,
				intensity;

			int
				ir,
				ig,
				ib;

			real_colour
				colour;

			//
			// Colour the additive to the light colour
			//

			colour.colour = sprite->colour;

			r = colour.red;
			g = colour.green;
			b = colour.blue;

			intensity = ( 0.3 * r ) + ( 0.59 * g ) + ( 0.11 * b );

			r = intensity * ambient_3d_light.colour.red;
			g = intensity * ambient_3d_light.colour.green;
			b = intensity * ambient_3d_light.colour.blue;

			convert_float_to_int ( r, &ir );
			convert_float_to_int ( g, &ig );
			convert_float_to_int ( b, &ib );

			colour.colour = sprite->colour;
			colour.red = ir;
			colour.green = ig;
			colour.blue = ib;

			sprite->colour = colour.colour;
		}

		if ( sprite->additive )
		{

			set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, D3DBLEND_ONE );
			set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, D3DBLEND_ONE );

			set_d3d_flat_shaded_textured_renderstate ( sprite->texture );

			draw_wbuffered_flat_shaded_textured_polygon ( poly, *( ( real_colour * ) &sprite->colour ), specular_colour );
		}
		else
		{



			set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, D3DBLEND_SRCALPHA );
			set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, D3DBLEND_INVSRCALPHA );

			set_d3d_flat_shaded_textured_renderstate ( sprite->texture );

			draw_wbuffered_flat_shaded_textured_polygon ( poly, *( ( real_colour * ) &sprite->colour ), specular_colour );
		}
	}
}
Пример #23
0
void draw_3d_cloud_sector ( scene_slot_drawing_list *slot )
{

	int
		count;

	float
		current_sector_x_offset,
		current_sector_z_offset;

	double
		tempx,
		tempz;

	vec3d
		sector_centre,
		sector_relative_centre;

	cloud_3d_point
		cloud_points[256];

	float
		cloud_polygon_alphas[256];

	cloud_3d_textured_reference
		point_references[4];

	//
	// Set the fog intensity for clouds ( NO FOG )
	//

	current_sector_x_offset = slot->cloud_sector.x * CLOUD_3D_SECTOR_SIDE_LENGTH;
	current_sector_z_offset = slot->cloud_sector.z * CLOUD_3D_SECTOR_SIDE_LENGTH;

	sector_centre.x = current_sector_x_offset + ( CLOUD_3D_SECTOR_SIDE_LENGTH / 2 );
	sector_centre.y = cloud_3d_base_height;
	sector_centre.z = current_sector_z_offset + ( CLOUD_3D_SECTOR_SIDE_LENGTH / 2 );

	sector_centre.x -= visual_3d_vp->x;
	sector_centre.y -= visual_3d_vp->y;
	sector_centre.z -= visual_3d_vp->z;

	sector_relative_centre.x = (	( sector_centre.x ) * visual_3d_vp->xv.x +
											( sector_centre.y ) * visual_3d_vp->xv.y +
											( sector_centre.z ) * visual_3d_vp->xv.z );

	sector_relative_centre.y = (	( sector_centre.x ) * visual_3d_vp->yv.x +
											( sector_centre.y ) * visual_3d_vp->yv.y +
											( sector_centre.z ) * visual_3d_vp->yv.z );

	sector_relative_centre.z = (	( sector_centre.x ) * visual_3d_vp->zv.x +
											( sector_centre.y ) * visual_3d_vp->zv.y +
											( sector_centre.z ) * visual_3d_vp->zv.z );

	set_d3d_fog_face_intensity ( 0 );

	if ( d3d_flat_only_alpha )
	{

		int
			number_of_sub_sectors,
			number_of_points,
			x,
			z;

		float
			x_offset,
			z_offset,
			alpha;

		number_of_sub_sectors = 1;

		number_of_points = ( number_of_sub_sectors + 1 ) * ( number_of_sub_sectors + 1 );

		count = 0;

		for ( z = 0; z <= number_of_sub_sectors; z++ )
		{

			for ( x = 0; x <= number_of_sub_sectors; x++ )
			{

				vec3d
					point_vector;

				float
					angle,
					distance,
					colour_t,
					dr,
					dg,
					db,
					r,
					g,
					b;

				int
					ir,
					ig,
					ib;

				x_offset = ( -CLOUD_3D_SECTOR_SIDE_LENGTH/2 ) + ( ( ( float ) x / ( float ) number_of_sub_sectors ) * CLOUD_3D_SECTOR_SIDE_LENGTH );
				z_offset = ( -CLOUD_3D_SECTOR_SIDE_LENGTH/2 ) + ( ( ( float ) z / ( float ) number_of_sub_sectors ) * CLOUD_3D_SECTOR_SIDE_LENGTH );

				cloud_points[count].x = x_offset;
				cloud_points[count].y = 0;
				cloud_points[count].z = z_offset;

				point_vector.x = sector_centre.x + x_offset;
				point_vector.y = 0;
				point_vector.z = sector_centre.z + z_offset;

				distance = get_3d_vector_magnitude ( &point_vector );

				if ( distance > 1 )
				{

					normalise_3d_vector_given_magnitude ( &point_vector, distance );

					angle = ( ( point_vector.x * cloud_colour_blend_vector.x ) + ( point_vector.z * cloud_colour_blend_vector.z ) );
					angle = bound ( angle, 0, 1 );
					angle *= angle;
					angle *= angle;

					colour_t = ( distance / CLOUD_MAXIMUM_COLOUR_BLEND_DISTANCE );
					colour_t = bound ( colour_t, 0, 1 );
					colour_t *= angle;
				}
				else
				{

					colour_t = 0;
				}

				dr = active_3d_environment->cloud_light.object_colour.red - active_3d_environment->cloud_light.light_colour.red;
				dg = active_3d_environment->cloud_light.object_colour.green - active_3d_environment->cloud_light.light_colour.green;
				db = active_3d_environment->cloud_light.object_colour.blue - active_3d_environment->cloud_light.light_colour.blue;

				r = active_3d_environment->cloud_light.light_colour.red + ( colour_t * dr );
				g = active_3d_environment->cloud_light.light_colour.green + ( colour_t * dg );
				b = active_3d_environment->cloud_light.light_colour.blue + ( colour_t * db );

				convert_float_to_int ( r * 255.0, &ir );
				convert_float_to_int ( g * 255.0, &ig );
				convert_float_to_int ( b * 255.0, &ib );

				cloud_points[count].red = ir;
				cloud_points[count].green = ig;
				cloud_points[count].blue = ib;

				count++;
			}
		}

		count = 0;

		z_offset = -CLOUD_3D_SECTOR_SIDE_LENGTH/2 + ( CLOUD_3D_SECTOR_SIDE_LENGTH / ( number_of_sub_sectors * 2 ) );

		for ( z = 0; z < number_of_sub_sectors; z++ )
		{

			x_offset = -CLOUD_3D_SECTOR_SIDE_LENGTH/2 + ( CLOUD_3D_SECTOR_SIDE_LENGTH / ( number_of_sub_sectors * 2 ) );

			for ( x = 0; x < number_of_sub_sectors; x++ )
			{

				tempx = sector_centre.x + x_offset;
				tempz = sector_centre.z + z_offset;

				tempx *= tempx;
				tempz *= tempz;

				alpha = ( ( cloud_3d_blend_constant - ( tempx + tempz ) ) * cloud_3d_adjusted_blend_factor );
				alpha = bound ( alpha, 0, 1 );

				cloud_polygon_alphas[count] = alpha;

				x_offset += CLOUD_3D_SECTOR_SIDE_LENGTH / ( number_of_sub_sectors * 1 );

				count++;
			}

			z_offset += CLOUD_3D_SECTOR_SIDE_LENGTH / ( number_of_sub_sectors * 1 );
		}

		transform_cloud_points ( number_of_points, cloud_points, cloud_transformed_3d_points, &sector_relative_centre );

		//
		// Render a quad twice, for the blending between cloud textures
		//

		count = 0;

		z_offset = 0;

		for ( z = 0; z < number_of_sub_sectors; z++ )
		{

			x_offset = 0;

			for ( x = 0; x < number_of_sub_sectors; x++ )
			{

				int
					tmp,
					z_bottom_point_offset,
					z_top_point_offset;

				z_bottom_point_offset = z * ( number_of_sub_sectors + 1 );

				z_top_point_offset = z_bottom_point_offset +  ( number_of_sub_sectors + 1 );

				if ( cloud_3d_base_height < visual_3d_vp->y )
				{

					point_references[3].point = x + z_bottom_point_offset;
					point_references[3].u = x_offset;
					point_references[3].v = z_offset;

					point_references[2].point = x + z_bottom_point_offset + 1;
					point_references[2].u = x_offset + ( 1.0 / number_of_sub_sectors );
					point_references[2].v = z_offset;

					point_references[1].point = x + z_top_point_offset + 1;
					point_references[1].u = x_offset + ( 1.0 / number_of_sub_sectors );
					point_references[1].v = z_offset + ( 1.0 / number_of_sub_sectors );

					point_references[0].point = x + z_top_point_offset;
					point_references[0].u = x_offset;
					point_references[0].v = z_offset + ( 1.0 / number_of_sub_sectors );
				}
				else
				{

					point_references[0].point = x + z_bottom_point_offset;
					point_references[0].u = x_offset;
					point_references[0].v = z_offset;

					point_references[1].point = x + z_bottom_point_offset + 1;
					point_references[1].u = x_offset + ( 1.0 / number_of_sub_sectors );
					point_references[1].v = z_offset;

					point_references[2].point = x + z_top_point_offset + 1;
					point_references[2].u = x_offset + ( 1.0 / number_of_sub_sectors );
					point_references[2].v = z_offset + ( 1.0 / number_of_sub_sectors );

					point_references[3].point = x + z_top_point_offset;
					point_references[3].u = x_offset;
					point_references[3].v = z_offset + ( 1.0 / number_of_sub_sectors );
				}

				for ( tmp = 0; tmp < 4; tmp++ )
				{

					cloud_points[ point_references[tmp].point ].a = cloud_polygon_alphas[count];
				}

				if ( current_weather_texture )
				{

					render_cloud_polygon ( 4, point_references, cloud_transformed_3d_points, cloud_points, cloud_weather_one_minus_blend_factor, current_weather_texture );
				}

				if ( target_weather_texture )
				{

					render_cloud_polygon ( 4, point_references, cloud_transformed_3d_points, cloud_points, cloud_weather_blend_factor, target_weather_texture );
				}

				x_offset += ( 1.0 / number_of_sub_sectors );

				count++;
			}

			z_offset += ( 1.0 / number_of_sub_sectors );
		}
	}
	else
	{

		cloud_points[0].x = -CLOUD_3D_SECTOR_SIDE_LENGTH/2;
		cloud_points[0].y = 0;
		cloud_points[0].z = -CLOUD_3D_SECTOR_SIDE_LENGTH/2;

		cloud_points[1].x = +CLOUD_3D_SECTOR_SIDE_LENGTH/2;
		cloud_points[1].y = 0;
		cloud_points[1].z = -CLOUD_3D_SECTOR_SIDE_LENGTH/2;

		cloud_points[2].x = +CLOUD_3D_SECTOR_SIDE_LENGTH/2;
		cloud_points[2].y = 0;
		cloud_points[2].z = +CLOUD_3D_SECTOR_SIDE_LENGTH/2;

		cloud_points[3].x = -CLOUD_3D_SECTOR_SIDE_LENGTH/2;
		cloud_points[3].y = 0;
		cloud_points[3].z = +CLOUD_3D_SECTOR_SIDE_LENGTH/2;

		for ( count = 0; count < 4; count++ )
		{

			vec3d
				point_vector;

			int
				ir,
				ig,
				ib;

			float
				colour_t,
				alpha,
				distance,
				angle,
				dr,
				dg,
				db,
				r,
				g,
				b;

			tempx = sector_centre.x + cloud_points[count].x;
			tempz = sector_centre.z + cloud_points[count].z;

			point_vector.x = tempx;
			point_vector.y = 0;
			point_vector.z = tempz;

			distance = get_3d_vector_magnitude ( &point_vector );

			if ( distance > 1 )
			{

				normalise_3d_vector_given_magnitude ( &point_vector, distance );

				angle = ( ( point_vector.x * cloud_colour_blend_vector.x ) + ( point_vector.z * cloud_colour_blend_vector.z ) );
				angle = bound ( angle, 0, 1 );
				angle *= angle;
				angle *= angle;

				colour_t = ( distance / CLOUD_MAXIMUM_COLOUR_BLEND_DISTANCE );
				colour_t = bound ( colour_t, 0, 1 );
				colour_t *= angle;
			}
			else
			{

				colour_t = 0;
			}

			alpha = ( ( cloud_3d_blend_constant - ( distance * distance ) ) * cloud_3d_adjusted_blend_factor );

			cloud_points[count].a = bound ( alpha, 0, 1 );

			dr = active_3d_environment->cloud_light.object_colour.red - active_3d_environment->cloud_light.light_colour.red;
			dg = active_3d_environment->cloud_light.object_colour.green - active_3d_environment->cloud_light.light_colour.green;
			db = active_3d_environment->cloud_light.object_colour.blue - active_3d_environment->cloud_light.light_colour.blue;

			r = active_3d_environment->cloud_light.light_colour.red + ( colour_t * dr );
			g = active_3d_environment->cloud_light.light_colour.green + ( colour_t * dg );
			b = active_3d_environment->cloud_light.light_colour.blue + ( colour_t * db );

			convert_float_to_int ( r * 255.0, &ir );
			convert_float_to_int ( g * 255.0, &ig );
			convert_float_to_int ( b * 255.0, &ib );

			cloud_points[count].red = ir;
			cloud_points[count].green = ig;
			cloud_points[count].blue = ib;
/*
			debug_log ( "( %d, %d, %d ) -> ( %d, %d, %d ) d( %d, %d, %d ) blend = %f = %d, %d, %d",
									active_3d_environment->cloud_light.light_colour.red * 255,
									active_3d_environment->cloud_light.light_colour.green * 255,
									active_3d_environment->cloud_light.light_colour.blue * 255,
									active_3d_environment->cloud_light.object_colour.red * 255,
									active_3d_environment->cloud_light.object_colour.green * 255,
									active_3d_environment->cloud_light.object_colour.blue * 255,
									dr * 255,
									dg * 255,
									db * 255,
									colour_t,
									ir, ig, ib );
*/
		}

		transform_cloud_points ( 4, cloud_points, cloud_transformed_3d_points, &sector_relative_centre );

		//
		// Render a quad twice, for the blending between cloud textures
		//

		if ( cloud_3d_base_height < visual_3d_vp->y )
		{

			point_references[3].point = 0; point_references[3].u = 0; point_references[3].v = 0;
			point_references[2].point = 1; point_references[2].u = 1; point_references[2].v = 0;
			point_references[1].point = 2; point_references[1].u = 1; point_references[1].v = 1;
			point_references[0].point = 3; point_references[0].u = 0; point_references[0].v = 1;
		}
		else
		{

			point_references[0].point = 0; point_references[0].u = 0; point_references[0].v = 0;
			point_references[1].point = 1; point_references[1].u = 1; point_references[1].v = 0;
			point_references[2].point = 2; point_references[2].u = 1; point_references[2].v = 1;
			point_references[3].point = 3; point_references[3].u = 0; point_references[3].v = 1;
		}

		if ( current_weather_texture )
		{

			render_cloud_polygon ( 4, point_references, cloud_transformed_3d_points, cloud_points, cloud_weather_one_minus_blend_factor, current_weather_texture );
		}

		if ( target_weather_texture )
		{

			render_cloud_polygon ( 4, point_references, cloud_transformed_3d_points, cloud_points, cloud_weather_blend_factor, target_weather_texture );
		}
	}
}
Пример #24
0
void render_clipped_3d_terrain_tree_textured_diffuse_lit_polygon ( object_3d_face *this_face, struct OBJECT_3D_INFO *object_base )
{

	vertex
		*poly;

	texture_map
		*texture;

	texture = &system_textures[current_object_3d_surface->texture_index];

	{

		real_colour
			colour;

		float
			red,
			green,
			blue;

		int
			ired,
			igreen,
			iblue;

		//
		// Look up the colour of the face normal
		//

		red = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].r;
		green = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].g;
		blue = current_object_3d_transformed_normals[current_object_3d_face_normal_list->point].b;

		red *= current_tree_colour_red;
		green *= current_tree_colour_green;
		blue *= current_tree_colour_blue;

		convert_float_to_int ( red, &ired );
		convert_float_to_int ( green, &igreen );
		convert_float_to_int ( blue, &iblue );

		colour.red = ired;
		colour.green = igreen;
		colour.blue = iblue;
		colour.alpha = 255;

		poly = NULL;
		/*construct_3d_vertex_textured_polygon ( this_face->number_of_points,
																		current_object_3d_point_list,
																		current_object_3d_texture_list,
																		object_base->points_base );
																		*/
		
		clip_3d_coord = 0;

		if ( current_object_3d_outcode & CLIP_HITHER )
		{
	
			poly = hither_clip_3d_polygon ( poly, &current_object_3d_outcode );

			if ( !poly )
			{

				return;
			}
		}

		if ( current_object_3d_outcode )
		{

			apply_perspective_to_polygon_texture ( poly );
				
			poly = clip_3d_polygon ( poly, current_object_3d_outcode );

			if ( !poly )
			{

				return;
			}

			remove_perspective_from_polygon_texture ( poly );
		}

//		set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMAG, current_object_3d_texture_filter );
//		set_d3d_int_state ( D3DRENDERSTATE_TEXTUREMIN, current_object_3d_texture_mipmap );
//		set_d3d_int_state ( D3DRENDERSTATE_TEXTUREADDRESS, current_object_3d_texture_address );

//		draw_d3d_flat_shaded_textured_polygon ( poly, texture, colour );
	}
}
Пример #25
0
void ui_draw_button (float x1, float y1, float x2, float y2, int state)
{

	float
		new_x1,
		new_y1,
		new_x2,
		new_y2;

	int
		int_x1,
		int_y1,
		int_x2,
		int_y2;


	rgb_colour
		background_colour,
		top_line_colour,
		bottom_line_colour,
		left_line_colour,
		right_line_colour,
		top_left_pixel_colour,
		bottom_left_pixel_colour,
		top_right_pixel_colour,
		bottom_right_pixel_colour;

	x1 -= ui_x_origin;
	y1 -= ui_y_origin;
	x2 -= ui_x_origin;
	y2 -= ui_y_origin;

	new_x1 = x1;

	new_y1 = y1;

	new_x2 = x2;

	new_y2 = y2;

	// clip button to ui viewport

	ui_clip_area (&new_x1, &new_y1, &new_x2, &new_y2);

	// button coords should be in viewport coords,
	// so add ui_origin to convert into screen coords

	x1 += ui_x_origin;

	y1 += ui_y_origin;

	x2 += ui_x_origin;

	y2 += ui_y_origin;

	new_x1 += ui_x_origin;

	new_y1 += ui_y_origin;

	new_x2 += ui_x_origin;

	new_y2 += ui_y_origin;

	// check if possible to draw

	if ((new_x2 - new_x1 < 2) || (new_y2 - new_y1 <= 2))
	{

		return;
	}

	// convert variabless to ints to save crap conversion

	convert_float_to_int (new_x1, &int_x1);
	convert_float_to_int (new_y1, &int_y1);
	convert_float_to_int (new_x2, &int_x2);
	convert_float_to_int (new_y2, &int_y2);

	// assign correct colours

	switch (state)
	{

		case UI_OBJECT_STATE_ON:
		{

			background_colour = ui_button_down_background;
			top_line_colour = ui_button_down_dark_edge;
			bottom_line_colour = ui_button_down_light_edge;
			left_line_colour = ui_button_down_dark_edge;
			right_line_colour = ui_button_down_light_edge;
			top_left_pixel_colour = ui_button_down_dark_edge;
			bottom_left_pixel_colour = ui_button_down_light_edge;
			top_right_pixel_colour = ui_button_down_light_edge;
			bottom_right_pixel_colour = ui_button_down_light_edge;

			break;
		}
		case UI_OBJECT_STATE_OFF:
		{

			background_colour = ui_button_up_background;
			top_line_colour = ui_button_up_light_edge;
			bottom_line_colour = ui_button_up_dark_edge;
			left_line_colour = ui_button_up_light_edge;
			right_line_colour = ui_button_up_dark_edge;
			top_left_pixel_colour = ui_button_up_light_edge;
			bottom_left_pixel_colour = ui_button_up_light_edge;
			top_right_pixel_colour = ui_button_up_light_edge;
			bottom_right_pixel_colour = ui_button_up_dark_edge;

			break;
		}
		case UI_OBJECT_STATE_HIGHLIGHTED:
		{

			background_colour = ui_button_highlighted_background;
			top_line_colour = ui_button_highlighted_light_edge;
			bottom_line_colour = ui_button_highlighted_dark_edge;
			left_line_colour = ui_button_highlighted_light_edge;
			right_line_colour = ui_button_highlighted_dark_edge;
			top_left_pixel_colour = ui_button_highlighted_light_edge;
			bottom_left_pixel_colour = ui_button_highlighted_light_edge;
			top_right_pixel_colour = ui_button_highlighted_light_edge;
			bottom_right_pixel_colour = ui_button_highlighted_dark_edge;

			break;
		}
	}

	// draw background

	if (x1 != new_x1)
	{

		if (y1 != new_y1)
		{

			set_block (int_x1, int_y1, int_x2, int_y2, background_colour);
		}
		else
		{

			set_block (int_x1, int_y1 + 1, int_x2, int_y2, background_colour);
		}
	}
	else if (y1 != new_y1)
	{

		set_block (int_x1 + 1 , int_y1, int_x2, int_y2, background_colour);
	}
	else
	{

		set_block (int_x1 + 1 , int_y1 + 1, int_x2 - 1, int_y2 - 1, background_colour);
	}

	// draw top line

	if (y1 == new_y1)
	{

	  	if ((x1 == new_x1) && (x2 == new_x2))
		{

			draw_line (new_x1 + 2, new_y1, new_x2 - 2, new_y1, top_line_colour);
		}
	  	else if (x1 == new_x1)
		{

			draw_line (new_x1 + 2, new_y1, new_x2, new_y1, top_line_colour);
		}
	  	else if (x2 == new_x2)
		{

			draw_line (new_x1, new_y1, new_x2 - 2, new_y1, top_line_colour);
		}
	  	else
		{

			draw_line (new_x1, new_y1, new_x2, new_y1, top_line_colour);
		}
	}

	// draw botton line

	if (y2 == new_y2)
	{

	  	if ((x1 == new_x1) && (x2 == new_x2))
		{

			draw_line (new_x1 + 2, new_y2, new_x2 - 2, new_y2, bottom_line_colour);
		}
	  	else if (x1 == new_x1)
		{

			draw_line (new_x1 + 2, new_y2, new_x2, new_y2, bottom_line_colour);
		}
	  	else if (x2 == new_x2)
		{

			draw_line (new_x1, new_y2, new_x2 - 2, new_y2, bottom_line_colour);
		}
	  	else
		{

			draw_line (new_x1, new_y2, new_x2, new_y2, bottom_line_colour);
		}
	}

	// draw left side

	if (x1 == new_x1)
	{

	  	if ((y1 == new_y1) && (y2 == new_y2))
		{

			draw_line (new_x1, new_y1 + 2, new_x1, new_y2 - 2, left_line_colour);
		}
	  	else if (y1 == new_y1)
		{

			draw_line (new_x1, new_y1 + 2, new_x1, new_y2, left_line_colour);
		}
	  	else if (y2 == new_y2)
		{

			draw_line (new_x1, new_y1, new_x1, new_y2 - 2, left_line_colour);
		}
	  	else
		{

			draw_line (new_x1, new_y1, new_x1, new_y2, left_line_colour);
		}
	}

	// draw right side

	if (x2 == new_x2)
	{

	  	if ((y1 == new_y1) && (y2 == new_y2))
		{

			draw_line (new_x2, new_y1 + 2, new_x2, new_y2 - 2, right_line_colour);
		}
	  	else if (y1 == new_y1)
		{

			draw_line (new_x2, new_y1 + 2, new_x2, new_y2, right_line_colour);
		}
	  	else if (y2 == new_y2)
		{

			draw_line (new_x2, new_y1, new_x2, new_y2 - 2, right_line_colour);
		}
	  	else
		{

			draw_line (new_x2, new_y1, new_x2, new_y2, right_line_colour);
		}
	}

	// draw odd pixels in corners

	if (x1 == new_x1)
	{

		// top left
		if (y1 == new_y1)
		{

			set_pixel (int_x1 + 1, int_y1 + 1, top_left_pixel_colour);
		}

		// bottom left
		if (y2 == new_y2)
		{

			set_pixel (int_x1 + 1, int_y2 - 1, bottom_left_pixel_colour);
		}
	}

	if (x2 == new_x2)
	{

		// top right
		if (y1 == new_y1)
		{

			set_pixel (int_x2 - 1, int_y1 + 1, top_right_pixel_colour);
		}

		// bottom right
		if (y2 == new_y2)
		{

			set_pixel (int_x2 - 1, int_y2 - 1, bottom_right_pixel_colour);
		}
	}
}
Пример #26
0
void draw_buffered_sorted_terrain_trees ( void )
{

	buffered_tree
		*tree;

	tree = buffered_sorted_tree_tail;

	while ( tree )
	{

		//
		// Draw a tree object at ( x, y, z )
		//

		terrain_3d_tree_object->vp.x = tree->position.x;
		terrain_3d_tree_object->vp.y = tree->position.y;
		terrain_3d_tree_object->vp.z = tree->position.z;

		terrain_3d_tree_object->relative_scale.x = tree->scale.x;
		terrain_3d_tree_object->relative_scale.y = tree->scale.y;
		terrain_3d_tree_object->relative_scale.z = tree->scale.z;

		get_3d_transformation_matrix ( terrain_3d_tree_object->vp.attitude, 0, 0, 0 );

		set_object_3d_instance_relative_position ( terrain_3d_tree_object );

		if ( get_object_3d_instance_visibility ( terrain_3d_tree_object ) != OBJECT_3D_NOT_VISIBLE )
		{

			if ( terrain_3d_tree_object->rel_vp.z < 1024.0 )
			{

				float
					alpha;

				int
					ialpha;

				current_tree_colour_red = tree->colour.red;
				current_tree_colour_green = tree->colour.green;
				current_tree_colour_blue = tree->colour.blue;

				current_tree_colour_red /= 255.0;
				current_tree_colour_green /= 255.0;
				current_tree_colour_blue /= 255.0;

				//
				// Set the alpha value here
				//

				if ( terrain_3d_tree_object->rel_vp.z > 512.0 )
				{

					alpha = 1024.0 - terrain_3d_tree_object->rel_vp.z;
					alpha /= 512.0;

					convert_float_to_int ( ( alpha * 255 ), &ialpha );
					current_tree_colour_alpha = ialpha;
				}
				else
				{

					current_tree_colour_alpha = 255;
				}

				current_tree_colour_alpha = 255;

				draw_3d_terrain_tree ( terrain_3d_tree_object );
			}
		}

		tree = tree->pred;
	}
}
Пример #27
0
static void update_weapon_loading_gunship_page (ui_object *obj, void *arg)
{
	entity
		*en;

	gunship_types
		gunship;

	weapon_loading_hardpoint_types
		hardpoint;

	int
		count,
		fixed,
		auw,
		weapon_type;

	float
		mass;

	ui_object
		*button_object;

	rgb_colour
		*col;

	ASSERT (obj);

	en = get_local_entity_safe_ptr (get_ui_object_item_number (obj));

	ASSERT (en);

	gunship = get_local_entity_int_value (en, INT_TYPE_GUNSHIP_TYPE);

	ASSERT (gunship < NUM_GUNSHIP_TYPES);

	if (get_helicopter_allowed_to_rearm (en))
	{
		fixed = FALSE;
	}
	else
	{
		fixed = TRUE;
	}

	//
	// Set button text
	//

	for (hardpoint = 0; hardpoint < NUM_WEAPON_LOADING_HARDPOINT_TYPES; hardpoint ++)
	{
		if (weapon_loading_button_list [gunship][hardpoint].valid)
		{
			button_object = weapon_loading_button_list [gunship][hardpoint].button_ptr;

			weapon_type = weapon_loading_get_current_hardpoint_weapon (gunship, hardpoint);

			//
			// Set Text
			//

			if (weapon_type != ENTITY_SUB_TYPE_WEAPON_NO_WEAPON)
			{
				count = get_weapon_loading_hardpoint_weapon_count (en, hardpoint, weapon_type);

				sprintf (buffer, "%dx %s", count, weapon_database [weapon_type].weapon_loading_list_name);
			}
			else
			{
				sprintf (buffer, "%s", weapon_database [weapon_type].weapon_loading_list_name);
			}

			set_ui_object_text (button_object, buffer);

			//
			// Set Button Attributes
			//

			if ((fixed) || (weapon_loading_get_valid_weapon_count (en, hardpoint) < 2))
			{
				set_ui_object_notify_on (button_object, NOTIFY_TYPE_NONE);

				set_ui_object_highlightable (button_object, FALSE);

				col = &ui_ingame_dead_text_colour;

				set_ui_object_font_colour (button_object, col->r, col->g, col->b, col->a);
			}
			else
			{
				set_ui_object_notify_on (button_object, NOTIFY_TYPE_BUTTON_DOWN);

				set_ingame_ui_object_mouse_over_properties (button_object);
			}
		}
	}

	//
	// All-Up-Weight (player only)
	//

	if (en == get_gunship_entity ())
	{
		mass = set_flight_dynamics_mass ();

		convert_float_to_int (mass, &auw);

		sprintf (buffer, "%s: %dkg", get_trans ("All Up Weight"), auw);

		set_ui_object_text (page_auw_text, buffer);
	}
	else
	{
		set_ui_object_text (page_auw_text, "");
	}

	//
	// Fuel Page (player only)
	//

	if (en == get_gunship_entity ())
	{
		sprintf (buffer, " %.0fkg", get_current_flight_dynamics_fuel_weight ());

		set_ui_object_text (page_fuel_gauge, buffer);

		set_ui_object_drawable (page_fuel_text, TRUE);

		set_ui_object_drawable (page_fuel_gauge, TRUE);

		draw_weapon_loading_gauge (page_fuel_gauge, get_dynamics_normalised_fuel_value ());
	}
	else
	{
		set_ui_object_drawable (page_fuel_text, FALSE);

		set_ui_object_drawable (page_fuel_gauge, FALSE);
	}

	//
	// Damage Page (player only)
	//

	set_ui_object_drawable (page_repairing_text, FALSE);

	set_ui_object_drawable (page_repairing_gauge, FALSE);

	if (en == get_gunship_entity ())
	{
		int
			repair_index;

		float
			level,
			repair_time;

		if (current_flight_dynamics->repairing_damage != DYNAMICS_DAMAGE_NONE)
		{
			repair_index = get_dynamics_damage_currently_repairing_type ();

			repair_time = dynamics_damage_database [repair_index].repair_time;

			if (repair_time == 0.0)
			{
				level = 1.0;
			}
			else
			{
				level = 1.0 - (current_flight_dynamics->damage_repair_time / repair_time);

				level = bound (level, 0.0, 1.0);
			}

			sprintf (buffer, " %s", get_trans (dynamics_damage_database [repair_index].name));

			set_ui_object_text (page_repairing_gauge, buffer);

			set_ui_object_drawable (page_repairing_text, TRUE);

			set_ui_object_drawable (page_repairing_gauge, TRUE);

			draw_weapon_loading_gauge (page_repairing_gauge, level);
		}
	}
}
Пример #28
0
void draw_line ( float fx1, float fy1, float fx2, float fy2, rgb_colour colour )
{

	ASSERT ( active_screen );

	if ( get_screen_locked ( active_screen ) )
	{
	
		int
			x1,
			y1,
			x2,
			y2,
			dx,
			dy,
			error,
			screen_pitch;
		

		unsigned char
			*screen_data;
	
		if ( active_screen->pixel_length <= 16 )
		{
		
			unsigned short int
				col;
	
			col = get_packed_colour (colour);
		
			screen_data = get_screen_data (active_screen);
			screen_pitch = get_screen_pitch (active_screen);
		
			convert_float_to_int ( fx1, &x1 );
			convert_float_to_int ( fy1, &y1 );
			convert_float_to_int ( fx2, &x2 );
			convert_float_to_int ( fy2, &y2 );
		
			dx = x2 - x1;
		
			if ( dx < 0 )
			{
		
				dx = -dx;
		
				dy = y2 - y1;
		
				if ( dy < 0 )
				{
		
					dy = -dy;
		
					if ( dx > dy )
					{
		
						error = ( ( dx + 1 ) >> 1 );
		
						for ( ; x1 >= x2; x1-- )
						{
		
							*((USHORT *) (screen_data + y1 * screen_pitch) + x1) = col;
		
							if ( ( error -= dy ) <= 0 )
							{
		
								error += dx;
		
								y1--;
							}
						}
					}
					else
					{