Skip to content

Conversation

@Mosch0512
Copy link
Contributor

added 3d camera
its not perfect i had to limit the pitch when camera is close to ground due to rendering issues i could not solve

closes #253

@gemini-code-assist
Copy link
Contributor

Summary of Changes

Hello @Mosch0512, 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 new 3D camera feature, enabling players to control their viewpoint with greater flexibility. The system allows for dynamic zooming, horizontal rotation, and vertical pitching around the character, enhancing the overall immersion and perspective. To support this new camera, several rendering components have been updated to correctly display terrain, effects, and pointers, ensuring visual consistency and functionality across different camera settings.

Highlights

  • New 3D Camera System: Introduces a comprehensive 3D camera with zoom, horizontal rotation, and vertical pitch controls.
  • Dynamic Camera Controls: Allows players to zoom in/out using the mouse wheel and rotate/pitch the camera using the middle mouse button. The camera can be toggled on/off with the F9 key.
  • Rendering Adjustments for 3D View: Implements dynamic adjustments to the rendering frustum, object visibility, and pointer scaling to ensure proper display across various zoom levels and angles.
  • Camera State Management: Saves and restores the original camera state to seamlessly switch between default and 3D camera modes.
  • Bug Fix: Corrects a minor input handling bug in Winmain.cpp where the middle mouse button release was incorrectly setting MouseRButton instead of MouseMButton.
  • Known Limitation: The camera's pitch is limited when close to the ground due to unresolved rendering issues.

🧠 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.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

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
Contributor

@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 introduces a new CCustomCamera3D system, enabling players to control camera zoom, horizontal rotation, and vertical pitch using the mouse wheel and middle mouse button, toggled by the F9 key. The new camera system dynamically adjusts rendering parameters such as frustum culling, object visibility range, pointer scaling, and terrain rendering bounds based on the camera's zoom level to prevent visual artifacts when zoomed out. It also includes a fix for an incorrect mouse button state in Winmain.cpp and ensures proper camera state restoration in ZzzOpenglUtil.cpp. Review comments suggest replacing while loops for angle normalization with fmodf, using a dedicated boolean flag instead of (0,0,0) to track the initial camera offset, removing an unused m_bF9KeyPressed member, and replacing several 'magic numbers' with named constants for improved readability and maintainability, along with removing a debug logging block.

@Mosch0512 Mosch0512 force-pushed the 3d-camera branch 2 times, most recently from 7fdf626 to 64344d5 Compare February 7, 2026 17:53
… module and replace legacy functions across the codebase. Remove redundant utility methods from `ZzzOpenglUtil`.
…ogic in `CameraUtility` with a modular and reusable design.
…luding `DefaultCamera`, `OrbitalCamera`, and editor-only `FreeFlyCamera`. Integrate mode switching via F9 key.
…ng modularity and enabling culling logic for `DefaultCamera` and `OrbitalCamera`.
…ining compatibility with legacy frustum logic.
…port; retain legacy frustum logic as fallback.
…amic culling; update frustum logic in `DefaultCamera` and `OrbitalCamera` to use `ViewFar`.
… `ICamera` and update rendering logic for compatibility.
…opped items, weather effects, item labels, and UI; refactored related logic for improved clarity and modularity.
…amera` and `Frustum` integration; update rendering functions for compatibility.
… scenarios in `DefaultCamera` and `OrbitalCamera`
…cing change checks to reduce unnecessary rebuilds; improve performance by ~20-25%. Adjust fallback logic and add support for tour mode camera positioning in `DefaultCamera`.
…r mode, validate tour position, and set default LoginScene camera values.
…itor far-plane override logic for improved frustum control.
…rbital camera offsets, default zoom, and fog pitch thresholds for improved depth, visibility, and character framing.
…alculations for dropped items to reflect camera movement.
…helper functions for clarity and reusability.
… with hardcoded 640×480 reference scaling for consistent UI rendering and game viewport calculations.
…config.ini` management. Add resolution-dependent camera updates and inventory slot refresh for 3D rendering.
…mensions` and `UpdateAllCameraDimensions` methods to streamline width and height adjustments for proper rendering. Ensure dimensions are updated during window resizing.
…onstants.h` for unified culling definitions. Replace hardcoded culling radii with constants across terrain, objects, characters, and items. Add debug visualization of culling spheres in DevEditor.
… tile loops based on camera position and view distance instead of iterating all 256x256 tiles
…nCamera()

Replaces the DefaultCamera-inherited stub with a full standalone ICamera
implementation that exactly replicates the original camera logic: position
calculation, angle setting, FOV, view distance, and custom camera distance.
Uses cheap distance-based culling instead of 3D frustum sphere tests.
Add Frustum::TestPoint2D() — a cheap 2D ground-plane projection test
using the convex hull of frustum vertices projected to XY. Computed once
per frame via Andrew's monotone chain, then tested with the same
cross-product winding algorithm as the original TestFrustrum2D.

Replace expensive 6-plane sphere tests (~100K/frame) with the cheap 2D
test for: TestFrustrum2D shim, ShouldCullTerrain in DefaultCamera and
OrbitalCamera.

Fix LegacyCamera: replace removed globals (CameraDistance,
CameraDistanceTarget, g_fCameraCustomDistance) with CameraState members
(m_State.Distance, m_State.DistanceTarget, m_State.CustomDistance).
TestFrustrum2D/TestFrustrum were calling CameraManager::Instance() +
virtual GetActiveCamera() + virtual GetFrustum() tens of thousands of
times per frame. Now cached once after camera update via
CacheActiveFrustum(), reducing each call to a single pointer deref.
…tum AABB, fix release build

- Disable fog for Legacy/other cameras to match main branch behavior
- Use frustum AABB for tight terrain iteration bounds instead of circle fallback
- Move cached frustum pointers before UpdateFrustrumBounds (scope fix)
- Guard MuEditorConsoleUI.h includes with #ifdef _EDITOR for non-editor builds
- Enable RenderDebugInfo in _EDITOR builds (not just _DEBUG)
- Restore CreateFrustrum2D/CreateFrustrum with FrustrumX/Y arrays
  from main branch, adapted for g_Camera.* globals
- Restore original TestFrustrum2D (4-vertex cross-product winding)
  and TestFrustrum (5-plane dot product) using file-static arrays
- Revert ZzzObject block/object/LoginScene culling to TestFrustrum2D
- Revert ZzzCharacter visibility to TestFrustrum2D
- Revert RenderTerrainFrustrum to TestFrustrum2D
- Remove unused ICamera* parameter passing from RenderGameWorld
- Simplify fog logic: replace strcmp with CameraMode enum check
- Simplify MoveMainCamera: remove UpdateFrustrumBounds call
OrbitalCamera's Frustum class already computes a correct 2D ground
projection, but the legacy rendering pipeline ignored it and used
hardcoded trapezoid tables that assume fixed pitch. This bridges the gap:

- Expand FrustrumX/Y arrays to [8] with FrustrumCount for convex hulls
- CreateFrustrum2D copies camera's 2D projection when Orbital is active
- TestFrustrum2D uses FrustrumCount instead of hardcoded 4
- Add Get2DCount/Get2DX/Get2DY public accessors to Frustum class
- Rename UpdateConfigForZoom to UpdateConfigForView (zoom-only scaling)
- Update fog to 80% start / 90% end of far plane for OrbitalCamera
Replace vertical FOV with horizontal FOV (hFov) throughout the camera
system. Vertical FOV is now derived at runtime via HFovToVFov() based
on current aspect ratio. This gives wider FOV on widescreen displays
while preserving the original ~30° vFOV on 4:3 for DefaultCamera.

- CameraConfig: fov→hFov, add HFovToVFov() utility
- OrbitalCamera: hFov=90° (~59° vFOV on 16:9), farPlane 7560→3800
- DefaultCamera/CharacterScene: hFov=40° (preserves original look)
- DevEditor: slider shows hFOV + computed vFOV, add objectCullRange
- FreeFlyCamera/LegacyCamera: same hFov→vFov conversion pattern
…and color coding

- Scale far-plane vertices by RENDER_DISTANCE_MULTIPLIER to match actual GL projection
- Add semi-transparent filled side planes for volume visibility from any angle
- Draw 2D convex hull ground projection on terrain with elevation-following subdivision
- Color-code wireframe: green (near), red (far), yellow (sides), cyan (camera)
…k-down crash

- Add yellow ground projection showing 10% buffer zone outside green frustum footprint
- Expand 2D culling hull by 10% from centroid so terrain renders within buffer zone
- Compute FreeFly iteration bounds from expanded hull instead of original AABB
- Fix degenerate cross product in OrbitalCamera when looking straight down at 90° elevation
- Add UpdateFrustum() to LegacyCamera so spectating shows proper frustum wireframe
- SetConfig() now triggers frustum rebuild in LegacyCamera
- Compute actual frustum apex (eye position) from near/far plane geometry
  instead of using near-plane center, fixing camera marker placement
- Add degenerate cross-product fix to DefaultCamera::UpdateFrustum()
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.

3D camera feature

1 participant