nesdev.com
http://forums.nesdev.com/

Matrix multiplication / 3D demo
http://forums.nesdev.com/viewtopic.php?f=2&t=132
Page 1 of 1

Author:  abonetochew [ Sun Jan 02, 2005 8:06 pm ]
Post subject:  Matrix multiplication / 3D demo

I haven't had anything else to do for the last three days, so I put together a little 3D demo for the NES. The methods I used are far from optimal, but the code seems to be stable and runs correctly on every emulator I've tested.

Features include:
- 1-8 moving objects, selectable
- 1-3 axes of rotation, selectable
- hex display of rotation matrix
- frame rate counter

Framerate ranges from 6 to 60 FPS, depending on how many objects and how many matrices are in use. I do plan to rewrite this sometime in the future to use a faster multiplication algorithm, and faster 3D transformations. (I really need to get into GBA assembly...)

The ROM is available on my temporary website. (my main website is currently being redesigned)

Would anyone with an NROM devcart be willing to test this on hardware?

Author:  doynax [ Sun Jan 02, 2005 8:49 pm ]
Post subject:  Re: Matrix multiplication / 3D demo

Nice work, I'm impressed! There's nothing quite like watching hex dumps in a tech-demo =)

The depressing thing is that there's some insane C64 demos out there than beat the crap out of anything we mere mortals could ever write. Dawnfall somehow manages to rotate 250 points in full framerate on a machine half as fast..

Author:  Memblers [ Mon Jan 03, 2005 6:45 am ]
Post subject: 

Awesome! I wanted to write something like this a while back, but I suck too much at math. I tried, but only ended up with some neat sinewave-based 2D patterns, heheh.

I'll test this on my cart later and let you know how it went. I might be able to make it run faster, it could be a good test for Squeedo's hardware multiplier feature.

Author:  Memblers [ Mon Jan 03, 2005 11:20 am ]
Post subject: 

It works. I'll try something to speed it up a little.

Author:  abonetochew [ Mon Jan 03, 2005 3:43 pm ]
Post subject: 

Yay! I've written a NES demo that actually works on hardware! Happiness! Glee!
... Now that I'm done with that, where might I be able to find some of these C64 demos? I need to study the techniques of the immortal coders...

Author:  Memblers [ Mon Jan 03, 2005 3:54 pm ]
Post subject: 

There were some really good 3D articles in a few C=Hacking issues also (I forgot which ones, there's an index tho).
http://www.ffd2.com/fridge/chacking/

Author:  doynax [ Mon Jan 03, 2005 4:49 pm ]
Post subject: 

abonetochew wrote:
Yay! I've written a NES demo that actually works on hardware! Happiness! Glee!
... Now that I'm done with that, where might I be able to find some of these C64 demos? I need to study the techniques of the immortal coders...

Try watching through the top demos at http://noname.c64.org/csdb.
Seeing Deus Ex Machina for the first time is something of a revelation, I just didn't want to believe it was possible until I saw it on hardware.
Oh, and I meant One-Der, not Dawnfall (both are 64 kB intros by Oxyron).

Author:  thefox [ Tue Jan 04, 2005 11:07 am ]
Post subject: 

An ok demo, tho I think much more could be taken out of NES 3D-wise :)

It's not worth comparing NES with C64... they're pretty different. NES was designed to be easy to write games with, whereas C64 (as it seems to me) is much more versatile. There's also much more information for C64 available and also many more developers developing for C64.

Author:  RoboNes [ Wed Jan 05, 2005 7:09 am ]
Post subject: 

and ever important the c64 has MUCH more ram available

Author:  abonetochew [ Wed Jan 05, 2005 6:25 pm ]
Post subject: 

I rewrote my multiplier subroutine, and the demo now runs at 15 FPS at XYZ/8.

old routine:
sign-extend mul_a and mul_b from 16 to 32 bits
loop through the 32-bit add-and-shift loop 32 times

new routine:
don't sign-extend
if mul_a is negative, negate it and toggle neg_flag
if mul_b is negative, negate it and toggle neg_flag
loop through the hybrid 16/32 bit add-and-shift loop 16 times
if neg_flag is set, negate mul_c

I still think there has got to be a better way to multiply 8.8 fixed point numbers (without using any cartridge hardware), but I'm not going to figure it out any time soon. I'm also going to restructure the 3D "pipeline" to avoid those nasty 27-multiply matrix operations. This would be a lot easier if I had sources for some of those C64 demos to leech off of. :)

Author:  doynax [ Wed Jan 05, 2005 6:49 pm ]
Post subject: 

abonetochew wrote:
I still think there has got to be a better way to multiply 8.8 fixed point numbers (without using any cartridge hardware), but I'm not going to figure it out any time soon. I'm also going to restructure the 3D "pipeline" to avoid those nasty 27-multiply matrix operations. This would be a lot easier if I had sources for some of those C64 demos to leech off of. :)

How about combining a couple of these (http://www.ffd2.com/fridge/math/fastmult) 8-bit multiplies?
Do you really need 16-bit precision at all? The vertices really shoudn't need them and a rotation matrix should only contain fractional values (almost anyway).

There's a proud tradition in the C64 scene of disassembling the works of the masters instead of giving out source codes.
Otherwise there's an explanation of the plotter from One-Der somewhere on the CSDB forum, I'll do a quick scan over the topics list and see if I can find it for you. I don't think it actually did any multiplies at all (per vertex anyway) but had everything precalculated instead.

edit: I managed to find the relevant thread (http://noname.c64.org/csdb/forums/?roomid=11&topicid=13369#13381).
Apparently everything is based on LUTs, there's no perspective at all, it's uses a bunch of speedcode, there's no pixel masking, and the display mode is hacked togheter with raster interrupts. Neat =)

Page 1 of 1 All times are UTC - 7 hours
Powered by phpBB® Forum Software © phpBB Group
http://www.phpbb.com/