Small Ray Tracing (or RayCasting)

Show off your games, demos and other (playable) creations.
Post Reply
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Small Ray Tracing (or RayCasting)

Post by darkfrei »

Hi all!

I've made small tool: it checks where is the first nearest point on the line (https://love2d.org/wiki/love.graphics.line) from given ray source.
Attachments
2020-11-22T18_10_24-RayTracing v.1-01 (Löve v.11.3).png
2020-11-22T18_10_24-RayTracing v.1-01 (Löve v.11.3).png (62.08 KiB) Viewed 13702 times
RayTracing_1-01.love
(2.59 KiB) Downloaded 395 times
Last edited by darkfrei on Tue May 18, 2021 3:14 pm, edited 2 times in total.
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Small ray tracing

Post by darkfrei »

My implementation ray tracing as a lib;

Please help me to fix it, I'm bad with objects. If possible, without metatables, I cannot understand them.
Attachments
Animation (7).gif
Animation (7).gif (3.5 MiB) Viewed 13618 times
2020-11-25T21_33_01-RayTracing v.1-03 (Löve v.11.3).png
2020-11-25T21_33_01-RayTracing v.1-03 (Löve v.11.3).png (79.18 KiB) Viewed 13618 times
RayTracing_1-03.love
(3.41 KiB) Downloaded 365 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
noahnadai
Prole
Posts: 15
Joined: Sat Jun 27, 2020 10:43 am

Re: Small ray tracing

Post by noahnadai »

Where were you three months ago when my game needed you? Good work!
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Small ray tracing

Post by darkfrei »

noahnadai wrote: Wed Dec 02, 2020 2:51 pm Where were you three months ago when my game needed you? Good work!
I need that tool for my project too, that's why I wrote that.

Where are you need it?
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
noahnadai
Prole
Posts: 15
Joined: Sat Jun 27, 2020 10:43 am

Re: Small ray tracing

Post by noahnadai »

darkfrei wrote: Wed Dec 02, 2020 10:40 pm
noahnadai wrote: Wed Dec 02, 2020 2:51 pm Where were you three months ago when my game needed you? Good work!
I need that tool for my project too, that's why I wrote that.

Where are you need it?
This game I recently finished. Had to manually assign co-ordinates for each laser and it's respective collision point.
https://mwasanje.itch.io/the-squarehouse
Attachments
The Squarehouse.love
(268.38 KiB) Downloaded 362 times
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Small ray tracing

Post by darkfrei »

Attachments
RayTracing_1-04.love
(2.63 KiB) Downloaded 338 times
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
lucked
Prole
Posts: 8
Joined: Fri Nov 13, 2020 10:27 am

Re: Small ray tracing

Post by lucked »

Well done!
User avatar
togFox
Party member
Posts: 770
Joined: Sat Jan 30, 2021 9:46 am
Location: Brisbane, Oztralia

Re: Small Ray Tracing (or RayCasting)

Post by togFox »

Trying to adapt rays.lua into my own project. The example here has two lines - line1 and line2 as two distinct lines. I have about 50 lines (all about 50 pixels short) so would like to adapt to call a table of lines ... I guess.

I have a line defined, not surprisingly, as x1,y1,x2,y2. So, I guess I might have:

line[1] = x1,y1,x2,y2
line[2] = x1,y1,x2,y2 -- different values for x1,y1,x2,y2
line[3] = x1,y1,x2,y2 -- different values for x1,y1,x2,y2
line[4] = x1,y1,x2,y2 -- different values for x1,y1,x2,y2

They are not continuous like in the example in this thread. They all have exactly two xy pairs - but - I have an undefined number of lines. How to adjust rays.lua?
Current project:
https://togfox.itch.io/backyard-gridiron-manager
American football manager/sim game - build and manage a roster and win season after season
User avatar
darkfrei
Party member
Posts: 1169
Joined: Sat Feb 08, 2020 11:09 pm

Re: Small Ray Tracing (or RayCasting)

Post by darkfrei »

togFox wrote: Mon Feb 21, 2022 10:45 am

Code: Select all

line[1] = x1,y1,x2,y2
Maybe table required?

Code: Select all

line[1] = {x1,y1,x2,y2}
:awesome: in Lua we Löve
:awesome: Platformer Guide
:awesome: freebies
Post Reply

Who is online

Users browsing this forum: No registered users and 42 guests