Add ray_intersection_point Usage Example#716
Add ray_intersection_point Usage Example#716ralphweng2023 wants to merge 1 commit intothoth-tech:mainfrom
Conversation
Integrated usage example demonstrating 2D dynamic lighting with ray casting. Functions demonstrated: - ray_intersection_point(): Core ray-to-line intersection detection - vector_from_angle(): Ray direction heading generation - draw_line(): Light ray visualization - fill_triangle(): Illuminated area rendering - draw_triangle(): Light boundary outlines The example simulates a lantern that follows the mouse, casting 360 light rays that interact with rectangular obstacles. Shadows are dynamically generated based on closest ray-to-edge intersections. Includes all 4 code versions (C++, C# top-level, C# OOP, Python) plus title file and GIF media.
❌ Deploy Preview for splashkit failed.
|
Peer ReviewI've reviewed the ray_intersection_point usage example. The lantern concept is creative and visually clear, and it demonstrates how the function can be used in a practical scenario. The light and shadow effect makes the example engaging and easy to understand when running. IssuesThe maximum ray distance is hardcoded as 1000.0. While this works, it could be improved by relating it to the window size for better scalability. Checks
Code Tests done
Website Tests done
|
222448082Ashen
left a comment
There was a problem hiding this comment.
Description
This PR adds a new usage example for ray_intersection_point by implementing a 2D dynamic lighting demo called The Raycast Lantern.
The lantern follows the mouse and casts 360 rays, with each ray tested against obstacle edges; the closest hit is used to render realistic light blocking and shadow-like behavior.
Related issue: N/A (new usage example contribution).
Motivation and context:
This provides a practical, visual, and beginner-friendly demonstration of ray_intersection_point in a real gameplay-style scenario.
Dependencies required:
None.
Type of change
- Bug fix (non-breaking change which fixes an issue)
- New feature (non-breaking change which adds functionality)
- Breaking change (fix or feature that would cause existing functionality to not work as expected)
- Documentation (update or new)
How Has This Been Tested?
I tested all four language versions locally and verified behavior matches across C++, C# (top-level), C# (OOP), and Python.
I also validated website build and preview to confirm the usage example content integrates correctly.
Repro steps:
- Run each language version and move the mouse to confirm lantern movement, ray casting, and obstacle blocking behavior.
- Run npm run build.
- Run npm run preview.
- Open the usage example page and verify rendering and assets in browser.
- Tested in latest Chrome
- Tested in latest Firefox
- npm run build
- npm run preview
Checklist
If involving code
- My code follows the style guidelines of this project
- I have performed a self-review of my own code
- I have commented my code in hard-to-understand areas
- I have made corresponding changes to the documentation
- My changes generate no new warnings
If modified config files
- I have checked the following files for changes:
- package.json
- astro.config.mjs
- netlify.toml
- docker-compose.yml
- custom.css
Folders and Files Added/Modified
Added:
- ray_intersection_point-1-example.txt
- ray_intersection_point-1-example.cpp
- ray_intersection_point-1-example-top-level.cs
- ray_intersection_point-1-example-oop.cs
- ray_intersection_point-1-example.py
- ray_intersection_point-1-example.gif
Modified:
- None
Additional Notes
All four implementations keep the same core logic and comments while following language-specific naming/style conventions.
Small future improvement idea: replace the fixed max ray distance with a value derived from window size for better scalability.
Overview
This usage example demonstrates
ray_intersection_pointby simulating a 2D dynamic lighting system — "The Raycast Lantern." A glowing lantern follows the mouse cursor and casts 360 light rays outward. Each ray is tested against rectangular obstacle edges usingray_intersection_point(), and the closest intersection determines where light is blocked. The illuminated area is rendered as filled triangles between adjacent ray endpoints, creating realistic dynamic shadows behind obstacles.SplashKit Functions:
ray_intersection_point,vector_from_angle,fill_triangle,draw_triangle,draw_line,draw_rectangle,fill_rectangle,fill_circle,point_point_distanceFiles Included
Usage Example Checks
!quit_requested()(nowhile(true)){on new line)snake_case, C# top-level usescamelCase, C# OOP usesNamespace/Class, Python usessnake_casedraw_line_point_to_point,fill_rectangle_record,refresh_screen_with_target_fps)