diff --git a/src/frame/AlphaGradient.cpp b/src/frame/AlphaGradient.cpp index e684de64..2226fabd 100644 --- a/src/frame/AlphaGradient.cpp +++ b/src/frame/AlphaGradient.cpp @@ -54,6 +54,7 @@ #include "Offsets.h" #include "frame/ClipChildren.h" #include "frame/Destruction.h" +#include "gx/Device.h" #include "texture/Load.h" #include @@ -63,10 +64,7 @@ namespace Frame::AlphaGradient { namespace { -using Matrix_t = void(__fastcall *)(float *m); using SetProjection_t = void(__fastcall *)(const float *m); -using GetViewport_t = void(__fastcall *)(float *minX, float *maxX, float *minY, float *maxY, float *minZ, - float *maxZ); using SetViewport_t = void(__stdcall *)(float minX, float maxX, float minY, float maxY, float minZ, float maxZ); using Convert_t = void(__fastcall *)(float *outX, float *outY, float x, float y); using GetRect_t = int(__fastcall *)(void *layout, void *edx, float *out); @@ -155,13 +153,12 @@ void RampColumn(const Stage &s, int axis, float vMin, float vMax, float col[4]) } void Load(const Stage &s) { - float p[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(p); - float minX, maxX, minY, maxY, minZ, maxZ; - reinterpret_cast(Offsets::FUN_GX_GET_VIEWPORT)(&minX, &maxX, &minY, &maxY, &minZ, &maxZ); + Gx::Matrix p; + Gx::GetProjection(p); + const Gx::Viewport vp = Gx::GetViewport(); float u[4], v[4]; - RampColumn(s, 0, minX, maxX, u); - RampColumn(s, 1, minY, maxY, v); + RampColumn(s, 0, vp.minX, vp.maxX, u); + RampColumn(s, 1, vp.minY, vp.maxY, v); float m[16]; for (int r = 0; r < 4; ++r) { const float *row = p + r * 4; diff --git a/src/frame/ClipChildren.cpp b/src/frame/ClipChildren.cpp index cf3c894c..04a62480 100644 --- a/src/frame/ClipChildren.cpp +++ b/src/frame/ClipChildren.cpp @@ -71,6 +71,7 @@ #include "frame/Destruction.h" #include "frame/LayerChange.h" #include "frame/ParentChange.h" +#include "gx/Device.h" #include "xml/FrameLoad.h" #include @@ -87,10 +88,6 @@ using Callback_t = void(__fastcall *)(void *arg); using AddCallback_t = void(__fastcall *)(void *batch, void *edx, Callback_t fn, void *arg); using SetFrameFlag_t = void(__fastcall *)(void *frame, void *edx, uint32_t mask, int on); using HitTest_t = int(__fastcall *)(void *frame, void *edx, const float *point); -using Matrix_t = void(__fastcall *)(float *m); -using GetViewport_t = void(__fastcall *)(float *minX, float *maxX, float *minY, float *maxY, float *minZ, - float *maxZ); -using SetViewport_t = void(__stdcall *)(float minX, float maxX, float minY, float maxY, float minZ, float maxZ); using SetupOrtho_t = void(__fastcall *)(const float *rect, const float *point, int unused); using Convert_t = void(__fastcall *)(float *outX, float *outY, float x, float y); @@ -218,18 +215,13 @@ bool ClipRect(const void *root, float rect[4]) { // The ScrollFrame's draw (0x00787220) with `rect` in place of its hit rect // and `draw(arg)` in place of its scroll child's. void DrawInside(float rect[4], Callback_t draw, void *arg) { - float projection[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - float view[16] = {1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1, 0, 0, 0, 0, 1}; - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(view); - float vpMinX, vpMaxX, vpMinY, vpMaxY, vpMinZ, vpMaxZ; - reinterpret_cast(Offsets::FUN_GX_GET_VIEWPORT)(&vpMinX, &vpMaxX, &vpMinY, &vpMaxY, &vpMinZ, - &vpMaxZ); + const Gx::SavedTransforms saved; + const Gx::Viewport &vp = saved.SavedViewport(); const auto toDdc = reinterpret_cast(Offsets::FUN_COORD_NDC_TO_DDC); float minX = 0, minY = 0, maxX = 0, maxY = 0; - toDdc(&minX, &minY, vpMinX, vpMinY); - toDdc(&maxX, &maxY, vpMaxX, vpMaxY); + toDdc(&minX, &minY, vp.minX, vp.minY); + toDdc(&maxX, &maxY, vp.maxX, vp.maxY); if (minX > rect[LEFT]) rect[LEFT] = minX; if (maxX < rect[RIGHT]) @@ -261,14 +253,9 @@ void DrawInside(float rect[4], Callback_t draw, void *arg) { rect[TOP] = 1.0f; } if (rect[LEFT] < rect[RIGHT] && rect[BOTTOM] < rect[TOP]) { - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)(rect[LEFT], rect[RIGHT], rect[BOTTOM], - rect[TOP], 0.0f, 1.0f); + Gx::SetViewport({rect[LEFT], rect[RIGHT], rect[BOTTOM], rect[TOP], 0.0f, 1.0f}); draw(arg); } - - reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_SET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)(vpMinX, vpMaxX, vpMinY, vpMaxY, vpMinZ, vpMaxZ); } void __fastcall DrawClipped(void *arg) { diff --git a/src/gx/Device.h b/src/gx/Device.h new file mode 100644 index 00000000..bb036851 --- /dev/null +++ b/src/gx/Device.h @@ -0,0 +1,82 @@ +// This file is part of ClassicAPI. +// +// ClassicAPI is free software: you can redistribute it and/or modify it under the terms +// of the GNU General Public License as published by the Free Software Foundation, either +// version 3 of the License, or (at your option) any later version. +// +// ClassicAPI is distributed in the hope that it will be useful, but WITHOUT ANY +// WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR +// PURPOSE. See the GNU General Public License for more details. +// +// You should have received a copy of the GNU General Public License along with +// ClassicAPI. If not, see . + +#pragma once + +// The graphics device's transforms: its projection and view matrices and its +// viewport (Offsets.h, at FUN_GX_GET_PROJECTION). The engine's own draws that +// leave the UI pass's transforms (SimpleModelDraw 0x0076D240, the ScrollFrame +// draw 0x00787220, the portrait bake) save all three first and restore them +// after; SavedTransforms does that for a scope. + +#include "Offsets.h" + +namespace Gx { + +using Matrix = float[16]; + +inline void GetProjection(Matrix &m) { + reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(m); +} +inline void SetProjection(const Matrix &m) { + reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(m); +} +inline void GetView(Matrix &m) { + reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(m); +} +inline void SetView(const Matrix &m) { + reinterpret_cast(Offsets::FUN_GX_SET_VIEW)(m); +} + +// In NDC, 0 to 1. +struct Viewport { + float minX, maxX, minY, maxY, minZ, maxZ; +}; + +inline Viewport GetViewport() { + using Fn = void(__fastcall *)(float *, float *, float *, float *, float *, float *); + Viewport v{}; + reinterpret_cast(Offsets::FUN_GX_GET_VIEWPORT)(&v.minX, &v.maxX, &v.minY, &v.maxY, &v.minZ, + &v.maxZ); + return v; +} +inline void SetViewport(const Viewport &v) { + using Fn = void(__stdcall *)(float, float, float, float, float, float); + reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)(v.minX, v.maxX, v.minY, v.maxY, v.minZ, + v.maxZ); +} + +// The projection, view and viewport, put back when the scope ends. +class SavedTransforms { + public: + SavedTransforms() : viewport_(GetViewport()) { + GetProjection(projection_); + GetView(view_); + } + ~SavedTransforms() { + SetProjection(projection_); + SetView(view_); + SetViewport(viewport_); + } + SavedTransforms(const SavedTransforms &) = delete; + SavedTransforms &operator=(const SavedTransforms &) = delete; + + const Viewport &SavedViewport() const { return viewport_; } + + private: + Matrix projection_; + Matrix view_; + Viewport viewport_; +}; + +} // namespace Gx diff --git a/src/model/Camera.cpp b/src/model/Camera.cpp index cf00afdb..37418824 100644 --- a/src/model/Camera.cpp +++ b/src/model/Camera.cpp @@ -96,6 +96,11 @@ void SetScalar(void *camera, uint32_t id, float value) { reinterpret_cast(Offsets::FUN_CAMERA_SET_SCALAR)(camera, id, value); } +void SetDeviceTransforms(void *camera, const float (&rect)[4]) { + using Fn = void(__fastcall *)(void *camera, const float *rect, uint32_t unused); + reinterpret_cast(Offsets::FUN_CAMERA_SET_DEVICE_TRANSFORMS)(camera, rect, 0); +} + namespace { // ConfigureCamera's own evaluation pass: facing 0, rebuild the root diff --git a/src/model/Camera.h b/src/model/Camera.h index 8ff516d1..6429a216 100644 --- a/src/model/Camera.h +++ b/src/model/Camera.h @@ -28,4 +28,9 @@ void SetVector(void *camera, uint32_t id, const Vec3 &v); float GetScalar(void *camera, uint32_t id); void SetScalar(void *camera, uint32_t id, float value); +// CameraSetDeviceTransforms (FUN_CAMERA_SET_DEVICE_TRANSFORMS): the device's +// projection and view from the camera, framed over `rect` {bottom, left, +// top, right}. +void SetDeviceTransforms(void *camera, const float (&rect)[4]); + } // namespace Model::Camera diff --git a/src/model/Portrait.cpp b/src/model/Portrait.cpp index 79ccefa0..128438f1 100644 --- a/src/model/Portrait.cpp +++ b/src/model/Portrait.cpp @@ -51,6 +51,7 @@ #include "Game.h" #include "Offsets.h" +#include "gx/Device.h" #include "model/Camera.h" #include "model/DisplayInfo.h" #include "model/M2.h" @@ -72,11 +73,6 @@ constexpr uint32_t kTexels = kSize * kSize; using CreateScene_t = void *(__cdecl *)(); using ReleaseScene_t = void(__thiscall *)(void *scene); using DrawScene_t = void(__thiscall *)(void *scene, uint32_t pass); -using SetTransforms_t = void(__fastcall *)(void *camera, const float *rect, uint32_t unused); -using GetMatrix_t = void(__fastcall *)(float *m); -using SetMatrix_t = void(__fastcall *)(const float *m); -using GetViewport_t = void(__fastcall *)(float *, float *, float *, float *, float *, float *); -using SetViewport_t = void(__stdcall *)(float, float, float, float, float, float); using ScreenSize_t = void(__fastcall *)(float *rect); using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY); using DeviceGate_t = int(__cdecl *)(); @@ -155,68 +151,58 @@ bool Bake(Portrait &p) { void *camera = Model::Camera::CameraById(copy, 0); M2::PlayAnimation(copy, -1, 0, 0, 0, 1.0f, 0, 1); - float projection[16]; - float view[16]; - float viewport[6]; - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_GET_VIEWPORT)( - &viewport[0], &viewport[1], &viewport[2], &viewport[3], &viewport[4], &viewport[5]); const bool fog = reinterpret_cast(Offsets::FUN_GX_MASTER_ENABLE_GET)( Offsets::GX_MASTER_FOG); auto setMaster = reinterpret_cast(Offsets::FUN_GX_MASTER_ENABLE_SET); setMaster(Offsets::GX_MASTER_FOG, 0); + { + const Gx::SavedTransforms saved; + const float aspect = static_cast((static_cast(x1) - x0) / + (static_cast(y1) - y0)); + auto toNdc = reinterpret_cast(Offsets::FUN_COORD_DDC_TO_NDC); + toNdc(&x0, &y0, x0, y0); + toNdc(&x1, &y1, x1, y1); - const float aspect = static_cast((static_cast(x1) - x0) / - (static_cast(y1) - y0)); - auto toNdc = reinterpret_cast(Offsets::FUN_COORD_DDC_TO_NDC); - toNdc(&x0, &y0, x0, y0); - toNdc(&x1, &y1, x1, y1); + // First collection: evaluate the portrait camera. + M2::IsLoaded(copy, 1, 1); + M2::SetAnimated(copy, true); + const float origin[3] = {0.0f, 0.0f, 0.0f}; + M2::AnimateScene(scene, origin); + const Model::Camera::Vec3 eye = Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_EYE); + Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_TARGET); // the bake reads it too + const float rect[4] = {0.0f, 0.0f, 1.0f, aspect}; + Model::Camera::SetDeviceTransforms(camera, rect); + Gx::SetViewport({x0, x1, y0, y1, 0.0f, 1.0f}); + reinterpret_cast(Offsets::FUN_GX_SET_CLEAR_COLOR)(0); + auto clear = reinterpret_cast(Offsets::FUN_GX_CLEAR); + clear(3); - // First collection: evaluate the portrait camera. - M2::IsLoaded(copy, 1, 1); - M2::SetAnimated(copy, true); - const float origin[3] = {0.0f, 0.0f, 0.0f}; - M2::AnimateScene(scene, origin); - const Model::Camera::Vec3 eye = Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_EYE); - Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_TARGET); // the bake reads it too - const float rect[4] = {0.0f, 0.0f, 1.0f, aspect}; - reinterpret_cast(Offsets::FUN_CAMERA_SET_DEVICE_TRANSFORMS)(camera, rect, 0); - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)(x0, x1, y0, y1, 0.0f, 1.0f); - reinterpret_cast(Offsets::FUN_GX_SET_CLEAR_COLOR)(0); - auto clear = reinterpret_cast(Offsets::FUN_GX_CLEAR); - clear(3); + // Second collection from the portrait eye, then both passes. + M2::IsReady(copy, 1, 1); + M2::SetAnimated(copy, true); + M2::SetVisible(copy, true); + M2::SetRenderCallback(copy, reinterpret_cast(Offsets::FUN_PORTRAIT_LIGHTING), + nullptr); + M2::AnimateScene(scene, &eye.x); + auto draw = reinterpret_cast(Offsets::FUN_M2SCENE_DRAW); + draw(scene, 0); + draw(scene, 1); - // Second collection from the portrait eye, then both passes. - M2::IsReady(copy, 1, 1); - M2::SetAnimated(copy, true); - M2::SetVisible(copy, true); - M2::SetRenderCallback(copy, reinterpret_cast(Offsets::FUN_PORTRAIT_LIGHTING), - nullptr); - M2::AnimateScene(scene, &eye.x); - auto draw = reinterpret_cast(Offsets::FUN_M2SCENE_DRAW); - draw(scene, 0); - draw(scene, 1); - - const int32_t box[4] = {0, 0, static_cast(kSize), static_cast(kSize)}; - TexelArray out{kTexels, kTexels, p.texels.data(), kTexels}; - reinterpret_cast( - Offsets::FUN_GX_READ_PIXELS)(box, &out); - clear(3); - const auto *mask = reinterpret_cast( - reinterpret_cast(Offsets::FUN_PORTRAIT_ALPHA_MASK)(kSize)); - if (out.data == p.texels.data()) { - for (uint32_t i = 0; i < kTexels; ++i) - p.texels[i] = (p.texels[i] & 0x00FFFFFFu) | static_cast(mask->alpha[i]) << 24; - void *gxTex = reinterpret_cast(Offsets::FUN_TEXTURE_GET_RENDERABLE)( - p.texture, 1, nullptr); - reinterpret_cast(Offsets::FUN_GX_TEX_MARK_RECT_DIRTY)(gxTex, box, 1); + const int32_t box[4] = {0, 0, static_cast(kSize), static_cast(kSize)}; + TexelArray out{kTexels, kTexels, p.texels.data(), kTexels}; + reinterpret_cast( + Offsets::FUN_GX_READ_PIXELS)(box, &out); + clear(3); + const auto *mask = reinterpret_cast( + reinterpret_cast(Offsets::FUN_PORTRAIT_ALPHA_MASK)(kSize)); + if (out.data == p.texels.data()) { + for (uint32_t i = 0; i < kTexels; ++i) + p.texels[i] = (p.texels[i] & 0x00FFFFFFu) | static_cast(mask->alpha[i]) << 24; + void *gxTex = reinterpret_cast(Offsets::FUN_TEXTURE_GET_RENDERABLE)( + p.texture, 1, nullptr); + reinterpret_cast(Offsets::FUN_GX_TEX_MARK_RECT_DIRTY)(gxTex, box, 1); + } } - - reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_SET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)( - viewport[0], viewport[1], viewport[2], viewport[3], viewport[4], viewport[5]); setMaster(Offsets::GX_MASTER_FOG, fog ? 1 : 0); M2::Release(copy); reinterpret_cast(Offsets::FUN_M2SCENE_RELEASE)(scene); diff --git a/src/model/Scene.cpp b/src/model/Scene.cpp index 655c0a5c..ec13cd71 100644 --- a/src/model/Scene.cpp +++ b/src/model/Scene.cpp @@ -101,6 +101,7 @@ #include "api/Documentation.h" #include "frame/LayerChange.h" #include "frame/Subclass.h" +#include "gx/Device.h" #include "model/Camera.h" #include "model/M2.h" #include "xml/FrameLoad.h" @@ -306,7 +307,6 @@ bool ViewRect(void *frame, const float rect[4], float view[4]) { // scaled and shifted in clip space, because the viewport stays the frame's // rect. Row-vector matrices: column 0 gives x', column 1 y', column 3 w'. void FitProjection(const float rect[4], const float view[4]) { - using Matrix_t = void(__fastcall *)(float *m); const float frameW = rect[3] - rect[1], frameH = rect[2] - rect[0]; if (!(frameW > 0.0f) || !(frameH > 0.0f)) return; @@ -314,22 +314,18 @@ void FitProjection(const float rect[4], const float view[4]) { const float sy = (view[2] - view[0]) / frameH; const float tx = ((view[1] + view[3]) - (rect[1] + rect[3])) / frameW; const float ty = ((view[0] + view[2]) - (rect[0] + rect[2])) / frameH; - float m[16]; - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(m); + Gx::Matrix m; + Gx::GetProjection(m); for (int row = 0; row < 4; ++row) { float *r = &m[row * 4]; r[0] = sx * r[0] + tx * r[3]; r[1] = sy * r[1] + ty * r[3]; } - reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(m); + Gx::SetProjection(m); } void __fastcall Paint(void *frame) { using GetRect_t = int(__thiscall *)(void *layout, float *rect); - using Matrix_t = void(__fastcall *)(float *m); - using GetViewport_t = void(__fastcall *)(float *, float *, float *, float *, float *, float *); - using SetViewport_t = void(__stdcall *)(float, float, float, float, float, float); - using SetTransforms_t = void(__fastcall *)(void *camera, const float *rect, uint32_t unused); using SetupOrtho_t = void(__fastcall *)(const float *rect, const float *point, int unused); using DdcToNdc_t = void(__fastcall *)(float *x, float *y, float inX, float inY); using Clear_t = void(__fastcall *)(uint32_t mask); @@ -340,13 +336,8 @@ void __fastcall Paint(void *frame) { if (!reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( Game::Ptr(frame, Offsets::OFF_FRAME_LAYOUT_SUBOBJECT), rect)) return; - float projection[16]; - float view[16]; - float vp[6]; // minX, maxX, minY, maxY, minZ, maxZ - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_GET_VIEWPORT)(&vp[0], &vp[1], &vp[2], &vp[3], - &vp[4], &vp[5]); + const Gx::SavedTransforms saved; + const Gx::Viewport &vp = saved.SavedViewport(); float eye[3] = {0.0f, 0.0f, 0.0f}; if (void *camera = CameraOf(frame)) { const Vec3 e = Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_EYE); @@ -355,10 +346,10 @@ void __fastcall Paint(void *frame) { eye[2] = e.z; float viewRect[4]; if (ViewRect(frame, rect, viewRect)) { - reinterpret_cast(Offsets::FUN_CAMERA_SET_DEVICE_TRANSFORMS)(camera, viewRect, 0); + Model::Camera::SetDeviceTransforms(camera, viewRect); FitProjection(rect, viewRect); } else { - reinterpret_cast(Offsets::FUN_CAMERA_SET_DEVICE_TRANSFORMS)(camera, rect, 0); + Model::Camera::SetDeviceTransforms(camera, rect); } } else { const float point[2] = {rect[1], rect[0]}; @@ -371,8 +362,8 @@ void __fastcall Paint(void *frame) { edge = ClampUnit(edge); const float epsilon = Game::Read(Offsets::VAR_HAS_RANGE_EPSILON); // 2^-22 if (!(std::fabs(rect[1] - rect[3]) < epsilon) && !(std::fabs(rect[0] - rect[2]) < epsilon)) { - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)( - rect[1] * vp[1], rect[3] * vp[1], rect[0] * vp[3], rect[2] * vp[3], 0.0f, 1.0f); + Gx::SetViewport({rect[1] * vp.maxX, rect[3] * vp.maxX, rect[0] * vp.maxY, rect[2] * vp.maxY, + 0.0f, 1.0f}); reinterpret_cast(Offsets::FUN_GX_CLEAR)(2); PlaceActors(frame); void *scene = Model::Pane::Scene(frame); @@ -381,10 +372,6 @@ void __fastcall Paint(void *frame) { draw(scene, 0); draw(scene, 1); } - reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_SET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_SET_VIEWPORT)(vp[0], vp[1], vp[2], vp[3], vp[4], - vp[5]); } // ---- projection (Project3DPointTo2D) --------------------------------------------- @@ -409,8 +396,6 @@ void __fastcall Paint(void *frame) { // 0 at the far); retail's callers all discard it. bool Project(void *frame, const Vec3 &point, double out[3]) { using GetRect_t = int(__thiscall *)(void *layout, float *rect); - using Matrix_t = void(__fastcall *)(float *m); - using SetTransforms_t = void(__fastcall *)(void *camera, const float *rect, uint32_t unused); void *camera = CameraOf(frame); float rect[4] = {}; // {bottom, left, top, right} @@ -418,14 +403,13 @@ bool Project(void *frame, const Vec3 &point, double out[3]) { !reinterpret_cast(Offsets::FUN_REGION_GET_RECT)( Game::Ptr(frame, Offsets::OFF_FRAME_LAYOUT_SUBOBJECT), rect)) return false; - float savedProjection[16], savedView[16], projection[16], view[16]; - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(savedProjection); - reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(savedView); - reinterpret_cast(Offsets::FUN_CAMERA_SET_DEVICE_TRANSFORMS)(camera, rect, 0); - reinterpret_cast(Offsets::FUN_GX_GET_PROJECTION)(projection); - reinterpret_cast(Offsets::FUN_GX_GET_VIEW)(view); - reinterpret_cast(Offsets::FUN_GX_SET_PROJECTION)(savedProjection); - reinterpret_cast(Offsets::FUN_GX_SET_VIEW)(savedView); + Gx::Matrix projection, view; + { + const Gx::SavedTransforms saved; + Model::Camera::SetDeviceTransforms(camera, rect); + Gx::GetProjection(projection); + Gx::GetView(view); + } const Vec3 eye = Model::Camera::GetVector(camera, Offsets::CAMERA_PROP_EYE); const double p[4] = {point.x - eye.x, point.y - eye.y, point.z - eye.z, 1.0};