Exemple #1
0
void draw_hokum_virtual_cockpit_periscope_mask (void)
{
	vertex
		quad[4];

	real_colour
		colour,
		specular;

	set_3d_active_environment (main_3d_env);

	if (begin_3d_scene ())
	{
		colour.red		= 255;
		colour.green	= 255;
		colour.blue		= 255;
		colour.alpha	= 255;

		specular.red	= 0;
		specular.green	= 0;
		specular.blue	= 0;
		specular.alpha	= 255;

		set_d3d_transparency_on ();

		set_d3d_zbuffer_comparison (FALSE);

		set_d3d_culling (FALSE);

		set_d3d_texture_wrapping (0, FALSE);

		set_d3d_texture_filtering (FALSE);

		set_d3d_flat_shaded_textured_renderstate (get_system_texture_ptr (TEXTURE_INDEX_HOKUM_COCKPIT_WSO_SCOPE_VIEW));

		////////////////////////////////////////
		//
		// top left
		//
		////////////////////////////////////////

		quad[0].i 				= full_screen_x_min;
		quad[0].j  				= full_screen_y_min;
		quad[0].z  				= 0.5;
		quad[0].q  				= 0.5;
		quad[0].u  				= 0.0;
		quad[0].v				= 0.0;

		quad[1].i  				= full_screen_x_mid;
		quad[1].j  				= full_screen_y_min;
		quad[1].z  				= 0.5;
		quad[1].q  				= 0.5;
		quad[1].u  				= 1.0;
		quad[1].v  				= 0.0;

		quad[2].i				= full_screen_x_mid;
		quad[2].j  				= full_screen_y_mid;
		quad[2].z  				= 0.5;
		quad[2].q  				= 0.5;
		quad[2].u  				= 1.0;
		quad[2].v  				= 1.0;

		quad[3].i  				= full_screen_x_min;
		quad[3].j  				= full_screen_y_mid;
		quad[3].z  				= 0.5;
		quad[3].q  				= 0.5;
		quad[3].u				= 0.0;
		quad[3].v				= 1.0;

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

		draw_wbuffered_flat_shaded_textured_polygon (quad, colour, specular);

		////////////////////////////////////////
		//
		// bottom left
		//
		////////////////////////////////////////

		quad[0].i 				= full_screen_x_min;
		quad[0].j  				= full_screen_y_mid;
		quad[0].z  				= 0.5;
		quad[0].q  				= 0.5;
		quad[0].u  				= 0.0;
		quad[0].v				= 1.0;

		quad[1].i  				= full_screen_x_mid;
		quad[1].j  				= full_screen_y_mid;
		quad[1].z  				= 0.5;
		quad[1].q  				= 0.5;
		quad[1].u  				= 1.0;
		quad[1].v  				= 1.0;

		quad[2].i				= full_screen_x_mid;
		quad[2].j  				= full_screen_y_max;
		quad[2].z  				= 0.5;
		quad[2].q  				= 0.5;
		quad[2].u  				= 1.0;
		quad[2].v  				= 0.0;

		quad[3].i  				= full_screen_x_min;
		quad[3].j  				= full_screen_y_max;
		quad[3].z  				= 0.5;
		quad[3].q  				= 0.5;
		quad[3].u				= 0.0;
		quad[3].v				= 0.0;

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

		draw_wbuffered_flat_shaded_textured_polygon (quad, colour, specular);

		////////////////////////////////////////
		//
		// top right
		//
		////////////////////////////////////////

		quad[0].i 				= full_screen_x_mid;
		quad[0].j  				= full_screen_y_min;
		quad[0].z  				= 0.5;
		quad[0].q  				= 0.5;
		quad[0].u  				= 1.0;
		quad[0].v				= 0.0;

		quad[1].i  				= full_screen_x_max;
		quad[1].j  				= full_screen_y_min;
		quad[1].z  				= 0.5;
		quad[1].q  				= 0.5;
		quad[1].u  				= 0.0;
		quad[1].v  				= 0.0;

		quad[2].i				= full_screen_x_max;
		quad[2].j  				= full_screen_y_mid;
		quad[2].z  				= 0.5;
		quad[2].q  				= 0.5;
		quad[2].u  				= 0.0;
		quad[2].v  				= 1.0;

		quad[3].i  				= full_screen_x_mid;
		quad[3].j  				= full_screen_y_mid;
		quad[3].z  				= 0.5;
		quad[3].q  				= 0.5;
		quad[3].u				= 1.0;
		quad[3].v				= 1.0;

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

		draw_wbuffered_flat_shaded_textured_polygon (quad, colour, specular);

		////////////////////////////////////////
		//
		// bottom left
		//
		////////////////////////////////////////

		quad[0].i 				= full_screen_x_mid;
		quad[0].j  				= full_screen_y_mid;
		quad[0].z  				= 0.5;
		quad[0].q  				= 0.5;
		quad[0].u  				= 1.0;
		quad[0].v				= 1.0;

		quad[1].i  				= full_screen_x_max;
		quad[1].j  				= full_screen_y_mid;
		quad[1].z  				= 0.5;
		quad[1].q  				= 0.5;
		quad[1].u  				= 0.0;
		quad[1].v  				= 1.0;

		quad[2].i				= full_screen_x_max;
		quad[2].j  				= full_screen_y_max;
		quad[2].z  				= 0.5;
		quad[2].q  				= 0.5;
		quad[2].u  				= 0.0;
		quad[2].v  				= 0.0;

		quad[3].i  				= full_screen_x_mid;
		quad[3].j  				= full_screen_y_max;
		quad[3].z  				= 0.5;
		quad[3].q  				= 0.5;
		quad[3].u				= 1.0;
		quad[3].v				= 0.0;

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

		draw_wbuffered_flat_shaded_textured_polygon (quad, colour, specular);

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

		set_d3d_transparency_off ();

		set_d3d_zbuffer_comparison (TRUE);

		set_d3d_culling (TRUE);

		end_3d_scene ();
	}
}
Exemple #2
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 );
		}
	}
}
Exemple #3
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 );
}