..................................................
-
Автор темы
- #1
Он типо как в неверлузе плавно переключается
в hooked_overrideview.cpp
In IEngineTrace.hpp
Спащенно с catware
в hooked_overrideview.cpp
C++:
void Thirdperson_Init(bool fakeducking, float progress) {
/* our current fraction. */
static float current_fraction = 0.0f;
auto distance = ((float)g_cfg.misc.thirdperson_distance) * progress;
Vector angles, inverse_angles;
// get camera angles.
m_engine()->GetViewAngles(angles);
m_engine()->GetViewAngles(inverse_angles);
// cam_idealdist convar.
inverse_angles.z = distance;
// set camera direction.
Vector forward, right, up;
math::angle_vectors(inverse_angles, &forward, &right, &up);
// various fixes to camera when fakeducking.
auto eye_pos = fakeducking ? g_ctx.local()->GetAbsOrigin() + m_gamemovement()->GetPlayerViewOffset(false) : g_ctx.local()->GetAbsOrigin() + g_ctx.local()->m_vecViewOffset();
auto offset = eye_pos + forward * -distance + right + up;
// setup trace filter and trace.
CTraceFilterWorldOnly filter;
trace_t tr;
// tracing to camera angles.
m_trace()->TraceRay(Ray_t(eye_pos, offset, Vector(-16.0f, -16.0f, -16.0f), Vector(16.0f, 16.0f, 16.0f)), 131083, &filter, &tr);
// interpolate camera speed if something behind our camera.
if (current_fraction > tr.fraction)
current_fraction = tr.fraction;
else if (current_fraction > 0.9999f)
current_fraction = 1.0f;
// adapt distance to travel time.
current_fraction = math::interpolate(current_fraction, tr.fraction, m_globals()->m_frametime * 10.0f);
angles.z = distance * current_fraction;
// override camera angles.
m_input()->m_vecCameraOffset = angles;
}
void thirdperson(bool fakeducking)
{
/* thirdperson code. */
{
static float progress;
static bool in_transition;
static auto in_thirdperson = false;
if (!in_thirdperson && g_ctx.globals.in_thirdperson)
{
in_thirdperson = true;
}
else if (in_thirdperson && !g_ctx.globals.in_thirdperson)
in_thirdperson = false;
if (g_ctx.local()->is_alive() && in_thirdperson)
{
in_transition = false;
if (!m_input()->m_fCameraInThirdPerson)
{
m_input()->m_fCameraInThirdPerson = true;
}
}
else
{
progress -= m_globals()->m_frametime * 8.f + (progress / 100);
progress = std::clamp(progress, 0.f, 1.f);
if (!progress)
m_input()->m_fCameraInThirdPerson = false;
else
{
in_transition = true;
m_input()->m_fCameraInThirdPerson = true;
}
}
if (m_input()->m_fCameraInThirdPerson && !in_transition)
{
progress += m_globals()->m_frametime * 8.f + (progress / 100);
progress = std::clamp(progress, 0.f, 1.f);
}
Thirdperson_Init(fakeducking, progress);
}
/* thirdperson on death code. */
{
static auto require_reset = false;
if (g_ctx.local()->is_alive())
{
require_reset = false;
return;
}
if (g_cfg.misc.thirdperson_when_spectating)
{
if (require_reset)
g_ctx.local()->m_iObserverMode() = OBS_MODE_CHASE;
if (g_ctx.local()->m_iObserverMode() == OBS_MODE_IN_EYE)
require_reset = true;
}
}
}
In IEngineTrace.hpp
Код:
struct Ray_t
{
VectorAligned m_Start; // starting point, centered within the extents
VectorAligned m_Delta; // direction + length of the ray
VectorAligned m_StartOffset; // Add this to m_Start to Get the actual ray start
VectorAligned m_Extents; // Describes an axis aligned box extruded along a ray
const matrix3x4_t *m_pWorldAxisTransform;
bool m_IsRay; // are the extents zero?
bool m_IsSwept; // is delta != 0?
Ray_t() : m_pWorldAxisTransform(NULL) {} //-V730
Ray_t(Vector const& start, Vector const& end) { //-V818
m_Delta = end - start;
m_IsSwept = (m_Delta.LengthSqr() != 0); //-V550
m_Extents.Init();
m_pWorldAxisTransform = NULL;
m_IsRay = true;
// Offset m_Start to be in the center of the box...
m_StartOffset.Init();
m_Start = start;
}
__forceinline Ray_t(const Vector& start, const Vector& end, const Vector& mins, const Vector& maxs) {
m_Delta = VectorAligned{ end - start };
m_pWorldAxisTransform = nullptr;
m_IsSwept = m_Delta.LengthSqr() != 0.f;
m_Extents = VectorAligned{ maxs - mins };
m_Extents *= 0.5f;
m_IsRay = m_Extents.LengthSqr() < 1e-6;
m_StartOffset = VectorAligned{ mins + maxs };
m_StartOffset *= 0.5f;
m_Start = VectorAligned{ start + m_StartOffset };
m_StartOffset *= -1.f;
}
void Init(Vector const& start, Vector const& end)
{
m_Delta = end - start;
m_IsSwept = (m_Delta.LengthSqr() != 0); //-V550
m_Extents.Init();
m_pWorldAxisTransform = NULL;
m_IsRay = true;
// Offset m_Start to be in the center of the box...
m_StartOffset.Init();
m_Start = start;
}
void Init(Vector const& start, Vector const& end, Vector const& mins, Vector const& maxs)
{
m_Delta = end - start;
m_pWorldAxisTransform = NULL;
m_IsSwept = (m_Delta.LengthSqr() != 0); //-V550
m_Extents = maxs - mins;
m_Extents *= 0.5f;
m_IsRay = (m_Extents.LengthSqr() < 1e-6);
// Offset m_Start to be in the center of the box...
m_StartOffset = maxs + mins;
m_StartOffset *= 0.5f;
m_Start = start + m_StartOffset;
m_StartOffset *= -1.0f;
}
Vector InvDelta() const
{
Vector vecInvDelta;
for(int iAxis = 0; iAxis < 3; ++iAxis) {
if(m_Delta[iAxis] != 0.0f) { //-V550
vecInvDelta[iAxis] = 1.0f / m_Delta[iAxis];
} else {
vecInvDelta[iAxis] = FLT_MAX;
}
}
return vecInvDelta;
}
private:
};
Спащенно с catware
Последнее редактирование: