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

📄 viewthing.cpp

📁 this keik game source
💻 CPP
📖 第 1 页 / 共 2 页
字号:
	   { &EV_ViewThing_NextSkin,			( Response )Viewthing::NextSkinEvent },
	   { &EV_ViewThing_PrevSkin,			( Response )Viewthing::PrevSkinEvent },
	   { &EV_ViewThing_AutoAnimate,		( Response )Viewthing::AutoAnimateEvent },
		{ NULL, NULL }
	};

Viewthing::Viewthing
	(
	void
	)

	{
   animstate = 0;
	setSolidType( SOLID_BBOX );
   baseorigin = origin;
   Viewmodel.current_viewthing = entnum;

	PostEvent( EV_ViewThing_Think, FRAMETIME );
	}

void Viewthing::Think
	(
	Event *ev
	)
	
	{
   if (animstate >= 2)
      {
      Vector   forward;
	   Vector	right;
	   Vector	up;
      Vector   realmove;

	   angles.AngleVectors( &forward, &right, &up );
      realmove = right * total_delta[1] + up * total_delta[2] + forward * total_delta[0];
      setOrigin( baseorigin + realmove );
      }
	PostEvent( EV_ViewThing_Think, FRAMETIME );
   if ( ( animstate > 0 ) && ( Viewmodel.current_viewthing == entnum ) )
      {
      gi.dprintf( "current frame %d time %.2f\n", edict->s.frame, gi.Frame_Time( edict->s.modelindex, edict->s.anim, edict->s.frame ) );
      }
	}

void Viewthing::LastFrameEvent
	(
	Event *ev
	)

	{
	if ( animstate != 3 )
		{
		total_delta = "0 0 0";
		}
	}

void Viewthing::ToggleAnimateEvent
	(
	Event *ev
	)

	{
   animstate = ( animstate + 1 ) % 4;

   // reset to a known state
   StopAnimating();
   switch( animstate )
      {
      case 0:
         total_delta = "0 0 0";
         setOrigin( baseorigin );
         gi.dprintf( "Animation stopped.\n" );
         break;
      case 1:
         total_delta = "0 0 0";
         setOrigin( baseorigin );
         StartAnimating();
         gi.dprintf( "Animation no motion.\n" );
         break;
      case 2:
         StartAnimating();
         gi.dprintf( "Animation with motion and looping.\n" );
         break;
      case 3:
         StartAnimating();
         gi.dprintf( "Animation with motion no looping.\n" );
         break;
      }
	}

void Viewthing::SetModelEvent
	(
	Event *ev
	)

	{
	setModel( ev->GetString( 1 ) );
   NextAnim( 0 );
	}

void Viewthing::NextFrameEvent
	(
	Event *ev
	)

	{
   NextFrame( edict->s.frame + 1 );
	AnimateFrame();
   StopAnimating();
   animstate = 0;
   gi.dprintf( "current frame %d time %.2f\n", edict->s.frame, gi.Frame_Time( edict->s.modelindex, edict->s.anim, edict->s.frame ) );
	}

void Viewthing::PrevFrameEvent
	(
	Event *ev
	)

	{
   edict->s.frame--;
	if ( edict->s.frame < 0 )
		{
		edict->s.frame = last_frame_in_anim;
		}
	NextFrame( edict->s.frame );
	AnimateFrame();
   StopAnimating();
   animstate = 0;
   gi.dprintf( "current frame %d time %.2f\n", edict->s.frame, gi.Frame_Time( edict->s.modelindex, edict->s.anim, edict->s.frame ) );
	}

void Viewthing::NextAnimEvent
	(
	Event *ev
	)

	{
   int group_num;

   StopAnimating();

   for( group_num = 0; group_num < edict->s.numgroups ; group_num++ )
      {
      edict->s.groups[ group_num ] &= ~( MDL_GROUP_NODRAW | MDL_GROUP_SKINOFFSET_BIT0 );
      }

	NextAnim( edict->s.anim + 1 );
   NextFrame( 0 );
	AnimateFrame();
   StopAnimating();
   animstate = 0;
   gi.dprintf( "current anim %s\n", gi.Anim_NameForNum( edict->s.modelindex, edict->s.anim ) );
	}

void Viewthing::PrevAnimEvent
	(
	Event *ev
	)

	{
   int group_num;

   StopAnimating();

   for( group_num = 0; group_num < edict->s.numgroups ; group_num++ )
      {
      edict->s.groups[ group_num ] &= ~( MDL_GROUP_NODRAW | MDL_GROUP_SKINOFFSET_BIT0 );
      }

   NextAnim( edict->s.anim - 1 );
   NextFrame( 0 );
	AnimateFrame();
   StopAnimating();
   animstate = 0;
   gi.dprintf( "current anim %s\n", gi.Anim_NameForNum( edict->s.modelindex, edict->s.anim ) );
	}

void Viewthing::ScaleUpEvent
	(
	Event *ev
	)

	{
   edict->s.scale += 0.01f;
   gi.dprintf( "viewscale = %f\n", edict->s.scale );
	}

void Viewthing::ScaleDownEvent
	(
	Event *ev
	)

	{
   edict->s.scale -= 0.01f;
   gi.dprintf( "viewscale = %f\n", edict->s.scale );
	}

void Viewthing::SetScaleEvent
	(
	Event *ev
	)

	{
   float s;

   if ( ev->NumArgs() )
      {
      s = ev->GetFloat( 1 );
      edict->s.scale = s;
      gi.dprintf( "viewscale = %f\n", edict->s.scale );
      }
   else
      {
      gi.dprintf( "viewscale = %f\n", edict->s.scale );
      }
   }

void Viewthing::SetYawEvent
	(
	Event *ev
	)

	{
	if ( ev->NumArgs() > 0 )
		{
		angles.setYaw( ev->GetFloat( 1 ) );
		setAngles( angles );
		}
   gi.dprintf( "yaw = %f\n", angles.yaw() );
	}

void Viewthing::SetPitchEvent
	(
	Event *ev
	)

	{
	if ( ev->NumArgs() > 0 )
		{
		angles.setPitch( ev->GetFloat( 1 ) );
		setAngles( angles );
		}
   gi.dprintf( "pitch = %f\n", angles.pitch() );
	}

void Viewthing::SetRollEvent
	(
	Event *ev
	)

	{
	if ( ev->NumArgs() > 0 )
		{
		angles.setRoll( ev->GetFloat( 1 ) );
		setAngles( angles );
		}
   gi.dprintf( "roll = %f\n", angles.roll() );
	}

void Viewthing::SetAnglesEvent
	(
	Event *ev
	)

	{
	if ( ev->NumArgs() > 2 )
		{
		angles.x = ev->GetFloat( 1 );
		angles.y = ev->GetFloat( 2 );
		angles.z = ev->GetFloat( 3 );
		setAngles( angles );
		}

   gi.dprintf( "angles = %f, %f, %f\n", angles.x, angles.y, angles.z );
	}

void Viewthing::AttachModel
	(
	Event *ev
	)

	{
   int groupindex;
   int tri_num;
   vec3_t orient;

   if ( gi.GetBoneInfo( edict->s.modelindex, ev->GetString( 1 ), &groupindex, &tri_num, orient ) )
      {
      Viewthing * child;

      child = new Viewthing;
      // 
      // attach the child
      //
      child->setModel( ev->GetString( 2 ) );
      child->attach( entnum, groupindex, tri_num, Vector(orient) );
      }
   else
      {
      gi.dprintf( "attach failed\n" );
      }
	}

void Viewthing::Delete
	(
	Event *ev
	)

	{
   Viewmodel.current_viewthing = 0;
   PostEvent( EV_Remove, 0 );
	}

void Viewthing::DetachAll
	(
	Event *ev
	)

	{
   int i;
   int num;

   num = numchildren;
   for (i=0;i<MAX_MODEL_CHILDREN;i++)
      {
      Entity * ent;
      if (!children[i])
         continue;
      ent = ( Entity * )G_GetEntity( children[i] );
      ent->PostEvent( EV_Remove, 0 );
      num--;
      if (!num)
         break;
      }
	}

void Viewthing::BoneGroup
	(
	Event *ev
	)

	{
   int s;

   if ( ev->NumArgs() )
      {
      s = ev->GetInteger( 1 );
      edict->s.bone.group_num = s;
      }
   gi.dprintf( "bone_group = %d\n", edict->s.bone.group_num );
   }

void Viewthing::BoneNum
	(
	Event *ev
	)

	{
   int s;

   if ( ev->NumArgs() )
      {
      s = ev->GetInteger( 1 );
      edict->s.bone.tri_num = s;
      }
   gi.dprintf( "bone_num = %d\n", edict->s.bone.tri_num );
   }

void Viewthing::ChangeOrigin
	(
	Event *ev
	)

	{
   if ( ev->NumArgs() )
      {
      origin.x = ev->GetFloat( 1 );
      origin.y = ev->GetFloat( 2 );
      origin.z = ev->GetFloat( 3 );
      setOrigin( origin );
      baseorigin = origin;
      }
   gi.dprintf( "vieworigin = x%f y%f z%f\n", origin.x, origin.y, origin.z );
   }

void Viewthing::ChangeBoneAngles
	(
	Event *ev
	)

	{
   if ( ev->NumArgs() )
      {
      edict->s.bone.orientation[0] = ev->GetFloat( 1 );
      edict->s.bone.orientation[1] = ev->GetFloat( 2 );
      edict->s.bone.orientation[2] = ev->GetFloat( 3 );
      }
   gi.dprintf( "boneangles = x%f y%f z%f\n", edict->s.bone.orientation[0], edict->s.bone.orientation[1], edict->s.bone.orientation[2] );
   }

void Viewthing::NextSkinEvent
	(
	Event *ev
	)

	{
   edict->s.skinnum = (edict->s.skinnum + 1)%gi.NumSkins( edict->s.modelindex );
   gi.dprintf( "current skin %s\n", gi.Skin_NameForNum( edict->s.modelindex, edict->s.skinnum ));
	}

void Viewthing::PrevSkinEvent
	(
	Event *ev
	)

	{
   edict->s.skinnum = (edict->s.skinnum - 1)%gi.NumSkins( edict->s.modelindex );
   gi.dprintf( "current skin %s\n", gi.Skin_NameForNum( edict->s.modelindex, edict->s.skinnum ));
	}

void Viewthing::AutoAnimateEvent
	(
	Event *ev
	)

	{
   if ( edict->s.effects & EF_AUTO_ANIMATE )
      {
      gi.dprintf( "turning off auto animation\n" );
	   edict->s.effects &= ~EF_AUTO_ANIMATE;
      }
   else
      {
      gi.dprintf( "turning on auto animation\n" );
	   edict->s.effects |= EF_AUTO_ANIMATE;
      }
	}

⌨️ 快捷键说明

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