Beispiel #1
0
/*
====================
SV_ClipToLinks

Mins and maxs enclose the entire area swept by the move
====================
*/
void SV_ClipToLinks ( areanode_t *node, moveclip_t *clip )
{
	int			i, numtouch;
	edict_t		*touchlist[MAX_EDICTS], *touch;
	trace_t		trace;

	numtouch = SV_AreaEdicts (clip->boxmins, clip->boxmaxs, touchlist, MAX_EDICTS, AREA_SOLID);

// touch linked edicts
	for (i = 0; i < numtouch; i++)
	{
		touch = touchlist[i];
		if (touch == clip->passedict)
			continue;
		if (touch->v.solid == SOLID_TRIGGER)
			Host_Error ("Trigger in clipping list");

		if (clip->type == MOVE_NOMONSTERS && touch->v.solid != SOLID_BSP)
			continue;

		if (clip->passedict && clip->passedict->v.size[0] && !touch->v.size[0])
			continue;	// points never interact

	// might intersect, so do an exact clip
		if (clip->trace.allsolid)
			return;
		if (clip->passedict)
		{
		 	if (PROG_TO_EDICT(touch->v.owner) == clip->passedict)
				continue;	// don't clip against own missiles
			if (PROG_TO_EDICT(clip->passedict->v.owner) == touch)
				continue;	// don't clip against owner
		}

		if ((int)touch->v.flags & FL_MONSTER)
			trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins2, clip->maxs2, clip->end);
		else
			trace = SV_ClipMoveToEntity (touch, clip->start, clip->mins, clip->maxs, clip->end);
		if (trace.allsolid || trace.startsolid ||
		trace.fraction < clip->trace.fraction)
		{
			trace.e.ent = touch;
		 	if (clip->trace.startsolid)
			{
				clip->trace = trace;
				clip->trace.startsolid = true;
			}
			else
				clip->trace = trace;
		}
		else if (trace.startsolid)
			clip->trace.startsolid = true;
	}
}
/* DESCRIPTION: SV_Move
// LOCATION: world.c
// PATH: A few places in the game logic
//
// Seems to be responsible for handling movements in the virtual world.
// Returns a trace_t struct, which is actually performed with some compiler
// magic--arg0 is used to store the pointer, and it's copied upon the
// function's return.
*/
trace_t SV_Move(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict, int hullnumthing) {

   moveclip_t clip;
   vec3_t var_94_end; //identical to declaring vec_t var_94[3]
   float var_98;

   memset(&clip, 0, sizeof(moveclip_t));
   SV_ClipMoveToEntity(&(clip.trace), global_sv.edicts, start, mins, maxs, end);

   if(clip.trace.fraction != 0) {

      var_94_end[0] = clip.trace.endpos[0];
      var_94_end[1] = clip.trace.endpos[1];
      var_94_end[2] = clip.trace.endpos[2];

      clip.end = var_94_end;
      var_98 = clip.trace.fraction;
      clip.trace.fraction = 1.0;
      clip.start = start;
      clip.mins = mins;
      clip.maxs = maxs;
      clip.type1 = type & 0xff; //Dunno why...
      clip.type2 = type << 8;
      clip.passedict = passedict;
      clip.hullnum = hullnumthing;

      if(type == 2) {

         clip.mins2[0] = -15.0;
         clip.mins2[1] = -15.0;
         clip.mins2[2] = -15.0;
         clip.maxs2[0] =  15.0;
         clip.maxs2[1] =  15.0;
         clip.maxs2[2] =  15.0;
      }
      else {

         clip.mins2[0] = mins[0];
         clip.mins2[1] = mins[1];
         clip.mins2[2] = mins[2];
         clip.maxs2[0] = maxs[0];
         clip.maxs2[1] = maxs[1];
         clip.maxs2[2] = maxs[2];
      }

      SV_MoveBounds(start, clip.mins2, clip.maxs2, var_94_end, clip.boxmins, clip.boxmaxs);
      SV_ClipToLinks(global_sv_areanodes, &clip);

      clip.trace.fraction *= var_98;

      gGlobalVariables.trace_ent = clip.trace.pHit;
   }
   return(clip.trace);
}/* DESCRIPTION: SV_MoveNoEnts
/* DESCRIPTION: SV_Move
// LOCATION: world.c
// PATH: A few places in the game logic
//
// Seems to be responsible for handling movements in the virtual world.
// Returns a trace_t struct, which is actually performed with some compiler
// magic--arg0 is used to store the pointer, and it's copied upon the
// function's return.
*/
trace_t SV_Move(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict, int hullnumthing) {

   moveclip_t clip;
   vec3_t var_94_end; //identical to declaring vec_t var_94[3]
   float var_98;

   memset(&clip, 0, sizeof(moveclip_t));
   SV_ClipMoveToEntity(&(clip.trace), global_sv.edicts, start, mins, maxs, end);

   if(clip.trace.fraction != 0) {

      var_94_end[0] = clip.trace.endpos[0];
      var_94_end[1] = clip.trace.endpos[1];
      var_94_end[2] = clip.trace.endpos[2];

      clip.end = var_94_end;
      var_98 = clip.trace.fraction;
      clip.trace.fraction = 1.0;
      clip.start = start;
      clip.mins = mins;
      clip.maxs = maxs;
      clip.type1 = type & 0xff; //Dunno why...
      clip.type2 = type << 8;
      clip.passedict = passedict;
      clip.hullnum = hullnumthing;

      if(type == 2) {

         clip.mins2[0] = -15.0;
         clip.mins2[1] = -15.0;
         clip.mins2[2] = -15.0;
         clip.maxs2[0] =  15.0;
         clip.maxs2[1] =  15.0;
         clip.maxs2[2] =  15.0;
      }
      else {

         clip.mins2[0] = mins[0];
         clip.mins2[1] = mins[1];
         clip.mins2[2] = mins[2];
         clip.maxs2[0] = maxs[0];
         clip.maxs2[1] = maxs[1];
         clip.maxs2[2] = maxs[2];
      }

      SV_MoveBounds(start, clip.mins2, clip.maxs2, var_94_end, clip.boxmins, clip.boxmaxs);
      SV_ClipToLinks(global_sv_areanodes, &clip);

      clip.trace.fraction *= var_98;

      gGlobalVariables.trace_ent = clip.trace.pHit;
   }
   return(clip.trace);
}/* DESCRIPTION: SV_MoveNoEnts
// LOCATION:
// PATH: PF_walkmove_I->SV_movetest
//
// Same as above, but does not check for collision with entities.
*/
trace_t SV_MoveNoEnts(vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict) {

   moveclip_t clip;
   vec3_t tempend; //identical to declaring vec_t var_94[3]
   float tempfraction;


   memset(&clip, 0, sizeof(moveclip_t));
   SV_ClipMoveToEntity(&(clip.trace), global_sv.edicts, start, mins, maxs, end);

   if(clip.trace.fraction != 0) {

      tempend[0] = clip.trace.endpos[0];
      tempend[1] = clip.trace.endpos[1];
      tempend[2] = clip.trace.endpos[2];

      clip.end = tempend;
      tempfraction = clip.trace.fraction;
      clip.trace.fraction = 1.0;
      clip.start = start;
      clip.mins = mins;
      clip.maxs = maxs;
      clip.type1 = type & 0xff;
      clip.type2 = type << 8;
      clip.passedict = passedict;
      clip.hullnum = 0;

      clip.mins2[0] = mins[0];
      clip.mins2[1] = mins[1];
      clip.mins2[2] = mins[2];
      clip.maxs2[0] = maxs[0];
      clip.maxs2[1] = maxs[1];
      clip.maxs2[2] = maxs[2];

      SV_MoveBounds(start, clip.mins2, clip.maxs2, tempend, clip.boxmins, clip.boxmaxs);
      SV_ClipToWorldBrush(global_sv_areanodes, &clip);

      clip.trace.fraction *= tempfraction;
      gGlobalVariables.trace_ent = clip.trace.pHit;
   }
   return(clip.trace);
}
Beispiel #4
0
/*
==================
SV_Trace
==================
*/
trace_t SV_Trace (vec3_t start, vec3_t mins, vec3_t maxs, vec3_t end, int type, edict_t *passedict)
{
	moveclip_t	clip;
	int			i;

	memset ( &clip, 0, sizeof ( moveclip_t ) );

// clip to world
	clip.trace = SV_ClipMoveToEntity ( sv.edicts, start, mins, maxs, end );

	clip.start = start;
	clip.end = end;
	clip.mins = mins;
	clip.maxs = maxs;
	clip.type = type;
	clip.passedict = passedict;

	if (type == MOVE_MISSILE)
	{
		for (i=0 ; i<3 ; i++)
		{
			clip.mins2[i] = -15;
			clip.maxs2[i] = 15;
		}
	}
	else
	{
		VectorCopy (mins, clip.mins2);
		VectorCopy (maxs, clip.maxs2);
	}
	
// create the bounding box of the entire move
	SV_MoveBounds ( start, clip.mins2, clip.maxs2, end, clip.boxmins, clip.boxmaxs );

// clip to entities
	SV_ClipToLinks ( sv_areanodes, &clip );

	return clip.trace;
}
Beispiel #5
0
void CL_DLLEXPORT CAM_Think( void )
{
	RecClCamThink();

#ifdef HL_CAMERA
	vec3_t origin;
	vec3_t ext, pnt, camForward, camRight, camUp;
	moveclip_t	clip;
	float dist;
	vec3_t camAngles;
	float flSensitivity;
#ifdef LATER
	int i;
#endif
	vec3_t viewangles;

	switch( (int) cam_command->value )
	{
		case CAM_COMMAND_TOTHIRDPERSON:
			CAM_ToThirdPerson();
			break;

		case CAM_COMMAND_TOFIRSTPERSON:
			CAM_ToFirstPerson();
			break;

		case CAM_COMMAND_NONE:
		default:
			break;
	}

	if( !cam_thirdperson )
		return;
	
#ifdef LATER
	if ( cam_contain->value )
	{
		gEngfuncs.GetClientOrigin( origin );
		ext[0] = ext[1] = ext[2] = 0.0;
	}
#endif

	camAngles[ PITCH ] = cam_idealpitch->value;
	camAngles[ YAW ] = cam_idealyaw->value;
	dist = cam_idealdist->value;
	//
	//movement of the camera with the mouse
	//
	if (cam_mousemove)
	{
	    //get windows cursor position
		GetCursorPos (&cam_mouse);
		//check for X delta values and adjust accordingly
		//eventually adjust YAW based on amount of movement
	  //don't do any movement of the cam using YAW/PITCH if we are zooming in/out the camera	
	  if (!cam_distancemove)
	  {
		
		//keep the camera within certain limits around the player (ie avoid certain bad viewing angles)  
		if (cam_mouse.x>gEngfuncs.GetWindowCenterX())
		{
			//if ((camAngles[YAW]>=225.0)||(camAngles[YAW]<135.0))
			if (camAngles[YAW]<c_maxyaw->value)
			{
				camAngles[ YAW ] += (CAM_ANGLE_MOVE)*((cam_mouse.x-gEngfuncs.GetWindowCenterX())/2);
			}
			if (camAngles[YAW]>c_maxyaw->value)
			{
				
				camAngles[YAW]=c_maxyaw->value;
			}
		}
		else if (cam_mouse.x<gEngfuncs.GetWindowCenterX())
		{
			//if ((camAngles[YAW]<=135.0)||(camAngles[YAW]>225.0))
			if (camAngles[YAW]>c_minyaw->value)
			{
			   camAngles[ YAW ] -= (CAM_ANGLE_MOVE)* ((gEngfuncs.GetWindowCenterX()-cam_mouse.x)/2);
			   	
			}
			if (camAngles[YAW]<c_minyaw->value)
			{
				camAngles[YAW]=c_minyaw->value;
				
			}
		}

		//check for y delta values and adjust accordingly
		//eventually adjust PITCH based on amount of movement
		//also make sure camera is within bounds
		if (cam_mouse.y>gEngfuncs.GetWindowCenterY())
		{
			if(camAngles[PITCH]<c_maxpitch->value)
			{
			    camAngles[PITCH] +=(CAM_ANGLE_MOVE)* ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2);
			}
			if (camAngles[PITCH]>c_maxpitch->value)
			{
				camAngles[PITCH]=c_maxpitch->value;
			}
		}
		else if (cam_mouse.y<gEngfuncs.GetWindowCenterY())
		{
			if (camAngles[PITCH]>c_minpitch->value)
			{
			   camAngles[PITCH] -= (CAM_ANGLE_MOVE)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2);
			}
			if (camAngles[PITCH]<c_minpitch->value)
			{
				camAngles[PITCH]=c_minpitch->value;
			}
		}

		//set old mouse coordinates to current mouse coordinates
		//since we are done with the mouse

		if ( ( flSensitivity = gHUD.GetSensitivity() ) != 0 )
		{
			cam_old_mouse_x=cam_mouse.x*flSensitivity;
			cam_old_mouse_y=cam_mouse.y*flSensitivity;
		}
		else
		{
			cam_old_mouse_x=cam_mouse.x;
			cam_old_mouse_y=cam_mouse.y;
		}
		SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
	  }
	}

	//Nathan code here
	if( CL_KeyState( &cam_pitchup ) )
		camAngles[ PITCH ] += CAM_ANGLE_DELTA;
	else if( CL_KeyState( &cam_pitchdown ) )
		camAngles[ PITCH ] -= CAM_ANGLE_DELTA;

	if( CL_KeyState( &cam_yawleft ) )
		camAngles[ YAW ] -= CAM_ANGLE_DELTA;
	else if( CL_KeyState( &cam_yawright ) )
		camAngles[ YAW ] += CAM_ANGLE_DELTA;

	if( CL_KeyState( &cam_in ) )
	{
		dist -= CAM_DIST_DELTA;
		if( dist < CAM_MIN_DIST )
		{
			// If we go back into first person, reset the angle
			camAngles[ PITCH ] = 0;
			camAngles[ YAW ] = 0;
			dist = CAM_MIN_DIST;
		}

	}
	else if( CL_KeyState( &cam_out ) )
		dist += CAM_DIST_DELTA;

	if (cam_distancemove)
	{
		if (cam_mouse.y>gEngfuncs.GetWindowCenterY())
		{
			if(dist<c_maxdistance->value)
			{
			    dist +=CAM_DIST_DELTA * ((cam_mouse.y-gEngfuncs.GetWindowCenterY())/2);
			}
			if (dist>c_maxdistance->value)
			{
				dist=c_maxdistance->value;
			}
		}
		else if (cam_mouse.y<gEngfuncs.GetWindowCenterY())
		{
			if (dist>c_mindistance->value)
			{
			   dist -= (CAM_DIST_DELTA)*((gEngfuncs.GetWindowCenterY()-cam_mouse.y)/2);
			}
			if (dist<c_mindistance->value)
			{
				dist=c_mindistance->value;
			}
		}
		//set old mouse coordinates to current mouse coordinates
		//since we are done with the mouse
		cam_old_mouse_x=cam_mouse.x*gHUD.GetSensitivity();
		cam_old_mouse_y=cam_mouse.y*gHUD.GetSensitivity();
		SetCursorPos (gEngfuncs.GetWindowCenterX(), gEngfuncs.GetWindowCenterY());
	}
#ifdef LATER
	if( cam_contain->value )
	{
		// check new ideal
		VectorCopy( origin, pnt );
		AngleVectors( camAngles, camForward, camRight, camUp );
		for (i=0 ; i<3 ; i++)
			pnt[i] += -dist*camForward[i];

		// check line from r_refdef.vieworg to pnt
		memset ( &clip, 0, sizeof ( moveclip_t ) );
		clip.trace = SV_ClipMoveToEntity( sv.edicts, r_refdef.vieworg, ext, ext, pnt );
		if( clip.trace.fraction == 1.0 )
		{
			// update ideal
			cam_idealpitch->value = camAngles[ PITCH ];
			cam_idealyaw->value = camAngles[ YAW ];
			cam_idealdist->value = dist;
		}
	}
	else
#endif
	{
		// update ideal
		cam_idealpitch->value = camAngles[ PITCH ];
		cam_idealyaw->value = camAngles[ YAW ];
		cam_idealdist->value = dist;
	}

	// Move towards ideal
	VectorCopy( cam_ofs, camAngles );

	gEngfuncs.GetViewAngles( (float *)viewangles );

	if( cam_snapto->value )
	{
		camAngles[ YAW ] = cam_idealyaw->value + viewangles[ YAW ];
		camAngles[ PITCH ] = cam_idealpitch->value + viewangles[ PITCH ];
		camAngles[ 2 ] = cam_idealdist->value;
	}
	else
	{
		if( camAngles[ YAW ] - viewangles[ YAW ] != cam_idealyaw->value )
			camAngles[ YAW ] = MoveToward( camAngles[ YAW ], cam_idealyaw->value + viewangles[ YAW ], CAM_ANGLE_SPEED );

		if( camAngles[ PITCH ] - viewangles[ PITCH ] != cam_idealpitch->value )
			camAngles[ PITCH ] = MoveToward( camAngles[ PITCH ], cam_idealpitch->value + viewangles[ PITCH ], CAM_ANGLE_SPEED );

		if( abs( camAngles[ 2 ] - cam_idealdist->value ) < 2.0 )
			camAngles[ 2 ] = cam_idealdist->value;
		else
			camAngles[ 2 ] += ( cam_idealdist->value - camAngles[ 2 ] ) / 4.0;
	}
#ifdef LATER
	if( cam_contain->value )
	{
		// Test new position
		dist = camAngles[ ROLL ];
		camAngles[ ROLL ] = 0;

		VectorCopy( origin, pnt );
		AngleVectors( camAngles, camForward, camRight, camUp );
		for (i=0 ; i<3 ; i++)
			pnt[i] += -dist*camForward[i];

		// check line from r_refdef.vieworg to pnt
		memset ( &clip, 0, sizeof ( moveclip_t ) );
		ext[0] = ext[1] = ext[2] = 0.0;
		clip.trace = SV_ClipMoveToEntity( sv.edicts, r_refdef.vieworg, ext, ext, pnt );
		if( clip.trace.fraction != 1.0 )
			return;
	}
#endif
	cam_ofs[ 0 ] = camAngles[ 0 ];
	cam_ofs[ 1 ] = camAngles[ 1 ];
	cam_ofs[ 2 ] = dist;

// HL_CAMERA
#endif
}