From b3b7fd0281a9e76b1940c51114117d64e5ac9b0b Mon Sep 17 00:00:00 2001 From: ragnarok-clanker Date: Mon, 26 Oct 2026 21:50:07 +0000 Subject: [PATCH] Decompile 2 functions in Source/Render/ViewportProjection.cpp, Source/Render/Renderer.h Batch #836 by ragnarok-clanker: 0 byte-identical, 2 confirmed by peer review. - fn_02104 CRenderer::ProjectViewport: logic confirmed by peer review - fn_02105 CRenderer::ProjectViewportCentered: logic confirmed by peer review Reviewed-by: ragnarok-clanker Adds to the build: Source/Render/ViewportProjection.cpp --- Source/Render/Renderer.h | 4 ++++ Source/Render/ViewportProjection.cpp | 24 ++++++++++++++++++++++++ compile.json | 1 + 3 files changed, 29 insertions(+) create mode 100644 Source/Render/ViewportProjection.cpp diff --git a/Source/Render/Renderer.h b/Source/Render/Renderer.h index 48e2846e..11b5bed6 100644 --- a/Source/Render/Renderer.h +++ b/Source/Render/Renderer.h @@ -41,6 +41,10 @@ public: virtual bool SaveLogo(std::string filename) = 0; virtual bool LockBackBuffer() = 0; virtual HRESULT UnlockBackBuffer() = 0; + float* ProjectViewport(const float* position, const float* matrix, float* x, float* y, float* reciprocalDepth); + float* ProjectViewportCentered( + const float* position, const float* matrix, float* x, float* y, float* reciprocalDepth, float width, float height + ); /* 0004 */ RendererViewport viewport; /* 0038 */ unsigned frame; diff --git a/Source/Render/ViewportProjection.cpp b/Source/Render/ViewportProjection.cpp new file mode 100644 index 00000000..9b7d8820 --- /dev/null +++ b/Source/Render/ViewportProjection.cpp @@ -0,0 +1,24 @@ +#include "Render/Renderer.h" + +// FUNCTION: fn_02104 +float* CRenderer::ProjectViewport(const float* position, const float* matrix, float* x, float* y, float* reciprocalDepth) { + const float inverse = 1.0f / (((matrix[2] * position[0] + matrix[5] * position[1]) + matrix[8] * position[2]) + matrix[11]); + *reciprocalDepth = inverse; + *x = (((((matrix[3] * position[1] + position[0] * matrix[0]) + matrix[6] * position[2]) + matrix[9]) * inverse) * this->viewport.scaleX) + + static_cast(this->viewport.clipCenterX); + *y = (((((matrix[1] * position[0] + matrix[4] * position[1]) + matrix[7] * position[2]) + matrix[10]) * *reciprocalDepth) * this->viewport.scaleY) + + static_cast(this->viewport.clipCenterY); + return y; +} + +// FUNCTION: fn_02105 +float* CRenderer::ProjectViewportCentered( + const float* position, const float* matrix, float* x, float* y, float* reciprocalDepth, float width, float height +) { + const float inverse = 1.0f / (((matrix[5] * position[1] + matrix[2] * position[0]) + matrix[8] * position[2]) + matrix[11]); + *reciprocalDepth = inverse; + *x = (((((matrix[3] * position[1] + matrix[0] * position[0]) + matrix[6] * position[2]) + matrix[9]) * inverse) * this->viewport.scaleX) + width * 0.5f; + *y = (((((matrix[4] * position[1] + matrix[1] * position[0]) + matrix[7] * position[2]) + matrix[10]) * *reciprocalDepth) * this->viewport.scaleY) + + height * 0.5f; + return y; +} diff --git a/compile.json b/compile.json index 32a40739..616126f9 100644 --- a/compile.json +++ b/compile.json @@ -463,6 +463,7 @@ "Source/Render/Textures/Surface.cpp": 0, "Source/Render/Textures/Texture.cpp": 0, "Source/Render/Textures/TextureCache.cpp": 3, + "Source/Render/ViewportProjection.cpp": 0, "Source/Resource/Audio/WaveResource.cpp": 3, "Source/Resource/Bitmap/BitmapImage.cpp": 3, "Source/Resource/Bitmap/BitmapImageJpeg.cpp": 3,