Skip to content

Add ray_intersection_point Usage Example#716

Open
ralphweng2023 wants to merge 1 commit intothoth-tech:mainfrom
ralphweng2023:raycast-lantern-usage-example
Open

Add ray_intersection_point Usage Example#716
ralphweng2023 wants to merge 1 commit intothoth-tech:mainfrom
ralphweng2023:raycast-lantern-usage-example

Conversation

@ralphweng2023
Copy link
Copy Markdown

Overview

This usage example demonstrates ray_intersection_point by 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 using ray_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_distance

Files Included

  • Title and explanation (.txt)
  • C++ code (SplashKit)
  • C# code (Top-Level statements)
  • C# code (Object-Oriented Programming)
  • Python code
  • Screenshot/GIF

Usage Example Checks

  • Simple, clear demonstration of the function
  • Code uses SplashKit functions
  • Uses !quit_requested() (no while(true))
  • Allman-style braces (opening { on new line)
  • Identical logic and comments across all 4 code versions
  • C++ uses snake_case, C# top-level uses camelCase, C# OOP uses Namespace/Class, Python uses snake_case
  • Title file contains creative name without the word "Example"
  • Python function names verified against API docs (e.g., draw_line_point_to_point, fill_rectangle_record, refresh_screen_with_target_fps)
  • Tested in Chrome and Firefox

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.
@netlify
Copy link
Copy Markdown

netlify bot commented Mar 31, 2026

Deploy Preview for splashkit failed.

Name Link
🔨 Latest commit d6b553f
🔍 Latest deploy log https://app.netlify.com/projects/splashkit/deploys/69cbc734cdf7690008c9ae41

@jasveena15
Copy link
Copy Markdown

Peer Review

I'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.

Issues

The 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.
The obstacle edge definitions are slightly repetitive across the code. This does not affect functionality, but simplifying this (e.g., using a helper approach) could improve readability.
Minor comment wording could be made consistent across languages (e.g., referring to ray_intersection_point vs RayIntersectionPoint).

Checks

  • All required files are present.
  • Example Title (.txt)
  • C++ code
  • C# code (top-level statements)
  • C# code (Object-Oriented Programming)
  • Python code
  • Code correctly uses SplashKit functions.
  • Code clearly demonstrates the function.
  • All versions maintain the same structure and comments.

Code Tests done

  • C++ code ran correctly.
  • C# top level code ran correctly.
  • C# OOP code ran correctly.
  • Python code ran correctly.

Website Tests done

  • npm run build
  • npm run preview

Copy link
Copy Markdown

@222448082Ashen 222448082Ashen left a comment

Choose a reason for hiding this comment

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

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:

  1. Run each language version and move the mouse to confirm lantern movement, ray casting, and obstacle blocking behavior.
  2. Run npm run build.
  3. Run npm run preview.
  4. 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.

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.

4 participants