Ru/Over the Shoulder View: Difference between revisions
Line 19: | Line 19: | ||
Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока. | Эти действия создали представление стандарта от третьего лица, не требуя каких-либо жестов от игрока. | ||
== | == Шаг 2 - Создайте вид из-за плеча. == | ||
На этом шаге мы внесем необходимые изменения, чтобы сделать камеру с видом сзади. Найдите и откройте clientmode_shared.cpp. Он также находится в файлах client.dll. | |||
Теперь найдите функцию void ClientModeShared :: OverrideView (CViewSetup * pSetup). | |||
Замените все внутри функции: | |||
<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) // | if (tr.fraction == 1) //мы достаточно далеко, чтобы не ударить стену камерой | ||
{ | { | ||
if(camCurrentX < 16.0f) | if(camCurrentX < 16.0f) | ||
Line 122: | Line 122: | ||
} | } | ||
</source> | </source> | ||
Это создаст вид плеча, который будет стоять у правого плеча в стандартной комплектации. Это, конечно, не идеальный код, но для начала можно создать интересный мод. | |||
Если справа нет места, тогда будет проведен тест, а если есть место, будут установлены 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
Шаг 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.