Skip to content

3d camera rework#29

Open
Mosch0512 wants to merge 23 commits intomainfrom
3d-camera-rework
Open

3d camera rework#29
Mosch0512 wants to merge 23 commits intomainfrom
3d-camera-rework

Conversation

@Mosch0512
Copy link
Copy Markdown
Owner

No description provided.

CameraState consolidates scattered camera globals (position, angle,
target, zoom) into a single g_Camera struct.

CameraProjection extracts projection math (WorldToScreen,
ScreenToWorld, BuildProjectionMatrix) from ZzzOpenglUtil into a
dedicated module.
CameraConfig defines per-scene presets (FOV, near/far, culling ranges)
and the global RENDER_DISTANCE_MULTIPLIER.

CameraMode enumerates camera types (Default, Orbital, Legacy, FreeFly)
with cycle logic.

ICamera provides the abstract interface all camera implementations
must satisfy (Update, Reset, GetFrustum, ShouldCull*).
Frustum implements 6-plane frustum extraction from the VP matrix with
a 2D ground-plane hull for terrain culling. Provides sphere, AABB,
and point containment tests.

FrustumRenderer adds editor-only wireframe visualization of the
frustum volume.

CullingConstants defines unified culling radii shared across the
rendering pipeline.
Wraps the original MoveMainCamera logic with scene-aware reset and
frustum caching. Serves as the primary camera mode for normal gameplay.
Middle-mouse drag for rotation, scroll wheel for zoom, and pitch
clamping. Provides an orbiting view around the player character.
Direct port of the original camera code with distance-squared culling.
Provides an unchanged reference implementation for comparing rendering
performance against the new camera system.
Arrow keys + PgUp/PgDn for movement, right-mouse for look direction.
Editor-only spectator camera for inspecting scenes from any angle.
Owns all camera implementations and manages mode switching via F9.
Handles auto-reset for non-MainScene contexts and provides the
spectated camera state to the rendering pipeline.
Replace scattered camera globals (CameraPosition, CameraAngle,
CameraFOV, CameraMatrix, etc.) with the unified g_Camera struct
across ~20 files. Migrate Projection() calls to
CameraProjection::WorldToScreen() and gluPerspective2() to
CameraProjection::SetupPerspective().

Refactor CameraUtility to a thin shim delegating to CameraManager.
Update ZzzOpenglUtil::BeginOpengl to use g_Camera and
CameraProjection.

Remove legacy camera globals from SceneCore.
ZzzLodTerrain: add 2D hull culling with CacheActiveFrustum,
TestFrustrum/2D shims, ResetFrustrumBoundsFullTerrain, and aspect
ratio correction for terrain block visibility.

ZzzObject: pass ICamera* to RenderObjects for frustum-based object
culling and item rotation with orbital yaw.

ZzzCharacter: add 3D frustum sphere test for character culling.
MainScene: add DevEditor render toggles, SceneManager clear color
with per-world entries for Lorencia and Devias.

LoginScene: migrate to g_Camera, fix tour mode, call
ResetFrustrumBoundsFullTerrain on scene entry.

CharacterScene: call CreateFrustrum after BeginOpengl, pass ICamera*
to render functions.

SceneManager: add SetWorldClearColor with per-world background colors.

CameraMove: add ApplyLoginSceneOffset and tour mode fixes.
Winmain: handle WM_SIZE to call ReinitializeFonts and
UpdateResolutionDependentSystems on window resize.

NewUI3DRenderMng: add UpdateDimensions and
UpdateAllCameraDimensions to propagate resolution changes to camera
viewports and 3D render panels.

NewUIMyInventory: make SetEquipmentSlotInfo public for resize updates.
DevEditorUI: full ImGui panel with camera state inspection, mode
switching, culling controls, and render toggle checkboxes.

MuEditorCore: hook DevEditor init and render into the editor
lifecycle.

MuInputBlockerCore: block mouse wheel when DevEditor panel is hovered.

MuEditorUI: add toolbar button to toggle DevEditor visibility.
Guard item label rendering in NewUINameWindow and weather effects
in ZzzEffectFireLeave with #ifdef _EDITOR conditional checks,
allowing the DevEditor panel to toggle these at runtime.
Enable fog globally across all scenes (login, character, loading,
main game) — GL_LINEAR fog is free on the GPU.

Fog distances: start at 100% of ViewFar, end at 125% of ViewFar.
This places fog transition just beyond the logical view distance
but within the projection far plane (ViewFar × 1.4).

CameraConfig: add fogStart/fogEnd fields with 100%/125% presets
for all scene configurations.

ZzzOpenglUtil: replace fixed FogDensity with dynamic percentage-based
GL_LINEAR fog that scales with g_Camera.ViewFar.

SceneManager: sync FogColor to match per-world glClearColor so fog
blends seamlessly into the background for each map.

DevEditorUI: add fog override checkbox, fog on/off toggle, and
fog start/end percentage sliders with real-time distance display.
Show ProjFar (actual projection far plane) alongside ViewFar.
Replace tight model OBB with scene-appropriate pick volumes:
- Character scene: generous cuboid anchored at feet, covers full
  character body for easy selection with the steep camera angle.
- In-game: original OBB extended by 65 units height, narrowed by
  5 units per side for tighter lateral selection.

Fix ScreenToWorldRay viewport mismatch: SetupPerspective now uses
actual viewport dimensions from SetViewport instead of full window
size, fixing the vertical ray offset in the character scene.

Add RenderDebugBox wireframe helper. DevEditor character culling
toggle now shows the actual pick cuboid per scene.

Remove unused character culling radius from DevEditor, CullingConstants,
and ZzzCharacter — character picking uses the OBB-based cuboid instead.
Set ViewFar before BeginOpengl so the projection matrix covers the
full render distance. Increase terrain multiplier from 330 to 1200
per distance level, raise object render cap from 2000 to 10000,
and increase terrain tile hard cap from 5200 to 20000.

Push near plane to 100 to preserve z-buffer precision with the
larger far plane. Update ForLoginScene config to match (20000).
Rename Camera tab to Scenes with collapsible sections:
- Login Scene: camera offsets, tour controls
- Character Scene: target character, custom origin
- Game Scene: camera config override, FOV, fog controls
- Debug: culling visualization, cull radii, render toggles

Move FreeFly toggle and camera info (mode, position, tile, pitch/yaw)
to always-visible top area. Restore disabled render toggles with
TODO labels.
…ettings

Add Terrain ViewFar and Object Distance sliders to the Login Scene
section of DevEditor for real-time tuning.

Isolate DevEditor settings by scene to prevent cross-scene interference:
- Game Scene settings (config override, FOV, fog) only apply in MAIN_SCENE
- Character Scene settings (custom origin, target character) only apply
  in CHARACTER_SCENE
- Login Scene settings already isolated by world/scene code paths
Delete LegacyCamera.cpp and LegacyCamera.h. Remove Legacy from
CameraMode enum, F9 cycling (now Default <-> Orbital), and
CameraManager instantiation. Clean up DevEditor switch-back logic.
Add [Camera] Zoom= setting to GameConfig. OrbitalCamera loads saved
zoom on construction and restores it on activation/scene reset.
Saves zoom on deactivation and scene transitions.

Call UpdateConfigForView() after loading zoom so ViewFar and fog
distances are correctly scaled from the first frame.
…icker

Remove terrain/object culling sphere visualization and terrain cull
radius — not used for actual culling decisions. Remove character scene
controls (custom origin, target character) — replaced with placeholder.

Add dropped item sphere visualization toggle. Rename item cull radius
to "Dropped Item Cull Radius" with negative value clamping.

Show scene sections only in their respective scene. Fix DefaultCamera
config override flicker caused by reading uninitialized local farPlane.

Remove DEFAULT_CULL_RADIUS_TERRAIN constant and DevEditor_GetCullRadiusTerrain
extern from DefaultCamera.h and OrbitalCamera.h.
@gemini-code-assist
Copy link
Copy Markdown

Summary of Changes

Hello, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

This pull request introduces a comprehensive rework of the 3D camera system. By centralizing camera state and implementing a modular camera manager, the codebase is now better equipped to handle different camera modes and configurations. The changes include a new DevEditor UI for live tuning, improved frustum culling, and better handling of window resolution changes, significantly modernizing the rendering pipeline.

Highlights

  • Camera System Rework: Replaced scattered global camera variables with a centralized CameraState structure and a new CameraManager system to handle multiple camera modes (Default, Orbital, FreeFly).
  • Dev Editor Integration: Added a new DevEditor UI for real-time camera configuration, including FOV, fog, and rendering toggles, along with resolution presets.
  • Frustum Culling Improvements: Implemented a unified Frustum class to replace the legacy dual-frustum system, improving culling accuracy and performance.
  • Resolution Handling: Improved window resizing support by updating OpenGL viewports and projection matrices dynamically via WM_SIZE and resolution-dependent system updates.

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for GitHub and other Google products, sign up here.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link
Copy Markdown

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

This pull request overhauls the camera system by introducing a centralized CameraManager and implementing Default, Orbital, and FreeFly camera modes. It also adds a DevEditorUI for real-time tuning and a unified frustum culling system. Key feedback includes addressing an incomplete implementation in DevEditor_GetCameraConfig, ensuring font and resolution-dependent systems are updated during window resizing in Winmain.cpp, and correcting copy-pasted documentation in CameraConfig.h.

Comment on lines +829 to +832
void DevEditor_GetCameraConfig(float* outHFOV, float* outNearPlane, float* outFarPlane, float* outTerrainCullRange)
{
if (outHFOV) *outHFOV = g_DevEditorUI.GetHFOV();
}
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The function DevEditor_GetCameraConfig has parameters for outNearPlane, outFarPlane, and outTerrainCullRange, but it only sets the outHFOV value. This is misleading and likely an incomplete implementation. If overriding these other camera properties is not intended, the function signature should be updated to remove the unused parameters.

void DevEditor_GetCameraConfig(float* outHFOV)
    {
        if (outHFOV) *outHFOV = g_DevEditorUI.GetHFOV();
    }

Comment on lines +568 to 587
case WM_SIZE:
if (wParam != SIZE_MINIMIZED)
{
// Update window dimensions
WindowWidth = LOWORD(lParam);
WindowHeight = HIWORD(lParam);

// Update screen rate factors
g_fScreenRate_x = (float)WindowWidth / 640.0f;
g_fScreenRate_y = (float)WindowHeight / 480.0f;

// Update OpenGL viewport dimensions
OpenglWindowWidth = WindowWidth;
OpenglWindowHeight = WindowHeight;

// Note: Projection matrix and frustum will be updated on next BeginOpengl() call
// No need to rebuild immediately - happens naturally in render loop
}
break;
case WM_PAINT:
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

high

The WM_SIZE message handler updates window dimension variables but doesn't call the new ReinitializeFonts() and UpdateResolutionDependentSystems() functions. This will cause rendering issues with fonts and UI elements when the window is resized. These functions were likely added to handle this exact scenario and should be called from within the WM_SIZE handler.

    case WM_SIZE:
        if (wParam != SIZE_MINIMIZED)
        {
            // Update window dimensions
            WindowWidth = LOWORD(lParam);
            WindowHeight = HIWORD(lParam);

            // Update screen rate factors
            g_fScreenRate_x = (float)WindowWidth / 640.0f;
            g_fScreenRate_y = (float)WindowHeight / 480.0f;

            // Update OpenGL viewport dimensions
            OpenglWindowWidth = WindowWidth;
            OpenglWindowHeight = WindowHeight;

            // Reinitialize fonts and update resolution-dependent systems
            ReinitializeFonts();
            UpdateResolutionDependentSystems();
        }
        break;

Comment on lines +138 to +148
* @brief MainScene default camera configuration
*
* Optimized configuration for MainScene OrbitalCamera.
* Balanced for performance and visibility.
*
* Values (user-specified):
* - FOV: 72 degrees
* - Near Plane: 10
* - Far Plane: 1700 (3D object culling)
* - Terrain Cull Range: 1700 (2D terrain culling)
*/
Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

The documentation for ForMainSceneOrbitalCamera appears to be a copy-paste from ForMainSceneDefaultCamera. The @brief line and the values in the comment should be updated to reflect that this configuration is for the orbital camera.

Suggested change
* @brief MainScene default camera configuration
*
* Optimized configuration for MainScene OrbitalCamera.
* Balanced for performance and visibility.
*
* Values (user-specified):
* - FOV: 72 degrees
* - Near Plane: 10
* - Far Plane: 1700 (3D object culling)
* - Terrain Cull Range: 1700 (2D terrain culling)
*/
* @brief MainScene orbital camera configuration
*
* Optimized configuration for MainScene OrbitalCamera.
* Balanced for performance and visibility.
*
* Values (user-specified):
* - FOV: 90 degrees
* - Near Plane: 500
* - Far Plane: 3800 (3D object culling)
* - Terrain Cull Range: 5320 (2D terrain culling)

Simplify DevEditor_GetCameraConfig to DevEditor_GetCameraConfigFOV —
remove unused outNearPlane/outFarPlane/outTerrainCullRange parameters
that were never written, causing uninitialized reads in DefaultCamera.

Add ReinitializeFonts() and UpdateResolutionDependentSystems() calls
to WM_SIZE handler so fonts and UI update correctly on window resize.

Fix AdjustWindowRect using WS_OVERLAPPEDWINDOW (includes WS_THICKFRAME)
instead of the actual window style, causing 10px oversized client area
and black borders on subsequent resolution changes.

Fix copy-paste in ForMainSceneOrbitalCamera doc comment to reflect
actual orbital camera values (90 FOV, 500 near, 3800 far).
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant