function outputs two values, but i dont know how to use booth

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
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

function outputs two values, but i dont know how to use booth

Post by NoreoAlles »

Hello, im writing a clipping algorythm for my 3D renderer and in one scenario its supposed to see if a triangle is clipping, turn it into two which arent and then return those, but i can only ever see one of them, despite each working seperatly
if i do this on line 58 of triangle.lua:

Code: Select all

return {3, triangle_out, triangle_out2 }

this is the result:
example1.png
example1.png (11.47 KiB) Viewed 2560 times
if is switch them around:

Code: Select all

        return {3, triangle_out2, triangle_out }
This happens (you can see both images would fill each others missing triangles):
example2.png
example2.png (8.82 KiB) Viewed 2560 times
The code which receives the clipped triangles looks like this:

Code: Select all

clippedTris = {}
                local result = Triangle.clipAgainstPlane({x = 0, y = 0, z = 0.01}, {x = 0, y = 0, z = 1}, triViewed)
                if result[1] == 1 then table.insert(clippedTris, triViewed) end
                if result[1] == 2 then table.insert(clippedTris, result[2]) end
                if result[1] == 3 then clippedTris[#clippedTris+1] =  result[2] clippedTris[#clippedTris+1] =  result[3] end
.love is attached, standard fps controlls (r resets the camera, press that if upon loading up the screen is blank), changing the mesh for testing purposes is possible by changing the string in LoadMesh() function
Just to make it clear im using post this as my last resort, ive checked my code against the tutorial and github and even ports to other languages of the engine.
https://github.com/OneLoneCoder/Javidx9 ... 3.cpp#L310
Attachments
clipping.love
(10.63 MiB) Downloaded 123 times
RNavega
Party member
Posts: 385
Joined: Sun Aug 16, 2020 1:28 pm

Re: function outputs two values, but i dont know how to use booth

Post by RNavega »

I'm on my phone so I can't test it, but could you clarify if the problem you're observing is that some triangles are missing from the result, or if all are there but some have flipped normals and are simply being backface-culled?
In other words, if all clipped triangles are there in the data, but the renderer only draws some of them to the screen (the front-facing ones).
User avatar
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Re: function outputs two values, but i dont know how to use booth

Post by NoreoAlles »

RNavega wrote: Sat Jul 06, 2024 2:25 am I'm on my phone so I can't test it, but could you clarify if the problem you're observing is that some triangles are missing from the result, or if all are there but some have flipped normals and are simply being backface-culled?
In other words, if all clipped triangles are there in the data, but the renderer only draws some of them to the screen (the front-facing ones).
I´ve since started to rewrite everything as shader based, because i could not get this to work. I just checked, thats not issues for whatever reason, culling happens before clipping, so i dont know anymore. I did do a little check to see if the triangles are indeed there by checking for the shade of purple i gave them for testing purposes and they are indeed there but dont get rendered for whatever reason.
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
vilonis
Prole
Posts: 12
Joined: Sun Jan 14, 2024 10:52 pm

Re: function outputs two values, but i dont know how to use booth

Post by vilonis »

That’s weird, does it change anything if you use multiple return values instead of returning a table?
Post Reply

Who is online

Users browsing this forum: Bing [Bot] and 1 guest