3D graphics: Linear Algebra in neslib.h

A place for your artistic side. Discuss techniques and tools for pixel art on the NES, GBC, or similar platforms.

Moderator: Moderators

Post Reply
marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

3D graphics: Linear Algebra in neslib.h

Post by marius4560 » Fri Jun 04, 2021 11:40 am

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.

lidnariq
Posts: 10656
Joined: Sun Apr 13, 2008 11:12 am
Location: Seattle

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

Post by lidnariq » Fri Jun 04, 2021 11:46 am

No, there's no preexisting linear algebra there. You'll have to implement it yourself, I fear.

marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

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

Post by marius4560 » Sat Jun 05, 2021 7:56 am

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?

calima
Posts: 1369
Joined: Tue Oct 06, 2015 10:16 am

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

Post by calima » Sat Jun 05, 2021 10:31 am

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.

User avatar
tokumaru
Posts: 12105
Joined: Sat Feb 12, 2005 9:43 pm
Location: Rio de Janeiro - Brazil

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

Post by tokumaru » Sat Jun 05, 2021 1:13 pm

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.

marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

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

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

Bananmos
Posts: 550
Joined: Wed Mar 09, 2005 9:08 am
Contact:

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

Post by Bananmos » Sun Jun 06, 2021 8:26 am

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.

User avatar
Controllerhead
Posts: 289
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

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

Post by Controllerhead » Mon Jun 07, 2021 12:48 am

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.
Image

marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

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

Post by marius4560 » Tue Jun 08, 2021 1:35 am


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!

marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

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

Post by marius4560 » Tue Jun 08, 2021 1:36 am

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 :)

User avatar
Controllerhead
Posts: 289
Joined: Tue Nov 13, 2018 4:58 am
Location: $4016
Contact:

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

Post by Controllerhead » Tue Jun 08, 2021 1:49 am

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.
Image

marius4560
Posts: 6
Joined: Fri Jun 04, 2021 11:30 am

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

Post by marius4560 » Tue Jun 08, 2021 3:01 am

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?

Oziphantom
Posts: 1162
Joined: Tue Feb 07, 2017 2:03 am

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

Post by Oziphantom » Tue Jun 08, 2021 6:57 am

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.

Post Reply