Example #1
0
void draw_temporary_translucent_polygons ( void )
{

	int
		vertex_index,
		count;

	//
	// No need to set the default blending mode, as each buffered polygon will set it itself
	//

	vertex_index = 0;

	set_d3d_int_state ( D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD );

	//
	// Flush any buffered vertex buffers
	//

	finalise_primitives ();

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

		LPD3DTLVERTEX
			vertices;

		set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, temporary_polygons[count].source_alpha_blend );
		set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, temporary_polygons[count].destination_alpha_blend );

		if ( temporary_polygons[count].texture )
		{

			set_d3d_texture ( 0, load_hardware_texture_map ( temporary_polygons[count].texture ) );
			set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_MODULATE );

			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSU, temporary_polygons[count].texture_u_address );
			set_d3d_texture_stage_state ( 0, D3DTSS_ADDRESSV, temporary_polygons[count].texture_v_address );
			set_d3d_texture_stage_state ( 0, D3DTSS_MAGFILTER, temporary_polygons[count].texture_mag );
			set_d3d_texture_stage_state ( 0, D3DTSS_MINFILTER, temporary_polygons[count].texture_mag );
			set_d3d_texture_stage_state ( 0, D3DTSS_MIPFILTER, temporary_polygons[count].texture_min );
		}
		else
		{

			set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
			set_d3d_texture ( 0, NULL );
		}


		if ( temporary_polygons[count].number_of_vertices > 2 )
		{

			vertices = get_d3d_vertices_points_address ( temporary_polygons[count].number_of_vertices );

			memcpy ( vertices, &temporary_vertices[vertex_index], sizeof ( D3DTLVERTEX ) * temporary_polygons[count].number_of_vertices );

			draw_fan_primitive ( temporary_polygons[count].number_of_vertices, vertices );
		}
		else
		{

			vertices = get_d3d_line_vertices_points_address ();

			memcpy ( vertices, &temporary_vertices[vertex_index], sizeof ( D3DTLVERTEX ) * 2 );

			draw_line_primitive ( vertices );
		}

		vertex_index += temporary_polygons[count].number_of_vertices;
	}
}
Example #2
0
void draw_terrain_3d_buffered_polygons ( void )
{


	if ( vertex_buffer != -1 )
	{

		//
		// Finalise the last vertex buffer used
		//

		unlock_d3d_alpha_vertex_buffer ( vertex_buffer );

		vertex_buffer_indices[vertex_buffer].number = base_index - vertex_buffer_indices[vertex_buffer].base_index;

		if ( base_index )
		{

			int
				count;

			//
			// Flush any buffered primitives
			//

			finalise_primitives ();

			//
			// Set the alpha blend modes
			//

			set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, TRUE, FALSE );

			//
			// Set the texture handle
			//

			set_d3d_texture ( 0, load_hardware_texture_map ( terrain_buffered_polygons_texture ) );

			//
			// Draw all the buffered vertex buffers
			//


			for ( count = 0; count <= vertex_buffer; count++ )
			{
#ifdef _WIN32
				unsigned int
					d3drval;

				d3drval = IDirect3DDevice7_DrawIndexedPrimitiveVB ( d3d.device, D3DPT_TRIANGLELIST, d3d.alpha_vertex_buffer[count],
																						0,
																						vertex_buffer_indices[count].number_of_vertices_buffered,
																						&buffered_indices[ vertex_buffer_indices[count].base_index ],
																						vertex_buffer_indices[count].number,
																						( unsigned long ) ( 0 ) );

				if ( d3drval != DD_OK )
				{

					debug_log ( "Unable to draw buffered triangles: %s", get_ddraw_error_message ( d3drval ) );
				}
#endif

Transform();



glVertexPointer(3, GL_FLOAT, sizeof(D3DTLVERTEX), 0);
glColorPointer(4, GL_UNSIGNED_BYTE, sizeof(D3DTLVERTEX), (GLvoid *) offsetof(D3DTLVERTEX, r));
glTexCoordPointer(2, GL_FLOAT, sizeof(D3DTLVERTEX), (GLvoid *) offsetof(D3DTLVERTEX, tu));

glDrawElements(GL_TRIANGLES,vertex_buffer_indices[count].number,GL_UNSIGNED_SHORT, (GLvoid *) buffered_indices[ vertex_buffer_indices[count].base_index]);
      //  OpenGlDrawIndexedBuffer(GL_TRIANGLES,d3d.alpha_vertex_buffer[count],0,vertex_buffer_indices[count].number_of_vertices_buffered,
        //                       buffered_indices[ vertex_buffer_indices[count].base_index]);

			}

			//
			// Turn the blend mode off
			//

			set_d3d_alpha_fog_zbuffer ( FALSE, TRUE, TRUE, TRUE );
		}

		//
		// Reset the things!
		//

		reset_terrain_3d_buffered_polygons ();
	}

}
Example #3
0
void draw_terrain_3d_buffered_polygons ( void )
{

	if ( vertex_buffer != -1 )
	{

		//
		// Finalise the last vertex buffer used
		//

		unlock_d3d_alpha_vertex_buffer ( vertex_buffer );

		vertex_buffer_indices[vertex_buffer].number = base_index - vertex_buffer_indices[vertex_buffer].base_index;

		if ( base_index )
		{

			int
				count;

			//
			// Flush any buffered primitives
			//

			finalise_primitives ();

			//
			// Set the alpha blend modes
			//
	
			set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, TRUE, FALSE );
	
			//
			// Set the texture handle
			//
	
			set_d3d_texture ( 0, terrain_buffered_polygons_texture );
	
			//
			// Draw all the buffered vertex buffers
			//

			for ( count = 0; count <= vertex_buffer; count++ )
			{
				f3d_draw_vb ( D3DPT_TRIANGLELIST, d3d.alpha_vertex_buffer[count],
																						0,
																						vertex_buffer_indices[count].number_of_vertices_buffered,
																						&buffered_indices[ vertex_buffer_indices[count].base_index ],
																						vertex_buffer_indices[count].number );
			}

			//
			// Turn the blend mode off
			//
	
			set_d3d_alpha_fog_zbuffer ( FALSE, TRUE, TRUE, TRUE );
		}

		//
		// Reset the things!
		//

		reset_terrain_3d_buffered_polygons ();
	}
}
Example #4
0
void draw_3d_moon ( void )
{


	vertex
		*moon_polygon,
		*vert,
		moon_quad[4];

	int
		outcode,
		outcode2,
		count;

	float
		moon_width,
		moon_height,
		moon_depth;

	matrix3x3
		moon_matrix;

	int
		moon_red,
		moon_green,
		moon_blue;

	real_colour
		colour,
		specular;

	moon_polygon = moon_quad;

	moon_width = 12000;
	moon_height = 12000;
	moon_depth = 100000;

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

	moon_quad[0].x = -moon_width/2;
	moon_quad[0].y = moon_height/2;
	moon_quad[0].z = moon_depth;
	moon_quad[0].u = 0;
	moon_quad[0].v = 0;

	moon_quad[1].x = moon_width/2;
	moon_quad[1].y = moon_height/2;
	moon_quad[1].z = moon_depth;
	moon_quad[1].u = 1;
	moon_quad[1].v = 0;

	moon_quad[2].x = moon_width/2;
	moon_quad[2].y = -moon_height/2;
	moon_quad[2].z = moon_depth;
	moon_quad[2].u = 1;
	moon_quad[2].v = 1;

	moon_quad[3].x = -moon_width/2;
	moon_quad[3].y = -moon_height/2;
	moon_quad[3].z = moon_depth;
	moon_quad[3].u = 0;
	moon_quad[3].v = 1;

	//
	// Rotate the moon into position
	//

	get_3d_transformation_matrix ( moon_matrix, moon_3d_heading, moon_3d_pitch, 0 );

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

		float
			x,
			y,
			z;


		x = moon_quad[count].x * moon_matrix[0][0] + moon_quad[count].y * moon_matrix[1][0] + moon_quad[count].z * moon_matrix[2][0];
		y = moon_quad[count].x * moon_matrix[0][1] + moon_quad[count].y * moon_matrix[1][1] + moon_quad[count].z * moon_matrix[2][1];
		z = moon_quad[count].x * moon_matrix[0][2] + moon_quad[count].y * moon_matrix[1][2] + moon_quad[count].z * moon_matrix[2][2];

		moon_quad[count].x = x;
		moon_quad[count].y = y;
		moon_quad[count].z = z;
	}

	//
	// Clip the moon to the horizon
	//

	clip_3d_coord = 0;

	moon_polygon = horizon_clip_3d_polygon ( moon_quad );

	if ( moon_polygon )
	{

		//
		// Rotate the polygon around to the users viewpoint
		//

		vert = moon_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;

		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];
			y = vert->x * rotation_3d[0][1] + vert->y * rotation_3d[1][1] + vert->z * rotation_3d[2][1];
			z = vert->x * rotation_3d[0][2] + vert->y * rotation_3d[1][2] + vert->z * rotation_3d[2][2];

			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 )
		{

			moon_polygon = hither_clip_3d_polygon ( moon_polygon, &outcode );

			if ( !moon_polygon )
			{

				return;
			}
		}

		if ( outcode )
		{

			apply_perspective_to_polygon_texture ( moon_polygon );

			moon_polygon = clip_3d_polygon ( moon_polygon, outcode );

			if ( !moon_polygon )
			{

				return;
			}

			remove_perspective_from_polygon_texture ( moon_polygon );
		}

		asm_convert_float_to_int ( ( moon_colour.red * 255 ), &moon_red );
		asm_convert_float_to_int ( ( moon_colour.green * 255 ), &moon_green );
		asm_convert_float_to_int ( ( moon_colour.blue * 255 ), &moon_blue );

		colour.red = moon_red;
		colour.green = moon_green;
		colour.blue = moon_blue;

		specular.colour = 0;

		set_d3d_int_state ( D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
		set_d3d_int_state ( D3DRENDERSTATE_ZWRITEENABLE, FALSE );

		suspend_d3d_fog ();

		set_d3d_int_state ( D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD );
		set_d3d_int_state ( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
		set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, ADDITIVE_SOURCE_BLEND );
		set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, ADDITIVE_DESTINATION_BLEND );

		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_COLOROP, D3DTOP_MODULATE );
        set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

		set_d3d_texture ( 0, load_hardware_texture_map ( moon_texture ) );

		draw_wbuffered_flat_shaded_textured_polygon ( moon_polygon, colour, specular );

		set_d3d_int_state ( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );

		set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
		set_d3d_texture ( 0, NULL );

		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

		reinstate_d3d_fog ();

		set_d3d_int_state ( D3DRENDERSTATE_ZFUNC, zbuffer_default_comparison );
		set_d3d_int_state ( D3DRENDERSTATE_ZWRITEENABLE, TRUE );
	}
}
Example #5
0
void draw_3d_sun ( void )
{

	vertex
		*sun_polygon,
		sun_quad[4];

	matrix3x3
		sun_matrix;

	float
		flare_intensity;

	int
		sun_red,
		sun_green,
		sun_blue;

	real_colour
		colour,
		specular;

	//
	// Draw the main sun object
	//

	get_3d_transformation_matrix ( sun_matrix, sun_3d_heading, sun_3d_pitch, 0 );

	sun_polygon = construct_sun_polygon ( sun_matrix, sun_quad, 32000 * sun_3d_scale, 32000 * sun_3d_scale, 100000 );

	specular.colour = 0;

	if ( sun_polygon )
	{

		asm_convert_float_to_int ( ( sun_3d_colour.red * 255 ), &sun_red );
		asm_convert_float_to_int ( ( sun_3d_colour.green * 255 ), &sun_green );
		asm_convert_float_to_int ( ( sun_3d_colour.blue * 255 ), &sun_blue );

		colour.red = sun_red;
		colour.green = sun_green;
		colour.blue = sun_blue;

		set_d3d_int_state ( D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
		set_d3d_int_state ( D3DRENDERSTATE_ZWRITEENABLE, FALSE );

		suspend_d3d_fog ();

		set_d3d_int_state ( D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT );
		set_d3d_int_state ( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
		set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, ADDITIVE_SOURCE_BLEND );
		set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, ADDITIVE_DESTINATION_BLEND );

		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_COLOROP, D3DTOP_MODULATE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		set_d3d_texture ( 0, load_hardware_texture_map ( sun_texture ) );

		draw_wbuffered_flat_shaded_textured_polygon ( sun_polygon, colour, specular );
	}

	//
	// Now render the flare around the sun, if it is indeed there.
	//

	//
	// Calculate the intensity of the sun flare
	//

	flare_intensity = (	( sun_matrix[2][0] * visual_3d_vp->zv.x ) +
							 	( sun_matrix[2][1] * visual_3d_vp->zv.y ) +
							 	( sun_matrix[2][2] * visual_3d_vp->zv.z ) );

	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;
	flare_intensity *= flare_intensity;

	flare_intensity *= sun_3d_intensity;
	flare_intensity *= sun_3d_intensity;
	flare_intensity *= sun_3d_intensity;

	flare_intensity *= 255;

	sun_polygon = construct_sun_polygon ( sun_matrix, sun_quad, 144000, 69750, 100000 );

	if ( sun_polygon )
	{

		asm_convert_float_to_int ( ( ( 74.0 / 255.0 ) * flare_intensity ), &sun_red );
		asm_convert_float_to_int ( ( ( 177.0 / 255.0 ) * flare_intensity ), &sun_green );
		asm_convert_float_to_int ( ( ( 248.0 / 255.0 ) * flare_intensity ), &sun_blue );
//		asm_convert_float_to_int ( ( sun_3d_colour.red * flare_intensity ), &sun_red );
//		asm_convert_float_to_int ( ( sun_3d_colour.green * flare_intensity ), &sun_green );
//		asm_convert_float_to_int ( ( sun_3d_colour.blue * flare_intensity ), &sun_blue );

		colour.red = sun_red;
		colour.green = sun_green;
		colour.blue = sun_blue;

		set_d3d_int_state ( D3DRENDERSTATE_ZFUNC, D3DCMP_ALWAYS );
		set_d3d_int_state ( D3DRENDERSTATE_ZWRITEENABLE, FALSE );

		suspend_d3d_fog ();

		set_d3d_int_state ( D3DRENDERSTATE_SHADEMODE, D3DSHADE_FLAT );
		set_d3d_int_state ( D3DRENDERSTATE_ALPHABLENDENABLE, TRUE );
		set_d3d_int_state ( D3DRENDERSTATE_SRCBLEND, ADDITIVE_SOURCE_BLEND );
		set_d3d_int_state ( D3DRENDERSTATE_DESTBLEND, ADDITIVE_DESTINATION_BLEND );

		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_COLOROP, D3DTOP_MODULATE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

		set_d3d_texture ( 0, load_hardware_texture_map ( sun_flare_texture ) );

		draw_wbuffered_flat_shaded_textured_polygon ( sun_polygon, colour, specular );
	}

	set_d3d_int_state ( D3DRENDERSTATE_ALPHABLENDENABLE, FALSE );

	set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
	set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
	set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );
	set_d3d_texture ( 0, NULL );

	set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );
	set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

	reinstate_d3d_fog ();

	set_d3d_int_state ( D3DRENDERSTATE_ZFUNC, zbuffer_default_comparison );
	set_d3d_int_state ( D3DRENDERSTATE_ZWRITEENABLE, TRUE );
}
Example #6
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 );
		}
	}
}
Example #7
0
void draw_3d_rain ( void )
{

	point_3d_plain_reference
		rain_point_references[2];

	int
		count,
		outcode;

	//
	// Calculate the rotation matrix, to transform rain drops relative to the view.
	//

	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 );

	if ( rain_3d_raindrops_valid )
	{

		int
			number_of_valid_raindrops;

		float
			rain_intensity;

		int
			rain_whiteness;


		rain_intensity = ambient_3d_light.colour.red * 0.3 + ambient_3d_light.colour.green * 0.59 * ambient_3d_light.colour.blue * 0.11;

		rain_intensity *= 4;

		rain_intensity *= 255;

		rain_intensity = bound ( rain_intensity, 0, 255 );

		rain_whiteness = rain_intensity;

		//
		// Remeber the number of valid raindrops
		//

		number_of_valid_raindrops = rain_3d_raindrops_valid;

		//
		// Rotate the rain - putting the results in transformed_3d_points
		//

		transform_3d_rain ();

		//
		// Go through pairing up the transformed points, drawing lines between them.
		//

		rain_point_references[0].point = 0;
		rain_point_references[1].point = 1;

		set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, TRUE, FALSE );

		set_d3d_int_state ( D3DRENDERSTATE_SHADEMODE, D3DSHADE_GOURAUD );

		set_d3d_texture ( 0, NULL );

		set_d3d_texture_stage_state ( 0, D3DTSS_COLOROP, D3DTOP_DISABLE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_DISABLE );

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

			vertex
				*line;

			//
			// Construct the 3d line
			//

			clip_3d_coord = 0;

			line = construct_3d_line ( rain_point_references, ( count * 2 ), &outcode );

			if ( line )
			{

				line->red = rain_whiteness;
				line->green = rain_whiteness;
				line->blue = rain_whiteness;
				line->alpha = 32;

				line->next_vertex->red = rain_whiteness;
				line->next_vertex->green = rain_whiteness;
				line->next_vertex->blue = rain_whiteness;
				line->next_vertex->alpha = 192;

				if ( outcode & CLIP_HITHER )
				{

					line = hither_clip_3d_polygon ( line, &outcode );
				}

				if ( line )
				{

					if ( outcode )
					{

						line = clip_3d_polygon ( line, outcode );
					}

					if ( line )
					{

						vertex
							*point1,
							*point2;

						LPD3DTLVERTEX
							vertices,
							vptr;

						vertices = get_d3d_line_vertices_points_address ();

						vptr = vertices;

						point2 = line;

						point1 = line->next_vertex;

						*( ( int * ) &vptr->sx ) = *( ( int * ) &point1->i );
						*( ( int * ) &vptr->sy ) = *( ( int * ) &point1->j );
						*( ( int * ) &vptr->rhw ) = *( ( int * ) &point1->q );
						vptr->sz = ( point1->q * zbuffer_factor ) + zbuffer_constant;

                        vptr->r = point1->red;
                        vptr->g = point1->green;
                        vptr->b = point1->blue;
                        vptr->a = point1->alpha;
						vptr->color = point1->colour;
						vptr->specular = d3d_fog_intensity;

						vptr++;

						*( ( int * ) &vptr->sx ) = *( ( int * ) &point2->i );
						*( ( int * ) &vptr->sy ) = *( ( int * ) &point2->j );
						*( ( int * ) &vptr->rhw ) = *( ( int * ) &point2->q );
						vptr->sz = ( point2->q * zbuffer_factor ) + zbuffer_constant;

                        vptr->r = point2->red;
                        vptr->g = point2->green;
                        vptr->b = point2->blue;
                        vptr->a = point2->alpha;
						vptr->color = point2->colour;
						vptr->specular = d3d_fog_intensity;

						draw_line_primitive ( vertices );
					}
				}
			}
		}

		flush_line_primitives ();

		set_d3d_alpha_fog_zbuffer ( FALSE, TRUE, TRUE, TRUE );
	}

	if ( rain_3d_snowdrops_valid )
	{

		real_colour
			snow_specular,
			snow_colour;

		//
		// Rotate the rain - putting the results in transformed_3d_points
		//

		transform_3d_snow ();

		set_d3d_alpha_fog_zbuffer ( TRUE, FALSE, FALSE, FALSE );

		//
		// First, set the snow texture
		//

		set_d3d_texture ( 0, load_hardware_texture_map ( snow_3d_texture ) );

		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_COLOROP, D3DTOP_MODULATE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_COLORARG2, D3DTA_DIFFUSE );

		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAOP, D3DTOP_MODULATE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG1, D3DTA_TEXTURE );
		set_d3d_texture_stage_state ( 0, D3DTSS_ALPHAARG2, D3DTA_DIFFUSE );

		snow_colour.red = 255;
		snow_colour.green = 255;
		snow_colour.blue = 255;
		snow_colour.alpha = 255;

		snow_specular.colour = d3d_fog_intensity;

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

			vertex
				*poly,
				snow_quad[4];

			if ( !transformed_3d_points[count].outcode )
			{

				float
					width,
					height;

				int
					outcode;

				//
				// We know the raindrop is on the screen ( to a certain extent )
				//

				width = active_3d_environment->screen_i_scale * snow_particle_radius * transformed_3d_points[count].q;
				height = active_3d_environment->screen_j_scale * snow_particle_radius * transformed_3d_points[count].q;

				snow_quad[0].q = transformed_3d_points[count].q;
				snow_quad[0].i = transformed_3d_points[count].i - ( width / 2 );
				snow_quad[0].j = transformed_3d_points[count].j - ( height / 2 );
				snow_quad[0].u = 0;
				snow_quad[0].v = 0;
				snow_quad[0].outcode = generate_3d_outcode ( snow_quad[0].i, snow_quad[0].j );
				snow_quad[0].next_vertex = &snow_quad[1];

				snow_quad[1].q = transformed_3d_points[count].q;
				snow_quad[1].i = transformed_3d_points[count].i + ( width / 2 );
				snow_quad[1].j = transformed_3d_points[count].j - ( height / 2 );
				snow_quad[1].u = 1;
				snow_quad[1].v = 0;
				snow_quad[1].outcode = generate_3d_outcode ( snow_quad[1].i, snow_quad[1].j );
				snow_quad[1].next_vertex = &snow_quad[2];

				snow_quad[2].q = transformed_3d_points[count].q;
				snow_quad[2].i = transformed_3d_points[count].i + ( width / 2 );
				snow_quad[2].j = transformed_3d_points[count].j + ( height / 2 );
				snow_quad[2].u = 1;
				snow_quad[2].v = 1;
				snow_quad[2].outcode = generate_3d_outcode ( snow_quad[2].i, snow_quad[2].j );
				snow_quad[2].next_vertex = &snow_quad[3];

				snow_quad[3].q = transformed_3d_points[count].q;
				snow_quad[3].i = transformed_3d_points[count].i - ( width / 2 );
				snow_quad[3].j = transformed_3d_points[count].j + ( height / 2 );
				snow_quad[3].u = 0;
				snow_quad[3].v = 1;
				snow_quad[3].outcode = generate_3d_outcode ( snow_quad[3].i, snow_quad[3].j );
				snow_quad[3].next_vertex = NULL;

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

				poly = snow_quad;

				if ( outcode )
				{

					clip_3d_coord = 0;

					poly = clip_3d_polygon ( poly, outcode );
				}

				if ( poly )
				{

					draw_wbuffered_flat_shaded_textured_polygon ( poly, snow_colour, snow_specular );
				}
			}
		}

		set_d3d_alpha_fog_zbuffer ( FALSE, TRUE, TRUE, TRUE );
	}
}