[SOLVED] Love2d raytracer weird output?

Questions about the LÖVE API, installing LÖVE and other support related questions go here.
Forum rules
Before you make a thread asking for help, read this.
Post Reply
User avatar
Joelrodiel
Prole
Posts: 27
Joined: Wed Apr 20, 2016 3:40 am

[SOLVED] Love2d raytracer weird output?

Post by Joelrodiel » Thu Jun 20, 2019 3:00 pm

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)
	c = dotVec3(oc, oc) - (s.radius*s.radius)
	
	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
(96 Bytes) Downloaded 60 times
main.lua
(2.13 KiB) Downloaded 62 times
Last edited by Joelrodiel on Mon Jun 24, 2019 3:36 pm, edited 1 time in total.

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

Re: Love2d raytracer weird output?

Post by pgimeno » 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.

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

Re: Love2d raytracer weird output?

Post by Joelrodiel » Mon Jun 24, 2019 3:36 pm

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!

Post Reply

Who is online

Users browsing this forum: No registered users and 8 guests