Esempio n. 1
0
void set_3d_pixel ( float x, float y, float z, rgb_colour colour )
{

	if ( z >= clip_hither )
	{

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

			asm_convert_float_to_int ( i, &inti );

			asm_convert_float_to_int ( j, &intj );

			set_pixel ( inti, intj, colour );
		}
	}
}
Esempio n. 2
0
void draw_3d_smoke_trail ( struct OBJECT_3D_SMOKE_TRAIL *smoke )
{

	vertex
		points[6];

	int
		segment,
		count,
		outcode,
		outcode2;

	segment = smoke->segment;

	set_d3d_fog_face_intensity ( 255 );

	//
	// Copy the 3d coordinates into a local quad
	//

	points[0].x = smoke->trail->points[segment].point1.x * active_3d_environment->screen_i_scale;
	points[0].y = smoke->trail->points[segment].point1.y * active_3d_environment->screen_j_scale;
	points[0].z = smoke->trail->points[segment].point1.z;
	points[0].u = smoke->trail->points[segment].texture_u;

	points[1].x = smoke->trail->points[segment].centre.x * active_3d_environment->screen_i_scale;
	points[1].y = smoke->trail->points[segment].centre.y * active_3d_environment->screen_j_scale;
	points[1].z = smoke->trail->points[segment].centre.z;
	points[1].u = smoke->trail->points[segment].texture_u;

	points[2].x = smoke->trail->points[segment].point2.x * active_3d_environment->screen_i_scale;
	points[2].y = smoke->trail->points[segment].point2.y * active_3d_environment->screen_j_scale;
	points[2].z = smoke->trail->points[segment].point2.z;
	points[2].u = smoke->trail->points[segment].texture_u;

	points[3].x = smoke->trail->points[segment+1].point1.x * active_3d_environment->screen_i_scale;
	points[3].y = smoke->trail->points[segment+1].point1.y * active_3d_environment->screen_j_scale;
	points[3].z = smoke->trail->points[segment+1].point1.z;
	points[3].u = smoke->trail->points[segment+1].texture_u;

	points[4].x = smoke->trail->points[segment+1].centre.x * active_3d_environment->screen_i_scale;
	points[4].y = smoke->trail->points[segment+1].centre.y * active_3d_environment->screen_j_scale;
	points[4].z = smoke->trail->points[segment+1].centre.z;
	points[4].u = smoke->trail->points[segment+1].texture_u;

	points[5].x = smoke->trail->points[segment+1].point2.x * active_3d_environment->screen_i_scale;
	points[5].y = smoke->trail->points[segment+1].point2.y * active_3d_environment->screen_j_scale;
	points[5].z = smoke->trail->points[segment+1].point2.z;
	points[5].u = smoke->trail->points[segment+1].texture_u;

	//
	// Transform the points and outcode the quad at the same time
	//

	outcode = 0;
	outcode2 = CLIP_HITHER | CLIP_LEFT | CLIP_RIGHT | CLIP_TOP | CLIP_BOTTOM;

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

		if ( *( ( int * ) &points[count].z ) >= *( ( int * ) &clip_hither ) )
		{

			float
				oxmax,
				oxmin,
				oymax,
				oymin,
				q,
				i,
				j;
		
			int
				ixmax,
				ixmin,
				iymax,
				iymin;

			q = 1.0 / points[count].z;

			i = ( points[count].x * q );
			j = ( points[count].y * q );

			j = active_3d_environment->y_origin - j;
			i = active_3d_environment->x_origin + i;

			points[count].j = j;
			points[count].i = i;
			points[count].q = q;

			oxmax = active_viewport.x_max - i;
			oxmin = i - active_viewport.x_min;
			oymax = active_viewport.y_max - j;
			oymin = j - active_viewport.y_min;
		
			ixmax = *( ( int * ) &oxmax );
			ixmin = *( ( int * ) &oxmin );
			iymax = *( ( int * ) &oymax );
			iymin = *( ( int * ) &oymin );
		
			points[count].outcode = generate_lookup_outcode ( ixmin, iymin, ixmax, iymax );
		}
		else
		{

			points[count].outcode = CLIP_HITHER;
		}

		outcode |= points[count].outcode;
		outcode2 &= points[count].outcode;
	}

	if ( outcode2 == 0 )
	{

		points[0].u = smoke->trail->points[segment].texture_u;
		points[0].v = 0;
		points[0].colour = smoke->trail->points[segment].colour.colour;

		points[3].u = smoke->trail->points[segment+1].texture_u;
		points[3].v = 0;
		points[3].colour = smoke->trail->points[segment+1].colour.colour;

		points[4].u = smoke->trail->points[segment+1].texture_u;
		points[4].v = 0.5;
		points[4].colour = smoke->trail->points[segment+1].colour.colour;

		points[0].next_vertex = &points[3];
		points[3].next_vertex = &points[4];
		points[4].next_vertex = NULL;

		render_smoke_trail_polygon ( &points[0], smoke->trail->texture, smoke->trail->additive );

		points[0].u = smoke->trail->points[segment].texture_u;
		points[0].v = 0;
		points[0].colour = smoke->trail->points[segment].colour.colour;

		points[1].u = smoke->trail->points[segment].texture_u;
		points[1].v = 0.5;
		points[1].colour = smoke->trail->points[segment].colour.colour;

		points[4].u = smoke->trail->points[segment+1].texture_u;
		points[4].v = 0.5;
		points[4].colour = smoke->trail->points[segment+1].colour.colour;

		points[0].next_vertex = &points[4];
		points[4].next_vertex = &points[1];
		points[1].next_vertex = NULL;

		render_smoke_trail_polygon ( &points[0], smoke->trail->texture, smoke->trail->additive );

		points[1].u = smoke->trail->points[segment].texture_u;
		points[1].v = 0.5;
		points[1].colour = smoke->trail->points[segment].colour.colour;

		points[2].u = smoke->trail->points[segment].texture_u;
		points[2].v = 1;
		points[2].colour = smoke->trail->points[segment].colour.colour;

		points[4].u = smoke->trail->points[segment+1].texture_u;
		points[4].v = 0.5;
		points[4].colour = smoke->trail->points[segment+1].colour.colour;

		points[1].next_vertex = &points[4];
		points[4].next_vertex = &points[2];
		points[2].next_vertex = NULL;

		render_smoke_trail_polygon ( &points[1], smoke->trail->texture, smoke->trail->additive );

		points[2].u = smoke->trail->points[segment].texture_u;
		points[2].v = 1;
		points[2].colour = smoke->trail->points[segment].colour.colour;

		points[4].u = smoke->trail->points[segment+1].texture_u;
		points[4].v = 0.5;
		points[4].colour = smoke->trail->points[segment+1].colour.colour;

		points[5].u = smoke->trail->points[segment+1].texture_u;
		points[5].v = 1;
		points[5].colour = smoke->trail->points[segment+1].colour.colour;

		points[2].next_vertex = &points[4];
		points[4].next_vertex = &points[5];
		points[5].next_vertex = NULL;

		render_smoke_trail_polygon ( &points[2], smoke->trail->texture, smoke->trail->additive );
	}
}
Esempio n. 3
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 );
	}
}
Esempio n. 4
0
void transform_cloud_points ( int number_of_points, cloud_3d_point *source_points, vertex *result_points, vec3d *position )
{

	float
		oxmax,
		oxmin,
		oymax,
		oymin;

	int
		count,
		ixmax,
		ixmin,
		iymax,
		iymin;

	//
	// Now transform all the points.
	//

	for ( count = number_of_points; count > 0; count-- )
	{

		float
			x,
			y,
			z;

		x = source_points->x * visual_3d_vp->attitude[0][0] +
				source_points->y * visual_3d_vp->attitude[0][1] +
				source_points->z * visual_3d_vp->attitude[0][2] + position->x;

		y = source_points->x * visual_3d_vp->attitude[1][0] +
				source_points->y * visual_3d_vp->attitude[1][1] +
				source_points->z * visual_3d_vp->attitude[1][2] + position->y;

		z = source_points->x * visual_3d_vp->attitude[2][0] +
				source_points->y * visual_3d_vp->attitude[2][1] +
				source_points->z * visual_3d_vp->attitude[2][2] + position->z;

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

		result_points->colour = source_points->colour;

		if ( *( ( int * ) &z ) >= *( ( int * ) &clip_hither ) )
		{

			float
				q,
				i,
				j;

			q = 1.0 / z;

			result_points->x = x;
			result_points->y = y;
			result_points->z = z;

			i = ( x * q );
			j = ( y * q );

			result_points->j = ( active_3d_environment->y_origin - j );
			result_points->i = ( active_3d_environment->x_origin + i );
			result_points->q = q;

			oxmax = active_viewport.x_max - result_points->i;
			oxmin = result_points->i - active_viewport.x_min;
			oymax = active_viewport.y_max - result_points->j;
			oymin = result_points->j - active_viewport.y_min;

			ixmax = *( ( int * ) &oxmax );
			ixmin = *( ( int * ) &oxmin );
			iymax = *( ( int * ) &oymax );
			iymin = *( ( int * ) &oymin );

			result_points->outcode = generate_lookup_outcode ( ixmin, iymin, ixmax, iymax );
		}
		else
		{

			result_points->outcode = CLIP_HITHER;
			result_points->z = z;
			result_points->x = x;
			result_points->y = y;
		}

		result_points++;

		source_points++;
	}
}
Esempio n. 5
0
vertex * construct_sun_polygon ( matrix3x3 sun_matrix, vertex *sun_quad, float sun_width, float sun_height, float sun_depth )
{

	vertex
		*sun_polygon,
		*vert;

	int
		outcode,
		outcode2,
		count;

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

	sun_quad[0].x = -sun_width/2;
	sun_quad[0].y = sun_height/2;
	sun_quad[0].z = sun_depth;
	sun_quad[0].u = 0;
	sun_quad[0].v = 0;

	sun_quad[1].x = sun_width/2;
	sun_quad[1].y = sun_height/2;
	sun_quad[1].z = sun_depth;
	sun_quad[1].u = 1;
	sun_quad[1].v = 0;

	sun_quad[2].x = sun_width/2;
	sun_quad[2].y = -sun_height/2;
	sun_quad[2].z = sun_depth;
	sun_quad[2].u = 1;
	sun_quad[2].v = 1;

	sun_quad[3].x = -sun_width/2;
	sun_quad[3].y = -sun_height/2;
	sun_quad[3].z = sun_depth;
	sun_quad[3].u = 0;
	sun_quad[3].v = 1;

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

		float
			x,
			y,
			z;


		x = sun_quad[count].x * sun_matrix[0][0] + sun_quad[count].y * sun_matrix[1][0] + sun_quad[count].z * sun_matrix[2][0];
		y = sun_quad[count].x * sun_matrix[0][1] + sun_quad[count].y * sun_matrix[1][1] + sun_quad[count].z * sun_matrix[2][1];
		z = sun_quad[count].x * sun_matrix[0][2] + sun_quad[count].y * sun_matrix[1][2] + sun_quad[count].z * sun_matrix[2][2];

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

	//
	// Clip the sun to the horizon
	//

	clip_3d_coord = 0;

	sun_polygon = horizon_clip_3d_polygon ( sun_quad );

	if ( sun_polygon )
	{

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

		vert = sun_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 ( NULL );
		}


		if ( outcode & CLIP_HITHER )
		{

			sun_polygon = hither_clip_3d_polygon ( sun_polygon, &outcode );

			if ( !sun_polygon )
			{

				return ( NULL );
			}
		}

		if ( outcode )
		{

			apply_perspective_to_polygon_texture ( sun_polygon );

			sun_polygon = clip_3d_polygon ( sun_polygon, outcode );

			if ( !sun_polygon )
			{

				return ( NULL );
			}

			remove_perspective_from_polygon_texture ( sun_polygon );
		}

		if ( sun_polygon )
		{

			vertex
				*p;

			p = sun_polygon;

			while ( p )
			{

				if ( p->q < clip_yonder_reciprocal )
				{

					p->q = clip_yonder_reciprocal;
				}

				p = p->next_vertex;
			}
		}

		return ( sun_polygon );
	}
	else
	{

		return ( NULL );
	}
}
Esempio n. 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 );
		}
	}
}
Esempio n. 7
0
int transform_3d_polyline_points ( int number_of_vertices, vec3d *vertices, polyline_point *result_points )
{

	int
		count,
		visible;

	float
		oxmax,
		oxmin,
		oymax,
		oymin;

	int
		ixmax,
		ixmin,
		iymax,
		iymin;

	visible = FALSE;

	for ( count = number_of_vertices; count > 0; count-- )
	{

		float
			pointx,
			pointy,
			pointz,
			x,
			y,
			z;

		result_points->world_point = *vertices;

		pointx = vertices->x - visual_3d_vp->x;
		pointy = vertices->y - visual_3d_vp->y;
		pointz = vertices->z - visual_3d_vp->z;

		x = pointx * visual_3d_vp->xv.x;
		y = pointx * visual_3d_vp->yv.x;
		z = pointx * visual_3d_vp->zv.x;

		x += pointy * visual_3d_vp->xv.y;
		y += pointy * visual_3d_vp->yv.y;
		z += pointy * visual_3d_vp->zv.y;

		x += pointz * visual_3d_vp->xv.z;
		y += pointz * visual_3d_vp->yv.z;
		z += pointz * visual_3d_vp->zv.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;

			visible = TRUE;

			q = 1.0 / z;

			result_points->transformed_point.x = x;
			result_points->transformed_point.y = y;
			result_points->transformed_point.z = z;

			i = active_3d_environment->x_origin + ( x * q );

			j = active_3d_environment->y_origin - ( y * q );

			oxmax = active_viewport.x_max - i;
			oxmin = i - active_viewport.x_min;
			oymax = active_viewport.y_max - j;
			oymin = j - active_viewport.y_min;
		
			ixmax = *( ( int * ) &oxmax );
			ixmin = *( ( int * ) &oxmin );
			iymax = *( ( int * ) &oymax );
			iymin = *( ( int * ) &oymin );
		
			result_points->transformed_point.outcode = generate_lookup_outcode ( ixmin, iymin, ixmax, iymax );

			result_points->transformed_point.j = j;
			result_points->transformed_point.i = i;
			result_points->transformed_point.q = q;
		}
		else
		{

			result_points->transformed_point.outcode = CLIP_HITHER;

			result_points->transformed_point.z = z;
			result_points->transformed_point.x = x;
			result_points->transformed_point.y = y;
		}

		result_points++;

		vertices++;
	}

	return ( visible );
}
Esempio n. 8
0
void transform_3d_snow ( void )
{

	int
		count;

	vertex
		*result_points;

	float
		oxmax,
		oxmin,
		oymax,
		oymin;

	int
		ixmax,
		ixmin,
		iymax,
		iymin;

	vec3d
		rel;


	//
	// Go through rotating/translating the rain positions, current and predicted, and draw lines accordingly.
	//

	//
	// We only need the fpu to be in single precision mode
	//

//	set_fpu_precision_mode_single ();

	result_points = transformed_3d_points;

	scaled_rotation[0][0] = rotation_3d[0][0] * active_3d_environment->screen_i_scale;
	scaled_rotation[0][1] = rotation_3d[0][1] * active_3d_environment->screen_j_scale;
	scaled_rotation[0][2] = rotation_3d[0][2];

	scaled_rotation[1][0] = rotation_3d[1][0] * active_3d_environment->screen_i_scale;
	scaled_rotation[1][1] = rotation_3d[1][1] * active_3d_environment->screen_j_scale;
	scaled_rotation[1][2] = rotation_3d[1][2];

	scaled_rotation[2][0] = rotation_3d[2][0] * active_3d_environment->screen_i_scale;
	scaled_rotation[2][1] = rotation_3d[2][1] * active_3d_environment->screen_j_scale;
	scaled_rotation[2][2] = rotation_3d[2][2];

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

		float
			x,
			y,
			z;

		vec3d
			*points;

		if ( rain_3d_drops[count].type == RAINDROP_SNOW )
		{

			points = &rain_3d_drops[count].current_position;

			rel.x = points->x - visual_3d_vp->x;
			rel.y = points->y - visual_3d_vp->y;
			rel.z = points->z - visual_3d_vp->z;

			z = rel.x * scaled_rotation[0][2] + rel.y * scaled_rotation[1][2] + rel.z * scaled_rotation[2][2];
			x = rel.x * scaled_rotation[0][0] + rel.y * scaled_rotation[1][0] + rel.z * scaled_rotation[2][0];
			y = rel.x * scaled_rotation[0][1] + rel.y * scaled_rotation[1][1] + rel.z * scaled_rotation[2][1];

			if ( *( ( int * ) &z ) >= *( ( int * ) &clip_hither ) )
			{

				float
					q,
					i,
					j;

				result_points->x = x;
				result_points->y = y;
				result_points->z = z;

				q = 1.0 / z;
				i = ( x * q );
				j = ( y * q );

				result_points->j = active_3d_environment->y_origin - j;
				result_points->i = active_3d_environment->x_origin + i;

				result_points->q = q;

				oxmax = active_viewport.x_max - result_points->i;
				oxmin = result_points->i - active_viewport.x_min;
				oymax = active_viewport.y_max - result_points->j;
				oymin = result_points->j - active_viewport.y_min;

				ixmax = *( ( int * ) &oxmax );
				ixmin = *( ( int * ) &oxmin );
				iymax = *( ( int * ) &oymax );
				iymin = *( ( int * ) &oymin );

				result_points->outcode = generate_lookup_outcode ( ixmin, iymin, ixmax, iymax );

				result_points++;
			}
			else
			{

				//
				// Tag this snowdrop as invalid now
				//

				rain_3d_drops[count].type = RAINDROP_INVALID;

				rain_3d_snowdrops_valid--;
			}
		}
	}

//	set_fpu_precision_mode_double ();
}