diff --git a/Source/Contents/Camera/Camera.h b/Source/Contents/Camera/Camera.h index 261c6962..76591c55 100644 --- a/Source/Contents/Camera/Camera.h +++ b/Source/Contents/Camera/Camera.h @@ -30,6 +30,8 @@ public: virtual void Render(); virtual void Update(); + matrix AlternateView(float yaw) const; + /* 0004 */ CameraShake shake; /* 0020 */ CameraState camera; /* 0050 */ float unknown_0050[3]; diff --git a/Source/Contents/Camera/CameraFrame.h b/Source/Contents/Camera/CameraFrame.h index 55afcf27..fd9b3b7c 100644 --- a/Source/Contents/Camera/CameraFrame.h +++ b/Source/Contents/Camera/CameraFrame.h @@ -17,7 +17,6 @@ struct CameraFrame { void Build(const CameraState& camera); void Refresh(const CameraState& camera, CRenderer& renderer); void Forward(const CameraState& camera, float* output) const; - void AlternateView(const CameraState& camera, float yaw, matrix& output) const; }; diff --git a/Source/Contents/Camera/CameraQueries.cpp b/Source/Contents/Camera/CameraQueries.cpp index 3fc10b88..d5452143 100644 --- a/Source/Contents/Camera/CameraQueries.cpp +++ b/Source/Contents/Camera/CameraQueries.cpp @@ -1,4 +1,4 @@ -#include "Contents/Camera/CameraFrame.h" +#include "Contents/Camera/Camera.h" #include "Client/Mode/CGameMode.h" #include "Client/Mode/ModeMgr.h" #include "Contents/World/World.h" @@ -6,14 +6,6 @@ #include -namespace { - // INLINED - float InverseLength(float squared) { - const float root = std::sqrt(squared); - return static_cast(1.0 / static_cast(root)); - } -} - // OFFSET: 0x00ADBAC0 // FUNCTION: fn_17924 void CameraFrame::Forward(const CameraState& camera, float* output) const { @@ -24,7 +16,7 @@ void CameraFrame::Forward(const CameraState& camera, float* output) const { output[1] = y; output[0] = x; output[2] = z; - const float inverse = InverseLength((y * y + x * x) + z * z); + const float inverse = 1.0f / SquareRoot((y * y + x * x) + z * z); output[0] = inverse * output[0]; const float last = inverse * output[2]; output[1] = inverse * output[1]; @@ -33,21 +25,23 @@ void CameraFrame::Forward(const CameraState& camera, float* output) const { // OFFSET: 0x00ADBB60 // FUNCTION: fn_17925 -void CameraFrame::AlternateView(const CameraState& camera, float yaw, matrix& output) const { +matrix CView::AlternateView(float yaw) const { constexpr float pi = 3.141592f; matrix orbit; - orbit.MakeXRotation((camera.pitch / 180.0f) * pi); + orbit.MakeXRotation((this->camera.pitch / 180.0f) * pi); orbit.AppendYRotation((yaw / 180.0f) * pi); - const float distance = -camera.distance; + const float distance = -this->camera.distance; float eye[3]; - eye[0] = (((orbit.values[3] * 0.0f + orbit.values[0] * 0.0f) + distance * orbit.values[6]) + orbit.values[9]) + camera.target[0]; - eye[1] = (((orbit.values[4] * 0.0f + orbit.values[1] * 0.0f) + distance * orbit.values[7]) + orbit.values[10]) + camera.target[1]; - eye[2] = (((orbit.values[5] * 0.0f + orbit.values[2] * 0.0f) + distance * orbit.values[8]) + orbit.values[11]) + camera.target[2]; + eye[0] = (((orbit.values[3] * 0.0f + orbit.values[0] * 0.0f) + distance * orbit.values[6]) + orbit.values[9]) + this->camera.target[0]; + eye[1] = (((orbit.values[4] * 0.0f + orbit.values[1] * 0.0f) + distance * orbit.values[7]) + orbit.values[10]) + this->camera.target[1]; + eye[2] = (((orbit.values[5] * 0.0f + orbit.values[2] * 0.0f) + distance * orbit.values[8]) + orbit.values[11]) + this->camera.target[2]; const float height = static_cast(g_modeMgr.GetGameMode())->scene->terrain->Height(eye[0], eye[2]); if (eye[1] > height) { eye[1] = height; } - output.LookAt(eye, camera.target, this->up); + matrix output; + output.LookAt(eye, this->camera.target, this->frame.up); + return output; }