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

📄 camera.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 2 页
字号:
   if ( !ent )
      return;

	pos.x = ent->worldorigin.x;
	pos.y = ent->worldorigin.y;
	pos.z = ent->absmax.z;
	delta = pos - worldorigin;
   delta.normalize();
   currentstate.watch.dir = delta;

	len = currentstate.watch.dir.length();
	if ( len > 0.05 )
		{
		angles = currentstate.watch.dir.toAngles();
		angles[ PITCH ] = -angles[ PITCH ];
      setAngles( angles );
		}
	}

void Camera::TurnTo
	(
	Event *ev
	)

	{
   Vector ang;

	ang = ev->GetVector( 1 );
   ang.AngleVectors( &currentstate.watch.dir, NULL, NULL );
   setAngles( ang );
	}

void Camera::MoveToEntity
	(
	Event *ev
	)

	{
   Entity * ent;

	ent = ev->GetEntity( 1 );
   if ( ent )
      currentstate.move.pos = ent->worldorigin;
   setOrigin( currentstate.move.pos );
	}

void Camera::MoveToPos
	(
	Event *ev
	)

	{
   currentstate.move.pos = ev->GetVector( 1 );
   setOrigin( currentstate.move.pos );
	}

void Camera::Stop
	(
	void
	)

	{
   if ( followTime )
      {
      currentstate.move = newstate.move;
      InitializeMoveState( newstate.move );
      }
   if ( watchTime )
      {
      currentstate.watch = newstate.watch;
      InitializeWatchState( newstate.watch );
      }
	CancelEventsOfType( moveevent );
//	moveevent = NullEvent;
	watchTime = 0;
   followTime = 0;
	}

void Camera::CreateOribit
	(
	Vector pos,
	float radius
	)

	{
	newstate.move.cameraPath.Clear();
	newstate.move.cameraPath.SetType( SPLINE_LOOP );

	newstate.move.cameraPath.AppendControlPoint( pos + Vector( radius, 0, 0 ) );
	newstate.move.cameraPath.AppendControlPoint( pos + Vector( 0, radius, 0 ) );
	newstate.move.cameraPath.AppendControlPoint( pos + Vector( -radius, 0, 0 ) );
	newstate.move.cameraPath.AppendControlPoint( pos + Vector( 0, -radius, 0 ) );
	}

void Camera::CreatePath
	(
	SplinePath *path,
	splinetype_t type
	)

	{
	SplinePath	*node;
	SplinePath	*loop;

	newstate.move.cameraPath.Clear();
	newstate.move.cameraPath.SetType( type );

	node = path;
	while( node != NULL )
		{
  		newstate.move.cameraPath.AppendControlPoint( node->worldorigin, node->angles, node->speed );
		loop = node->GetLoop();
      if ( loop )
         {
         newstate.move.cameraPath.SetLoopPoint( loop->worldorigin );
         }
		node = node->GetNext();

		if ( node == path )
			{
			break;
			}
		}
	}

void Camera::FollowPath
	(
	SplinePath *path,
	qboolean loop,
   Entity * watch
	)

	{
	Stop();
	if ( loop )
		{
		CreatePath( path, SPLINE_LOOP );
		}
	else
		{
		CreatePath( path, SPLINE_CLAMP );
		}

   newstate.move.cameraTime = -2;
   newstate.move.followingpath = true;
   followTime = level.time + jumpTime;
   watchTime = level.time + jumpTime;

   if ( watch )
      {
      newstate.watch.watchEnt = watch;
      }
   else
      {
      newstate.watch.watchEnt = NULL;
      }

	moveevent = EV_Camera_FollowingPath;
	PostEvent( EV_Camera_FollowingPath, FRAMETIME );
	}

void Camera::Orbit
	(
	Entity *ent,
	float dist,
   Entity *watch
	)

	{
	Stop();
	CreateOribit( Vector( 0, 0, newstate.move.height ), dist );
   newstate.move.cameraTime = -2;
	newstate.move.orbitEnt = ent;
   newstate.move.followingpath = true;
   followTime = level.time + jumpTime;

   watchTime = level.time + jumpTime;
   if ( watch )
      {
      newstate.watch.watchEnt = watch;
      }
   else
      {
	   newstate.watch.watchEnt = ent;
      }

	moveevent = EV_Camera_FollowingPath;
	PostEvent( EV_Camera_FollowingPath, FRAMETIME );
	}

void Camera::FollowEntity
	(
	Entity *ent,
	float dist,
	int mask,
   Entity *watch
	)

	{
	assert( ent );

	Stop();

	if ( ent )
		{
	   newstate.move.followEnt = ent;
      newstate.move.followingpath = false;
      followTime = level.time + jumpTime;
      watchTime = level.time + jumpTime;
      if ( watch )
         {
         newstate.watch.watchEnt = watch;
         }
      else
         {
	      newstate.watch.watchEnt = ent;
         }
		newstate.move.follow_dist = dist;
		newstate.move.follow_mask = mask;
		moveevent = EV_Camera_FollowingPath;
		PostEvent( EV_Camera_FollowingPath, 0 );
		}
	}

void Camera::StartMoving
	(
	Event *ev
	)

	{
	Entity *ent;
	SplinePath *path;
	int num;

	if ( !targetEnt )
		{
		num = G_FindTarget( 0, Target() );
		ent = G_GetEntity( num );
		if ( !num || !ent )
			{
         if ( spawnflags & PANNING )
            {
            currentstate.watch.panning = true;
	         moveevent = EV_Camera_FollowingPath;
	         PostEvent( EV_Camera_FollowingPath, FRAMETIME );
            return;
            }
         //
         // we took this out just because of too many warnings, oh well
         //
			//warning("StartMoving", "Can't find target for camera\n" );
			return;
			}
		}
	else
		{
		ent = targetEnt;
		}

	if ( ent->isSubclassOf( SplinePath ) )
		{
		path = ( SplinePath * )ent;
		FollowPath( path, spawnflags & ORBIT, targetWatchEnt );
		}
	else
		{
		if ( spawnflags & ORBIT )
			{
			Orbit( ent, newstate.move.follow_dist, targetWatchEnt );
			}
		else
			{
			FollowEntity( ent, newstate.move.follow_dist, newstate.move.follow_mask, targetWatchEnt );
			}
		}
	}

void Camera::StopMoving
	(
	Event *ev
	)

	{
	Stop();
	}

void Camera::Pause
	(
	Event *ev
	)

	{
	CancelEventsOfType( moveevent );
	}

void Camera::Continue
	(
	Event *ev
	)

	{
	if ( ( int )moveevent != ( int )NullEvent )
		{
		CancelEventsOfType( moveevent );
		PostEvent( moveevent, 0 );
		}
	}

void Camera::SetSpeed
	(
	Event *ev
	)

	{
	newstate.move.speed = ev->GetFloat( 1 );
	}

void Camera::SetDistance
	(
	Event *ev
	)

	{
	newstate.move.follow_dist = ev->GetFloat( 1 );
	}

void Camera::SetHeight
	(
	Event *ev
	)

	{
	newstate.move.height = ev->GetFloat( 1 );
	}

void Camera::SetYaw
	(
	Event *ev
	)

	{
	newstate.watch.yaw = ev->GetFloat( 1 );
	}

void Camera::FixedYaw
	(
	Event *ev
	)

	{
	newstate.watch.fixedyaw = true;
	}

void Camera::RelativeYaw
	(
	Event *ev
	)

	{
	newstate.watch.fixedyaw = false;
	}

void Camera::IgnoreAngles
	(
	Event *ev
	)

	{
	newstate.watch.ignoreangles = true;
	}

void Camera::UseAngles
	(
	Event *ev
	)

	{
   newstate.watch.ignoreangles = false;
	}

void Camera::SplineAngles
	(
	Event *ev
	)

	{
	newstate.watch.splineangles = true;
	}

void Camera::NormalAngles
	(
	Event *ev
	)

	{
   newstate.watch.splineangles = false;
	}

void Camera::FixedPosition
	(
	Event *ev
	)

	{
	newstate.move.fixed_position = true;
	}

void Camera::NoFixedPosition
	(
	Event *ev
	)

	{
	newstate.move.fixed_position = false;
	}

void Camera::PanEvent
	(
	Event *ev
	)

	{
	currentstate.watch.panning = true;
	}

void Camera::StopPanEvent
	(
	Event *ev
	)

	{
	currentstate.watch.panning = false;
	}

void Camera::PanSpeedEvent
	(
	Event *ev
	)

	{
	currentstate.watch.pan_speed = ev->GetFloat( 1 );
	}

void Camera::PanMaxEvent
	(
	Event *ev
	)

	{
	currentstate.watch.pan_max = ev->GetFloat( 1 );
	}

void Camera::SetPanAngles
	(
	Event *ev
	)

	{
   if ( ev->NumArgs() > 0 )
      {
	   currentstate.watch.pan_angles = ev->GetVector( 1 );
      }
   else
      {
      currentstate.watch.pan_angles = worldangles;
      }
	}

void Camera::SetNextCamera
	(
	Event *ev
	)

	{
   nextCamera = ev->GetString( 1 );
	}

void Camera::SetOverlay
	(
	Event *ev
	)

	{
   overlay = ev->GetString( 1 );
	}

void Camera::JumpCut
	(
	Event *ev
	)
	{
   if ( followTime )
      {
      currentstate.move = newstate.move;
      InitializeMoveState( newstate.move );
      followTime = 0;
      }
   if ( watchTime )
      {
      currentstate.watch = newstate.watch;
      InitializeWatchState( newstate.watch );
      watchTime = 0;
      }
   if ( moveevent )
      {
	   CancelEventsOfType( moveevent );
	   ProcessEvent( Event( moveevent ) );
      }
	}

void Camera::JumpTime
	(
	Event *ev
	)

	{
   float t;
   float newjumptime;

   newjumptime = ev->GetFloat( 1 );
   if ( followTime )
      {
      t = ( jumpTime - ( level.time - followTime ) ) / jumpTime;
      followTime = level.time + ( t * newjumptime );
      }
   if ( watchTime )
      {
      t = ( jumpTime - ( level.time - watchTime ) ) / jumpTime;
      watchTime = level.time + ( t * newjumptime );
      }
   jumpTime = newjumptime;
	}

void Camera::OrbitEvent
	(
	Event *ev
	)

	{
	Entity *ent;

	spawnflags |= ORBIT;
	ent = ev->GetEntity( 1 );
	if ( ent )
		{
		targetEnt = ent;
      targetWatchEnt = NULL;
      if ( ev->NumArgs() > 1 )
         targetWatchEnt = ev->GetEntity( 2 );
		if ( moveevent )
			{
			Stop();
			}
		ProcessEvent( EV_Activate );
		}
	}

void Camera::FollowEvent
	(
	Event *ev
	)

	{
	Entity *ent;

	spawnflags &= ~ORBIT;
	ent = ev->GetEntity( 1 );
	if ( ent )
		{
		targetEnt = ent;
      targetWatchEnt = NULL;
      if ( ev->NumArgs() > 1 )
         targetWatchEnt = ev->GetEntity( 2 );
		if ( moveevent )
			{
			Stop();
			}
		ProcessEvent( EV_Activate );
		}
	}

void Camera::SetFOV
	(
	Event *ev
	)

	{
	currentstate.move.fov = ev->GetFloat( 1 );
	}

void Camera::WatchEvent
	(
	Event *ev
	)

	{
	watchTime = level.time + jumpTime;
	newstate.watch.watchEnt = ev->GetEntity( 1 );
	}

void Camera::NoWatchEvent
	(
	Event *ev
	)

	{
	watchTime = level.time + jumpTime;
   newstate.watch.watchEnt = NULL;
	}

void SetCamera
	(
	Entity *ent
	)

	{
   int j;
	edict_t		*other;

	for( j = 1; j <= game.maxclients; j++ )
		{
		other = &g_edicts[ j ];
		if ( other->inuse && other->client )
			{
         Player * client;
         client = ( Player * )other->entity;
         client->SetCamera( ent );
			}
      }
	}

str &Camera::NextCamera
	(
   void
	)

	{
   return nextCamera;
	}

str &Camera::Overlay
	(
   void
	)

	{
   return overlay;
	}

void Camera::SetThread
	(
	Event *ev
	)

	{
   thread = ev->GetString( 1 );
	}

str &Camera::Thread
	(
   void
	)

	{
   return thread;
	}

CLASS_DECLARATION( Camera, SecurityCamera, "func_securitycamera" );

ResponseDef SecurityCamera::Responses[] =
	{
		{ NULL, NULL }
	};

SecurityCamera::SecurityCamera()
	{
	setModel( "camera.def" );
	showModel();
	}

⌨️ 快捷键说明

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