Ru/Over the Shoulder View

From Valve Developer Community
Jump to navigation Jump to search

Template:Otherlang2

заплечная камера в игре

Шаг 1 - поставить вид от третьего лица по умолчанию.

Найдите и откройте 'in_camera.cpp' , он должен быть в файлах 'client.dll' . Теперь найдите каждый вариант использования sv_cheats и удалите или закомментируйте все эти строки. Найдите последнюю функцию, и в самом конце вы должны увидеть что-то вроде этого 'void CInput :: Init_Camera (void)' В этой функции добавьте m_fCameraInThirdPerson = true ; Должно получиться так:

void CInput :: Init_Camera (void)
{
   m_CameraIsOrthographic = false;
   m_fCameraInThirdPerson = true;
}
</ Источник>
Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока.

== Step 2 - Create a view from behind the shoulder. ==
In this step, we will make the necessary changes in order to make a camera with a view from the back. Find and open clientmode_shared.cpp. It is also located in the client.dll files.
Now find the function void ClientModeShared :: OverrideView (CViewSetup * pSetup).
Replace everything inside the function with:
<source lang = cpp>
C_BasePlayer * pPlayer = C_BasePlayer :: GetLocalPlayer ();
if (! pPlayer)
       return;

pPlayer->OverrideView( pSetup );

if( ::input->CAM_IsThirdPerson() )
{
   Vector camForward, camRight, camUp;
     
          AngleVectors( pPlayer->EyeAngles(), &camForward, &camRight, &camUp );
     
   trace_t tr, tr2;
   Vector vecStart, vecStop, vecDirection, vecSetDirection;   
   static float camCurrentY;   
   static float camCurrentX=16.0f;   
   float camDelta=0.5f;
   vecStart=pSetup->origin;

   AngleVectors(pPlayer->EyeAngles(), &vecDirection);   
      
   vecSetDirection.Init(0,0,1.0f);
   vecDirection=vecDirection.Cross(vecSetDirection);
   vecStop = vecStart + vecDirection*52.0f;

   UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
      
   if (tr.fraction == 1) //are we far enough not to hit the wall with the camera
   {
    if(camCurrentX < 16.0f)
     camCurrentX +=camDelta;
    if(camCurrentX >16.0f)
     camCurrentX=16.0f;
    VectorMA( pSetup->origin, camCurrentX, camRight, pSetup->origin); //setting the correct offset
    VectorMA( pSetup->origin, 16.0f, camUp, pSetup->origin);
     vecStart=tr.endpos;
   }
   else   
   {   
       
    vecStop = vecStart + vecDirection * -52.0f;
       
    UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
         
    if (tr.fraction == 1)   
    {   
     if(camCurrentX > -16.0f)
      camCurrentX -=camDelta;
     if(camCurrentX < -16.0f)
      camCurrentX=-16.0f;
     VectorMA( pSetup->origin, camCurrentX, camRight, pSetup->origin);
     VectorMA( pSetup->origin, 16.0f, camUp, pSetup->origin);
     vecStart=tr.endpos;
    }
    else   
    {   
     VectorMA( pSetup->origin, 0.0f, camRight, pSetup->origin);   
     AngleVectors(pPlayer->EyeAngles(), &vecDirection);   
     vecSetDirection.Init(1.0f,0,0);
     vecDirection=vecDirection.Cross(vecSetDirection);
     vecStop = vecStart +vecDirection*32.0f;
       
     UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr);

     if(tr.fraction == 1)
     {
      VectorMA( pSetup->origin, 32.0f, camUp, pSetup->origin);
      vecStart=tr.endpos;
     }
     else   
       //Add code to make the player transparent so the player can see better. (?)
     {
      VectorMA( pSetup->origin, 0.0f, camUp, pSetup->origin);
     }
    }

   }
       
   AngleVectors(pPlayer->EyeAngles(), &vecDirection);   
   vecStop = vecStart + vecDirection * -96;
   UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
     
   vecStart=pSetup->origin;
     
   vecStop = vecStart+vecDirection*-96;
   UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
        
   if(tr.fraction != 1)
   {
    camCurrentY = -96 * tr.fraction + 10.0f;
   }
   else
          {
    camCurrentY=-96.0f;
    VectorMA( pSetup->origin, camCurrentY, camForward, pSetup->origin);
   }
}

This will create a shoulder view that will stand by the right shoulder as standard. This is certainly not an ideal code, but to start creating some interesting mod, it may be suitable. If there is no space on the right, then a test will occur and if there is space, then x and z -16 / + 16 will be installed and then the distance behind will be checked. If there is no space to the left or to the right, z is set to +32 and x 0. This will place the camera above the player’s model head, so the player can still see. If there is not enough space above, the camera will be placed at eye level. All these checks are needed for the correct type of camera, for example, if you crawl in the ventilation pipes or worse, in the sewer

Step 3 - Fix a small bug

There is a small bug that needs to be fixed, if you don’t fix it, then the animation of your character when turning the camera around will be buggy. Find and open c_sdk_player.cpp. Find the void C_SDKPlayer :: UpdateClientSideAnimation () function and replace the contents with:

if ( this == C_SDKPlayer::GetLocalSDKPlayer() )
   m_PlayerAnimState->Update( EyeAngles()[YAW], EyeAngles()[PITCH] );
else
   m_PlayerAnimState->Update( m_angEyeAngles[YAW], EyeAngles()[PITCH] );

BaseClass::UpdateClientSideAnimation();

Now the animation should be correct. For games on the engine HL2MP need to do a little more. Find and open the hl2mp_player.cpp file. Find the void function CHL2MP_Player :: PostThink (void) and replace the content with:

BaseClass :: PostThink ();
     
if ( GetFlags() & FL_DUCKING )
{
   SetCollisionBounds( VEC_CROUCH_TRACE_MIN, VEC_CROUCH_TRACE_MAX );
}

m_PlayerAnimState.Update();

QAngle angles = GetLocalAngles();

CBasePlayer *pPlayer = dynamic_cast<CBasePlayer*>(this);
if ( pPlayer )
{
   angles[PITCH] = EyeAngles()[PITCH];
   angles[YAW] = EyeAngles()[YAW];
}
else
{
   angles[PITCH] = EyeAngles()[PITCH];
   angles[YAW] = m_angEyeAngles[YAW];
}

SetLocalAngles( angles );

Now there should be no glitches.

Step 4 - Self-adjusting sight.

Find and open hud_crosshair.cpp. It resides in client.dll files. Now find the function void CHudCrosshair :: Paint (void). Replace the contents of the function with: <source lang = cpp> if (! m_pCrosshair)    return;

if (! IsCurrentViewAccessAllowed ())    return;

C_BasePlayer * pPlayer = C_BasePlayer :: GetLocalPlayer (); Vector vecStart, vecStop, vecDirection, vecCrossPos; trace_t tr;       AngleVectors (pPlayer-> EyeAngles (), & vecDirection);

vecStart = pPlayer-> EyePosition (); vecStop = vecStart + vecDirection * MAX_TRACE_LENGTH;       UTIL_TraceLine (vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, & tr);             ScreenTransform (tr.endpos, vecCrossPos);

m_pCrosshair-> DrawSelf (0.5f * ScreenWidth () + 0.5f * ScreenWidth () * vecCrossPos [0] -0.5f * m_pCrosshair-> Width (),      0.5f * ScreenHeight () + (0.5f * ScreenHeight () * - vecCrossPos [1]) - 0.5f * m_pCrosshair-> Height (),      m_clrCrosshair); </ source> Since the view is already from the shoulder, the coordinates of the sight must change. This is what we are actually changing.