⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 gl_mesh.pas

📁 雷神之锤2(Quake2)Delphi源码
💻 PAS
📖 第 1 页 / 共 2 页
字号:
			oldmaxs[i]  := oldmins[i] + poldframe.scale[i]*255;

			if ( thismins[i] < oldmins[i] )then 
				mins[i] := thismins[i]
			else
				mins[i] := oldmins[i];

			if ( thismaxs[i] > oldmaxs[i] ) then
				maxs[i] := thismaxs[i]
			else
				maxs[i] := oldmaxs[i];
		end;
	

	(*/*
	** compute a full bounding box
	*/*)
	for  i := 0 to 8 do
	begin

                // TODO   how do convert..... if (i & 1) ???? 
		if ( i & 1 ) then  //// {FAB} check this translations
			tmp[0] := mins[0]
		else
			tmp[0] := maxs[0];

		if ( i & 2 ) then
			tmp[1] := mins[1]
		else
			tmp[1] := maxs[1];

		if ( i & 4 ) then
			tmp[2] := mins[2]
		else
			tmp[2] := maxs[2];
                // end of TODO

		VectorCopy( tmp, bbox[i] );
	end;

	(*/*
	** rotate the bounding box
	*/*)
	VectorCopy( e.angles, angles );
	angles[YAW] := -angles[YAW];
	AngleVectors( angles, @vectors[0], @vectors[1], @vectors[2] );

	for  i := 0 to 8 do
	begin
		// vec3_t tmp;

		VectorCopy( bbox[i], tmp );

		bbox[i][0] := DotProduct( vectors[0], tmp );
		bbox[i][1] := -DotProduct( vectors[1], tmp );
		bbox[i][2] := DotProduct( vectors[2], tmp );

		VectorAdd( e.origin, bbox[i], bbox[i] );
	end;

	
		// int p, f, aggregatemask = ~0;

		for  p := 0 to 8 do
		begin
			// int mask = 0;

			for  f := 0 to 4 do
			begin
				dp := DotProduct( frustum[f].normal, bbox[p] );

				if ( ( dp - frustum[f].dist ) < 0 ) then
				
					mask := mask or (1 shl f) ; //mask |= ( 1 << f ); // {FAB} check this translation
				
			end;

			aggregatemask := aggregatemask and mask; // // {FAB} check this translation
		end;

		if ( aggregatemask <> 0)then 
		begin
			result := true ;// return true;
			exit;	
		end;
   result := false ;
	//return false;
end;

(*/*
=================
R_DrawAliasModel

=================
*/*)
procedure R_DrawAliasModel (e: entity_p);
var
	i:integer;
	paliashdr :dmdl_p;
	an,s,scale,min :Single;
	bbox :array [0..7]of vec3_t;
	skin :image_p;
begin
	if ( e.flags and RF_WEAPONMODEL = 0)  then
	begin
		if ( R_CullAliasModel( bbox, e )= true )then
			exit ;//return;
	end;

	if ( e.flags and RF_WEAPONMODEL <> 0) then
	begin
		if ( r_lefthand.value = 2 )then
			exit ; //return;
	end;

	//paliashdr = (dmdl_t *)currentmodel->extradata;
	paliashdr := @currentmodel.extradata ; //// {FAB} check this translation

	//
	// get lighting information
	//
	// PMM - rewrote, reordered to handle new shells & mixing
	// PMM - 3.20 code .. replaced with original way of doing it to keep mod authors happy
	//
	if ( currententity.flags and ( RF_SHELL_HALF_DAM or RF_SHELL_GREEN or RF_SHELL_RED or RF_SHELL_BLUE or RF_SHELL_DOUBLE )<> 0 )then
	begin
		VectorClear (shadelight);
		if (currententity.flags and RF_SHELL_HALF_DAM <> 0) then
		begin
				shadelight[0] := 0.56;
				shadelight[1] := 0.59;
				shadelight[2] := 0.45;
		end;
		if ( currententity.flags and RF_SHELL_DOUBLE <> 0) then
		begin
			shadelight[0] := 0.9;
			shadelight[1] := 0.7;
		end;
		if ( currententity.flags and RF_SHELL_RED <> 0)then
			shadelight[0] := 1.0;
		if ( currententity.flags and RF_SHELL_GREEN <> 0) then
			shadelight[1] := 1.0;
		if ( currententity.flags and RF_SHELL_BLUE <> 0) then
			shadelight[2] := 1.0;
	end ;
(*/*
		// PMM -special case for godmode
		if ( (currententity->flags & RF_SHELL_RED) &&
			(currententity->flags & RF_SHELL_BLUE) &&
			(currententity->flags & RF_SHELL_GREEN) )
		{
			for (i=0 ; i<3 ; i++)
				shadelight[i] = 1.0;
		}
		else if ( currententity->flags & ( RF_SHELL_RED | RF_SHELL_BLUE | RF_SHELL_DOUBLE ) )
		{
			VectorClear (shadelight);

			if ( currententity->flags & RF_SHELL_RED )
			{
				shadelight[0] = 1.0;
				if (currententity->flags & (RF_SHELL_BLUE|RF_SHELL_DOUBLE) )
					shadelight[2] = 1.0;
			}
			else if ( currententity->flags & RF_SHELL_BLUE )
			{
				if ( currententity->flags & RF_SHELL_DOUBLE )
				{
					shadelight[1] = 1.0;
					shadelight[2] = 1.0;
				}
				else
				{
					shadelight[2] = 1.0;
				}
			}
			else if ( currententity->flags & RF_SHELL_DOUBLE )
			{
				shadelight[0] = 0.9;
				shadelight[1] = 0.7;
			}
		}
		else if ( currententity->flags & ( RF_SHELL_HALF_DAM | RF_SHELL_GREEN ) )
		{
			VectorClear (shadelight);
			// PMM - new colors
			if ( currententity->flags & RF_SHELL_HALF_DAM )
			{
				shadelight[0] = 0.56;
				shadelight[1] = 0.59;
				shadelight[2] = 0.45;
			}
			if ( currententity->flags & RF_SHELL_GREEN )
			{
				shadelight[1] = 1.0;
			}
		}
	}
			//PMM - ok, now flatten these down to range from 0 to 1.0.
	//		max_shell_val = max(shadelight[0], max(shadelight[1], shadelight[2]));
	//		if (max_shell_val > 0)
	//		{
	//			for (i=0; i<3; i++)
	//			{
	//				shadelight[i] = shadelight[i] / max_shell_val;
	//			}
	//		}
	// pmm
*/*)
	else if ( currententity.flags and RF_FULLBRIGHT <> 0 )then
	begin
		for i:=0  to 3 do
		begin
			shadelight[i] := 1.0;
		end;	
	end
	else;
	begin
		R_LightPoint (currententity.origin, shadelight);

		// player lighting hack for communication back to server
		// big hack!
		if ( currententity.flags and RF_WEAPONMODEL <> 0) then
		begin
			// pick the greatest component, which should be the same
			// as the mono value returned by software
			if (shadelight[0] > shadelight[1]) then
			begin
				if (shadelight[0] > shadelight[2])then 
					r_lightlevel.value := 150*shadelight[0]
				else
					r_lightlevel.value := 150*shadelight[2];
			end
			else
			begin
				if (shadelight[1] > shadelight[2]) then
					r_lightlevel.value := 150*shadelight[1]
				else
					r_lightlevel.value := 150*shadelight[2];
			end;

		end;
		
		if ( gl_monolightmap._string[0] <> '0' ) then
		begin
			  s := shadelight[0];

			if ( s < shadelight[1] )then
				s := shadelight[1];
			if ( s < shadelight[2] )then
				s := shadelight[2];

			shadelight[0] := s;
			shadelight[1] := s;
			shadelight[2] := s;
		end;
	end;

	if ( currententity.flags and RF_MINLIGHT <> 0) then
	begin
		for i:=0 to 3 do
		begin 
			if (shadelight[i] > 0.1)then
				break;
				if (i = 3) then
				begin
				shadelight[0] := 0.1;
				shadelight[1] := 0.1;
				shadelight[2] := 0.1;
				end;
		end;		
	end;

	if ( currententity.flags and RF_GLOW <> 0) then
		// bonus items will pulse with time
           begin
		        //float	scale;
                        //float	min;

		scale := 0.1 * sin(r_newrefdef.time*7);
		for i:=0  to 3 do
		 begin
			min := shadelight[i] * 0.8;
			shadelight[i] :=shadelight [i]+ scale;
			if (shadelight[i] < min)then
                        shadelight[i] := min;
		 end;
	   end;

// =================
// PGM	ir goggles color override
	if ( r_newrefdef.rdflags and RDF_IRGOGGLES <> 0)and (currententity.flags and RF_IR_VISIBLE <> 0) then
	 begin
		shadelight[0] := 1.0;
		shadelight[1] := 0.0;
		shadelight[2] := 0.0;
	end;
// PGM	
// =================
        // TODO  by {FAB}
	// shadedots := r_avertexnormal_dots[((int)(currententity.angles[1] * (SHADEDOT_QUANT / 360.0))) and (SHADEDOT_QUANT - 1)];
	// end of TODO
	an := currententity.angles[1]/180 * M_PI;
	shadevector[0] := cos(-an);
	shadevector[1] := sin(-an);
	shadevector[2] := 1;
	VectorNormalize (shadevector);

	//
	// locate the proper data
	//

	c_alias_polys := c_alias_polys + paliashdr.num_tris;

	//
	// draw all the triangles
	//
	if (currententity.flags and RF_DEPTHHACK <> 0)then // hack the depth range to prevent view model from poking into walls
		qglDepthRange (gldepthmin, gldepthmin + 0.3*(gldepthmax-gldepthmin));

	if ( ( currententity.flags and RF_WEAPONMODEL <> 0) and ( r_lefthand.value = 1.0 ) ) then
	 begin
		// extern void MYgluPerspective( GLdouble fovy, GLdouble aspect, GLdouble zNear, GLdouble zFar );

		qglMatrixMode( GL_PROJECTION );
		qglPushMatrix();
		qglLoadIdentity();
		qglScalef( -1, 1, 1 );
	    MYgluPerspective( r_newrefdef.fov_y, trunc(r_newrefdef.width / r_newrefdef.height),  4,  4096);
		qglMatrixMode( GL_MODELVIEW );

		qglCullFace( GL_BACK );
	 end;

    qglPushMatrix ();
	e.angles[PITCH] = - e.angles[PITCH];	// sigh.
	R_RotateForEntity (e);
	e.angles[PITCH] = -e.angles[PITCH];	// sigh.

	// select skin
	if assigned (currententity.skin)
		skin := currententity.skin	// custom player skin
	else;
	 begin
		if (currententity.skinnum >= MAX_MD2SKINS)then
			skin := currentmodel.skins[0]
		else;
		 begin
			skin := currentmodel.skins[currententity.skinnum];
			if (skin = nil) then
                        skin := currentmodel.skins[0];
		end;
	 end;
	if (skin = nil)then
		skin := r_notexture;	// fallback...
	        GL_Bind(skin.texnum);

	// draw it

	qglShadeModel (GL_SMOOTH);

	GL_TexEnv( GL_MODULATE );
	if ( currententity.flags and RF_TRANSLUCENT <> 0 )then

		qglEnable (GL_BLEND);



	if ( (currententity.frame >= paliashdr.num_frames)or(currententity.frame < 0) )then
	 begin
		ri.Con_Printf (PRINT_ALL, 'R_DrawAliasModel %s: no such frame %d\n',
			currentmodel.name, currententity.frame);
		currententity.frame := 0;
		currententity.oldframe := 0;
	 end;

	if ((currententity.oldframe >= paliashdr.num_frames)or(currententity.oldframe < 0))then
	 begin
		ri.Con_Printf (PRINT_ALL, 'R_DrawAliasModel %s: no such oldframe %d\n',
			currentmodel.name, currententity.oldframe);
		currententity.frame := 0;
		currententity.oldframe := 0;
	 end;

	if ( r_lerpmodels.value = 0 )then
		currententity.backlerp := 0;
	        GL_DrawAliasFrameLerp (paliashdr, currententity.backlerp);

	        GL_TexEnv( GL_REPLACE );
	        qglShadeModel (GL_FLAT);

	        qglPopMatrix ();

{$ifdef 0}
	qglDisable( GL_CULL_FACE );
	qglPolygonMode( GL_FRONT_AND_BACK, GL_LINE );
	qglDisable( GL_TEXTURE_2D );
	qglBegin( GL_TRIANGLE_STRIP );
	for  i := 0 to 8 do
	begin
		qglVertex3fv( bbox[i] );
	end;
	qglEnd();
	qglEnable( GL_TEXTURE_2D );
	qglPolygonMode( GL_FRONT_AND_BACK, GL_FILL );
	qglEnable( GL_CULL_FACE );
{$endif}

	if (( currententity.flags and RF_WEAPONMODEL <> 0) and ( r_lefthand.value = 1.0 ))then
	 begin
		qglMatrixMode( GL_PROJECTION );
		qglPopMatrix();
		qglMatrixMode( GL_MODELVIEW );
		qglCullFace( GL_FRONT );
	 end;

	if ( currententity.flags and RF_TRANSLUCENT <> 0 )then

		qglDisable (GL_BLEND);


	if (currententity.flags and RF_DEPTHHACK <> 0) then
		qglDepthRange (gldepthmin, gldepthmax);

{$ifdef 1}
	if (gl_shadows.value <> 0 and (currententity.flags and(RF_TRANSLUCENT or RF_WEAPONMODEL)= 0))then
	 begin
		qglPushMatrix ();
		R_RotateForEntity (e);
		qglDisable (GL_TEXTURE_2D);
		qglEnable (GL_BLEND);
		qglColor4f (0,0,0,0.5);
		GL_DrawAliasShadow (paliashdr, currententity.frame );
		qglEnable (GL_TEXTURE_2D);
		qglDisable (GL_BLEND);
		qglPopMatrix ();
	 end;
{$endif}
	qglColor4f (1,1,1,1);
end;

end.

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -