Page 1 of 1
Issues when translating c to lua [Solved]
Posted: Sat Jun 29, 2024 5:15 pm
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
Re: Issues when translating c to lua
Posted: Sat Jun 29, 2024 5:48 pm
by marclurr
One line in your MultiplyMatrixVector function is wrong:
Change from this
to this
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
Re: Issues when translating c to lua
Posted: Sat Jun 29, 2024 5:56 pm
by NoreoAlles
Thank you so much, i already had an issue with that line of code, it was
, but i changed it to if not and thought that should of worked
Re: Issues when translating c to lua
Posted: Sat Jun 29, 2024 6:00 pm
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
, 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
Re: Issues when translating c to lua
Posted: Sat Jun 29, 2024 6:10 pm
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
, 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.