-
Notifications
You must be signed in to change notification settings - Fork 0
fix this stuff #18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
fix this stuff #18
Conversation
WalkthroughThe recent changes introduce new functionalities to the mathematical operations and camera handling within the system. A new perspective projection function is added, enhancing matrix calculations. The camera's internal logic has been refactored for improved clarity and efficiency, integrating the new projection method. Additionally, the frustum visibility logic has been modularized for better maintainability, while UI navigation has been optimized to manage performance during menu evaluations. Changes
Sequence Diagram(s)sequenceDiagram
participant Camera
participant Matrix
participant Frustum
Camera->>Matrix: Request perspective projection matrix
Matrix->>Camera: Return perspectiveProjectionCamera matrix
Camera->>Frustum: Update visibility with camera matrix
Frustum->>Camera: Return visibility results
Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media? TipsChatThere are 3 ways to chat with CodeRabbit:
Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments. CodeRabbit Commands (invoked as PR comments)
Additionally, you can add CodeRabbit Configuration File (
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 2
Review details
Configuration used: CodeRabbit UI
Review profile: CHILL
Files selected for processing (4)
- src/foundations/math/matrix.zig (1 hunks)
- src/foundations/physics/camera.zig (4 hunks)
- src/foundations/scenes/frustum_planes/FrustumPlanes.zig (6 hunks)
- src/foundations/ui/ui_navigation.zig (1 hunks)
Additional comments not posted (5)
src/foundations/ui/ui_navigation.zig (1)
35-35: Approved change to evaluation branch quota.The addition of
@setEvalBranchQuota(2_000);is a sensible change given the context of the PR. It's important to monitor its impact on performance.Consider profiling the performance before and after this change to ensure it does not negatively affect the user experience.
src/foundations/scenes/frustum_planes/FrustumPlanes.zig (2)
56-56: Approved modification to camera input handling.Changing
input_inactivefromtruetofalselikely enables more dynamic interaction capabilities. Ensure this change aligns with the intended user interaction model.
105-117: Approved addition ofpointVisiblefunction.This new function enhances code modularity by centralizing visibility checks. It's a clean and efficient implementation.
src/foundations/physics/camera.zig (1)
30-31: Approved enhancements to perspective calculations.Adding
perspective_gandperspective_simproves the precision of perspective transformations. Good job on enhancing clarity and functionality.Also applies to: 84-85
src/foundations/math/matrix.zig (1)
91-103: Review of the new functionperspectiveProjectionCamera.The function
perspectiveProjectionCamerais well-implemented and follows the existing coding style and formatting conventions of the file. It calculates a perspective projection matrix, which is crucial for 3D rendering processes. The function utilizes the parametersg,s,n, andfeffectively to compute the matrix values.Performance Consideration:
The function is marked asinline, which is appropriate given that it is likely to be called frequently within performance-critical rendering loops. This allows the compiler to optimize the function calls by potentially embedding the function's body directly into the calling code, reducing function call overhead.Correctness & Consistency:
The mathematical operations within the function appear correct based on the typical formulas used for perspective projections in computer graphics. The use of constants and operations aligns with the existing functions in the file, maintaining consistency.Documentation & Readability:
The function could benefit from additional comments explaining the purpose and usage of each parameter, especially for users who might not be familiar with perspective projection calculations. This would enhance the readability and maintainability of the code.Suggestion:
Consider adding detailed comments describing the parameters and the mathematical basis of the calculations. This would not only aid in maintenance but also help new developers understand the code more quickly.Overall, the implementation of the
perspectiveProjectionCamerafunction is robust and aligns with the module's functionality.
| const cm = cam.camera_matrix; | ||
|
|
||
| const left = math.vector.normalize(math.matrix.transformVector( | ||
| self.view_camera_0.cam_m, | ||
| pl, | ||
| )); | ||
| const nl: math.vector.vec3 = .{ left[0], left[1], left[2] }; | ||
| const left_plane = math.geometry.Plane.init(nl, left[3]); | ||
| const nl: math.vector.vec3 = math.vector.add( | ||
| math.vector.mul(cam.perspective_s, math.vector.vec4ToVec3(cm.columns[1])), | ||
| math.vector.mul(cam.perspective_g, math.vector.vec4ToVec3(cm.columns[2])), | ||
| ); | ||
| const dl = math.vector.dotProduct(nl, math.vector.vec4ToVec3(cm.columns[3])); | ||
| const left_plane = math.geometry.Plane.init(nl, dl); | ||
|
|
||
| const pt = math.vector.add(p.columns[3], p.columns[1]); | ||
| const top = math.vector.normalize(math.matrix.transformVector( | ||
| math.matrix.transformMatrix(self.view_camera_0.cam_m, math.matrix.rotationX(-std.math.pi / 3.5)), | ||
| pt, | ||
| )); | ||
| const nt: math.vector.vec3 = .{ top[0], top[1], top[2] }; | ||
| const top_plane = math.geometry.Plane.init(nt, top[3]); | ||
| const nr: math.vector.vec3 = math.vector.add( | ||
| math.vector.mul(cam.perspective_s, math.vector.vec4ToVec3(cm.columns[1])), | ||
| math.vector.mul(-cam.perspective_g, math.vector.vec4ToVec3(cm.columns[2])), | ||
| ); | ||
| const dr = math.vector.dotProduct(nr, math.vector.vec4ToVec3(cm.columns[3])); | ||
| const right_plane = math.geometry.Plane.init(nr, dr); | ||
|
|
||
| const pb = math.vector.sub(p.columns[3], p.columns[1]); | ||
| const bot = math.vector.normalize(math.matrix.transformVector( | ||
| math.matrix.transformMatrix(self.view_camera_0.cam_m, math.matrix.rotationX(std.math.pi / 3.5)), | ||
| pb, | ||
| )); | ||
| const nb: math.vector.vec3 = .{ bot[0], bot[1], bot[2] }; | ||
| const bot_plane = math.geometry.Plane.init(nb, bot[3]); | ||
| const nb: math.vector.vec3 = math.vector.add( | ||
| math.vector.mul(-cam.perspective_g, math.vector.vec4ToVec3(cm.columns[0])), | ||
| math.vector.vec4ToVec3(cm.columns[1]), | ||
| ); | ||
| const db = math.vector.dotProduct(nb, math.vector.vec4ToVec3(cm.columns[3])); | ||
| const bot_plane = math.geometry.Plane.init(nb, db); | ||
|
|
||
| const nt: math.vector.vec3 = math.vector.add( | ||
| math.vector.mul(cam.perspective_g, math.vector.vec4ToVec3(cm.columns[0])), | ||
| math.vector.vec4ToVec3(cm.columns[1]), | ||
| ); | ||
| const dt = math.vector.dotProduct(nt, math.vector.vec4ToVec3(cm.columns[3])); | ||
| const top_plane = math.geometry.Plane.init(nt, dt); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor suggestion for frustum plane calculations.
The new method of calculating frustum planes using camera matrix components directly is an improvement. However, consider abstracting these calculations into a separate function to enhance readability and reusability.
| const g: f32 = 1.0 / @tan(cfg.fovy * 0.5); | ||
| const P = math.matrix.perspectiveProjectionCamera(g, s, 0.01, 750); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Refactor suggestion for perspective projection calculation.
The new method using perspectiveProjectionCamera is a significant improvement. Consider adding detailed comments explaining the parameters g and s for future maintainability.
@setEvalBranchQuota(2_000);is due to a zig language breaking change ziglang/zig#21135Summary by CodeRabbit
New Features
Improvements
Bug Fixes
Performance Optimizations