## [SOLVED] Love2d raytracer weird output?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

### [SOLVED] Love2d raytracer weird output?

Hi! I've been working on a Raytracer on love2d. It is by no means meant to be a very optimized renderer, more like a learning project. But I cannot, for the love of everything holy, get it working. I've successfully made them in C++ using .bmp output, but when I ported it to love2d, the output is not what it should be! Im fairly new to this too so I'm stumped.

Here is the code for the intersection of the ray & the sphere (which I suspect is the culprit to my dilemma):

Code: Select all

-- Function to check if ray hits sphere
-- @param r - Ray object
-- @param s - Sphere object
-- @return 0 for no hit, 1 for hit
function rayHitSphere(r, s)

oc = subVec3(r.origin, s.origin)

b = 2 * dotVec3(oc, r.direction)

disc = b*b - 4*c

if disc < 1e-4 then
return 0
end

return 1
end
And I've attached the full main.lua, and I suspect that if the intersection function isn't at fault, it might be something with the pixel rendering... Thanks in advance!
Attachments
conf.lua
main.lua
Last edited by Joelrodiel on Mon Jun 24, 2019 3:36 pm, edited 1 time in total.

pgimeno
Party member
Posts: 1687
Joined: Sun Oct 18, 2015 2:58 pm

### Re: Love2d raytracer weird output?

There's a typo in your dotVec3 function. The first term is v1.x*v2.y, should be v1.x*v2.x.

Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

### Re: Love2d raytracer weird output?

pgimeno wrote:
Mon Jun 24, 2019 12:00 am
There's a typo in your dotVec3 function. The first term is v1.x*v2.y, should be v1.x*v2.x.
Wow... I've been going crazy because of a typo, thank you so much!

### Who is online

Users browsing this forum: No registered users and 8 guests