Ru/Over the Shoulder View: Difference between revisions

From Valve Developer Community
< Ru
Jump to navigation Jump to search
Line 19: Line 19:
Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока.
Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока.


== Step 2 - Create a view from behind the shoulder. ==
== Шаг 2 - Создайте вид из-за плеча. ==
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.
На этом шаге мы внесем необходимые изменения, чтобы сделать камеру с видом сзади. Найдите и откройте clientmode_shared.cpp. Он также находится в файлах client.dll.
Now find the function void ClientModeShared :: OverrideView (CViewSetup * pSetup).
Теперь найдите функцию void ClientModeShared :: OverrideView (CViewSetup * pSetup).
Replace everything inside the function with:
Замените все внутри функции:
<source lang = cpp>
<source lang = cpp>
C_BasePlayer * pPlayer = C_BasePlayer :: GetLocalPlayer ();
C_BasePlayer * pPlayer = C_BasePlayer :: GetLocalPlayer ();
Line 51: Line 51:
   UTIL_TraceLine( vecStart, vecStop, MASK_ALL, pPlayer, COLLISION_GROUP_NONE, &tr );
   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 (tr.fraction == 1) //мы достаточно далеко, чтобы не ударить стену камерой
   {
   {
     if(camCurrentX < 16.0f)
     if(camCurrentX < 16.0f)
Line 122: Line 122:
}
}
</source>
</source>
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
Если справа нет места, тогда будет проведен тест, а если есть место, будут установлены x и z -16 / + 16, а затем будет проверено расстояние позади. Если слева или справа нет места, z устанавливается на +32 и x 0. Это поместит камеру над головой модели игрока, чтобы игрок все еще мог видеть. Если сверху недостаточно места, камера будет расположена на уровне глаз. Все эти проверки необходимы для правильного типа камеры, например, если вы ползете в вентиляционных трубах или хуже, в канализации


== Step 3 - Fix a small bug ==
== Step 3 - Fix a small bug ==

Revision as of 15:13, 19 May 2019

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;
}
</ Источник>
Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока.

== Шаг 2 - Создайте вид из-за плеча. ==
На этом шаге мы внесем необходимые изменения, чтобы сделать камеру с видом сзади. Найдите и откройте clientmode_shared.cpp. Он также находится в файлах client.dll.
Теперь найдите функцию void ClientModeShared :: OverrideView (CViewSetup * pSetup).
Замените все внутри функции:
<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) //мы достаточно далеко, чтобы не ударить стену камерой
   {
    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);
   }
}

Это создаст вид плеча, который будет стоять у правого плеча в стандартной комплектации. Это, конечно, не идеальный код, но для начала можно создать интересный мод. Если справа нет места, тогда будет проведен тест, а если есть место, будут установлены x и z -16 / + 16, а затем будет проверено расстояние позади. Если слева или справа нет места, z устанавливается на +32 и x 0. Это поместит камеру над головой модели игрока, чтобы игрок все еще мог видеть. Если сверху недостаточно места, камера будет расположена на уровне глаз. Все эти проверки необходимы для правильного типа камеры, например, если вы ползете в вентиляционных трубах или хуже, в канализации

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.