Page 1 of 1

3D graphics: Linear Algebra in neslib.h

Posted: Fri Jun 04, 2021 11:40 am
by marius4560
Hi people! Nice to meet you all!

I want to program some 3D graphics on my NES. Is there any matrix operators or linear algebra functionality in neslib? Or do you know if anyone has already made a library for this?
Could I just use a seperate 3D specific C library together with neslib as long as I only use 8-bit datatypes?

I am new to neslib. I appreciate any help on this topic.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Fri Jun 04, 2021 11:46 am
by lidnariq
No, there's no preexisting linear algebra there. You'll have to implement it yourself, I fear.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Sat Jun 05, 2021 7:56 am
by marius4560
Could I import a linear algebra library and use functions from it? Or am I restricted to the functions in neslib if I want to compile for NES?

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Sat Jun 05, 2021 10:31 am
by calima
You can try to use any C library. They may or may not compile with cc65. What your real problem will be is having it fast enough.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Sat Jun 05, 2021 1:13 pm
by tokumaru
If you you're worried about the performance of 3D code on the NES at all, you'll probably have to write everything from scratch. If you do everything "by the book", using standard formulas, you can pretty much give up on any chance of getting a decent frame rate. To get anything remotely fluid on the NES you're gonna need look-up tables, approximations, interpolations, and whatever other tricks you can think of.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Sun Jun 06, 2021 4:30 am
by marius4560
I am not gonna worry about performance on my first try, I just want to try to implement it. I will probably want to look into raising performance afterwards though. I have to see much time I want to commit to this :)

I see the code for Elite is published on the web, with notes and comments. I think its written in assembly though, but it will probably teach me a thing or two.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Sun Jun 06, 2021 8:26 am
by Bananmos
marius4560 wrote:
Sun Jun 06, 2021 4:30 am
I am not gonna worry about performance on my first try, I just want to try to implement it. I will probably want to look into raising performance afterwards though. I have to see much time I want to commit to this :)

I see the code for Elite is published on the web, with notes and comments. I think its written in assembly though, but it will probably teach me a thing or two.
For as-close-as-can-be to a ready-made library, you might want to check out this very old article in C= Hacking:

http://www.ffd2.com/fridge/chacking/c=hacking18.txt

You'd probably have to rewrite parts of the code to work on NES, and figure out how to make it work with your C code. All part of the fun though ;)
IIRC correctly the articles (or those in previous editions) also cover a lot of the groundwork of efficient 3d math on the 6502, such as the trick of a table-of-squares for fast multiplications.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Mon Jun 07, 2021 12:48 am
by Controllerhead
marius4560 wrote:
Sun Jun 06, 2021 4:30 am
I see the code for Elite is published on the web, with notes and comments. I think its written in assembly though, but it will probably teach me a thing or two.
I've only seen the BBC Micro version published; the NES code would probably be very different. It's also PAL only as there is more time in vBlank.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Tue Jun 08, 2021 1:35 am
by marius4560

For as-close-as-can-be to a ready-made library, you might want to check out this very old article in C= Hacking:

http://www.ffd2.com/fridge/chacking/c=hacking18.txt

You'd probably have to rewrite parts of the code to work on NES, and figure out how to make it work with your C code. All part of the fun though ;)
IIRC correctly the articles (or those in previous editions) also cover a lot of the groundwork of efficient 3d math on the 6502, such as the trick of a table-of-squares for fast multiplications.
Oh that is perfect thanks!

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Tue Jun 08, 2021 1:36 am
by marius4560
I've only seen the BBC Micro version published; the NES code would probably be very different. It's also PAL only as there is more time in vBlank.
Yes but its the same proccessor, figured I might learn something from it :)

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Tue Jun 08, 2021 1:49 am
by Controllerhead
marius4560 wrote:
Tue Jun 08, 2021 1:36 am
Yes but its the same proccessor, figured I might learn something from it :)
I'm sure you absolutely can! Keep in mind though that retro console / computer code is very tied to the hardware it runs on; unlike modern code which is much more platform agnostic.

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Tue Jun 08, 2021 3:01 am
by marius4560
I'm sure you absolutely can! Keep in mind though that retro console / computer code is very tied to the hardware it runs on; unlike modern code which is much more platform agnostic.
Especially the graphics chip I suspect. Do you know anything about drawing lines from point to point instead of using sprites on the NES?

Re: 3D graphics: Linear Algebra in neslib.h

Posted: Tue Jun 08, 2021 6:57 am
by Oziphantom
the NES doesn't have a bitmap mode, so you have choose where you want a line, allocated tiles, plot the line in the tiles, and then put the tiles on the screen.
If a tile already exists at the position then you add the line to the existing tile.

The NES is really a bad machine to learn to do this on.