Issues when translating c to lua [Solved]

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

Issues when translating c to lua [Solved]

Post by NoreoAlles »

Hello everyone,
i´ve been trying to replicate/copy this 3D Engine by javid9x on Youtube, but ive been stuck on the part approx 35 Minutes in.The code on the github doesnt seem way more different to what im trying (except for not yet having rotation matrices). The Issue is that despite having copied exactly what he´s done, i cant get my cube from 0, 0, 0 and thus perspective.
Any Help appriciated :nyu:
Attachments
3D.love
(2.38 KiB) Downloaded 119 times
Last edited by NoreoAlles on Sat Jun 29, 2024 6:12 pm, edited 1 time in total.
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
User avatar
marclurr
Party member
Posts: 159
Joined: Fri Apr 22, 2022 9:25 am

Re: Issues when translating c to lua

Post by marclurr »

One line in your MultiplyMatrixVector function is wrong:

Change from this

Code: Select all

 if not  w == 0 then
to this

Code: Select all

 if w ~= 0 then
I actually ignored this originally because it seemed fine but the results on screen can only be explained by not dividing by w (or w being 1), so added some logging and lo it's not entering that conditional.

Edit: Actually there was one other change I made but I completely forgot I did it. You are translating the actual triangles every frame, I also changed translatedTri to be manually constructed rather than copying tris.

Code: Select all

        triTranslated.vectors[1] = Vector.new(tris.vectors[1].x, tris.vectors[1].y, tris.vectors[1].z)
        triTranslated.vectors[2] = Vector.new(tris.vectors[2].x, tris.vectors[2].y, tris.vectors[2].z)
        triTranslated.vectors[3] = Vector.new(tris.vectors[3].x, tris.vectors[3].y, tris.vectors[3].z)
 
instead of

Code: Select all

triTranslated = tris
User avatar
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Re: Issues when translating c to lua

Post by NoreoAlles »

Thank you so much, i already had an issue with that line of code, it was

Code: Select all

if ... then else do thing end
, but i changed it to if not and thought that should of worked
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
User avatar
marclurr
Party member
Posts: 159
Joined: Fri Apr 22, 2022 9:25 am

Re: Issues when translating c to lua

Post by marclurr »

NoreoAlles wrote: Sat Jun 29, 2024 5:56 pm Thank you so much, i already had an issue with that line of code, it was

Code: Select all

if ... then else do thing end
, but i changed it to if not and thought that should of worked
Just double checking you saw the edit too, both changes are required to get the correct result :)
User avatar
NoreoAlles
Party member
Posts: 130
Joined: Mon Jan 03, 2022 5:42 pm

Re: Issues when translating c to lua

Post by NoreoAlles »

marclurr wrote: Sat Jun 29, 2024 6:00 pm
NoreoAlles wrote: Sat Jun 29, 2024 5:56 pm Thank you so much, i already had an issue with that line of code, it was

Code: Select all

if ... then else do thing end
, but i changed it to if not and thought that should of worked
Just double checking you saw the edit too, both changes are required to get the correct result :)
Yes, thank you works all fine now, hope you havent seen my post where i replaced my code with yours but still messed up. Thanks again, im gonna turn this engine into a *so retro* star trek inspired space exploration game later down the line, which, judging by your profile pic might interest you. :awesome:
"Why do they call it oven when you of in the cold food of out hot eat the food?" - Jon Arbuckle
Post Reply

Who is online

Users browsing this forum: Bing [Bot], MisterImpossible and 3 guests