Skip to content

Commit

Permalink
correct menu text ang rotation
Browse files Browse the repository at this point in the history
  • Loading branch information
Nyano1337 committed Jan 14, 2025
1 parent 604efad commit b84c87b
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 29 deletions.
28 changes: 7 additions & 21 deletions src/core/menu.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -11,15 +11,8 @@ extern void SetMenuEntityTransmiter(CBaseEntity* pMenu, CBasePlayerController* p
constexpr float g_fMenuOffsetX = -9.1f;
constexpr float g_fMenuOffsetY = -4.6f;

Vector CWorldTextMenu::GetAimPoint(const Vector& eyePosition, const QAngle& eyeAngles, float distanceToTarget) {
double pitch = eyeAngles.x * (M_PI / 180.0);
double yaw = eyeAngles.y * (M_PI / 180.0);

double targetX = eyePosition.x + distanceToTarget * std::cos(pitch) * std::cos(yaw);
double targetY = eyePosition.y + distanceToTarget * std::cos(pitch) * std::sin(yaw);
double targetZ = eyePosition.z - distanceToTarget * std::sin(pitch);

return Vector(targetX, targetY, targetZ);
Vector CWorldTextMenu::GetAimPoint(const Vector& eyePosition, float distanceToTarget) {
return Vector(eyePosition.x + distanceToTarget, eyePosition.y, eyePosition.z);
}

CWorldTextMenu::CWorldTextMenu(MenuHandler pFnHandler, std::string sTitle) : CBaseMenu(pFnHandler, sTitle) {
Expand Down Expand Up @@ -151,14 +144,11 @@ void CWorldTextMenu::Display(CCSPlayerPawnBase* pPawn, int iPageIndex) {
SetMenuEntityTransmiter(pMenuEntity, pPawn->GetController());

Vector& vmPos = pViewModel->GetAbsOrigin();
QAngle& vmAng = pViewModel->GetAbsAngles();
Vector panelPos = GetAimPoint(vmPos, vmAng, 7.0f);
QAngle panelAng = vmAng;
panelAng.y -= 90.0f;
panelAng.z += 90.0f;
Vector panelPos = GetAimPoint(vmPos, 7.0f);

Vector rig;
Vector dwn;
static QAngle panelAng = {0.0f, -90.0f, 90.0f};
AngleVectors(panelAng, &rig, &dwn, nullptr);

rig *= g_fMenuOffsetX;
Expand All @@ -179,18 +169,14 @@ void CWorldTextMenu::Display(CCSPlayerPawnBase* pPawn, int iPageIndex) {
pMenuBackground->Enable();
SetMenuEntityTransmiter(pMenuBackground, pPawn->GetController());

Vector bgPos = GetAimPoint(vmPos, vmAng, 7.09f);
QAngle bgAng = vmAng;
bgAng.y -= 90.0f;
bgAng.z += 90.0f;

AngleVectors(bgAng, &rig, &dwn, nullptr);
Vector bgPos = GetAimPoint(vmPos, 7.09f);
AngleVectors(panelAng, &rig, &dwn, nullptr);

rig *= (g_fMenuOffsetX - 0.2f);
dwn *= (g_fMenuOffsetY + 1.64f);

bgPos += rig + dwn;
pMenuBackground->Teleport(&bgPos, &bgAng, nullptr);
pMenuBackground->Teleport(&bgPos, &panelAng, nullptr);
}

std::string CBaseMenu::GetItem(int iPageIndex, int iItemIndex) {
Expand Down
2 changes: 1 addition & 1 deletion src/core/menu.h
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ class CWorldTextMenu : public CBaseMenu {
virtual void Display(CCSPlayerPawnBase* pPawn, int iPageIndex = 0) override;

public:
static Vector GetAimPoint(const Vector& eyePosition, const QAngle& eyeAngles, float distanceToTarget = 100.0);
static Vector GetAimPoint(const Vector& eyePosition, float distanceToTarget = 100.0);

private:
CHandle<CPointWorldText> m_hWorldText;
Expand Down
17 changes: 10 additions & 7 deletions src/sdk/entity/ccsplayerpawn.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -12,13 +12,16 @@ Vector CCSPlayerPawnBase::GetEyePosition() {
}

CBaseViewModel* CCSPlayerPawnBase::GetCustomViewModel() {
CBaseViewModel* pViewModel = m_pViewModelServices()->GetViewModel(1);
if (!pViewModel) {
pViewModel = (CBaseViewModel*)MEM::CALL::CreateEntityByName("predicted_viewmodel");
pViewModel->DispatchSpawn();
m_pViewModelServices()->SetViewModel(1, pViewModel);
pViewModel->m_hOwnerEntity(this->GetRefEHandle());
CBaseViewModel* pCustomViewModel = m_pViewModelServices()->GetViewModel(1);
if (!pCustomViewModel) {
pCustomViewModel = (CBaseViewModel*)MEM::CALL::CreateEntityByName("predicted_viewmodel");
pCustomViewModel->DispatchSpawn();
m_pViewModelServices()->SetViewModel(1, pCustomViewModel);
pCustomViewModel->m_hOwnerEntity(this->GetRefEHandle());
} else {
static QAngle nullAng;
pCustomViewModel->Teleport(nullptr, &nullAng, nullptr);
}

return pViewModel;
return pCustomViewModel;
}

0 comments on commit b84c87b

Please sign in to comment.