09 September 2009, 08:34 | #121 | |||
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
Quote:
Quote:
|
|||
26 September 2009, 23:43 | #122 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
Now, admit it - you're not surprised. I've rewritten both the build matrix and rotate points routines to use the minimum of swaps and rols with the result that the accuracy has now improved enough for the cube to be nicely smooth. I just *had* to get it smooth before it got released in the megademo. Anyways, check the attached source to see... Last edited by pmc; 26 February 2010 at 12:23. |
|
21 October 2009, 21:40 | #123 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Hello guys
My hidden lines routine has now been adapted into a demo part for the megademo. \o/ It can handle multiple objects - not just a cube now - and transitions between them. Along with the other stuff that's going on in the part I've managed to get this routine up to rotating 48 points in one frame so I'm pretty pleased that it hasn't been so bad an effort after all. After the megademo has been released I'll post the source code of the hidden line part here so anyone who's interested can check it out. Last edited by pmc; 29 October 2009 at 00:16. Reason: Typo... |
28 October 2009, 11:28 | #124 |
TDI
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
|
Brilliant, can't wait to see it
|
05 January 2010, 17:58 | #125 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Watcha boys.
There was a subtle error (so subtle in fact that I still can't find exactly what it is! ) in the previous blitter line draw code I posted in this thread. It was causing a problem with just one of my objects in my vectors part for the megademo. The object looked perfect when running on WinUAE - the bug could only be noticed on real Amiga hardware. Very strange. Anyways, I've now rewritten the line draw routine to be neater, take less memory (no octant tab + some other savings) and (hopefully) faster too. This new version is bug free as far as I can tell on both WinUAE and real Amigas. Enjoy. EDIT: According to my testing, this rewrite shaves about a rasterline per line drawn off the execution time of the previously posted bugged version. Last edited by pmc; 26 February 2010 at 12:23. |
05 January 2010, 23:45 | #126 |
TDI
Join Date: Feb 2007
Location: Blitter Town
Posts: 124
|
Thanks man
|
06 January 2010, 09:21 | #127 |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Makes me smile for some reason, guess you know why. Nice that you fixed it (and apparently optimised it too :P). =)
|
06 January 2010, 09:35 | #128 | |||
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
Quote:
Quote:
Getting rid of non required octant tables, redundant checking (why did I check for is it less *as well as* is it equal instead of is it less or equal!? ) and redundant bitwise manipulations does tend to speed things up a bit! Still, I'm learning all the time and you know what they say: you only learn from your mistakes... |
|||
07 January 2010, 13:09 | #129 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Nice job on the new routine, and a further optimization you can do is to skip comparisons between values you will be subtracting anyway, as a comparison is essentially a subtraction operation, and tells you the result you're looking for. Then you can find the dX, dY and dY-dX values right away to find the line octant. Reducing memory accesses by keeping intermediate values in registers is a great optimization too.
Here's a spoiler attached: |
07 January 2010, 13:37 | #130 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Nice one Leffman.
I'll take some time with what you've suggested here and look at your routine to round out what you've said. Without getting all mushy on you () I've got a lot of time and respect for your coding knowledge both because of what you've posted in many threads here (not just mine) and because of the quality of those routines of yours you posted YouTube links to previously. It's very much appreciated that you've taken time not only to look at my efforts but also to suggest other ways I can increase my understanding. I've found the best way to learn is to think as much as I can for myself and write my own code then, when someone with more skills and experience (in this case you... ) tells me how I could have done it better, the lesson sinks in more. Top man. |
07 January 2010, 13:54 | #131 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
compare, branch on result, do the subtration (to find dx / dy) ordered so that the result is always positive and store I should do: Subtract, correct result to positive as required and store, obviously preferrably in a data reg rather than a mem location. |
|
07 January 2010, 17:14 | #132 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
Say I've run out of data registers and I've got no choice but to store a variable to memory temporarily. Is it quicker to save the reg to memory with something like this: Code:
move.w d0,savereg(a5) Code:
move.w d0,-(sp) |
|
07 January 2010, 20:23 | #133 |
Total Chaos forever!
Join Date: Aug 2007
Location: Waterville, MN, USA
Age: 49
Posts: 2,188
|
@pmc
IIRC, predecrements and postincrements are expensive on the '020+. Do the former especially if it's a single-byte offset. BTW, are you subtracting -128 from the heap when you allocate it and all of the other heap accesses then adding -128 back on at the end when you deallocate it? That will insure that you're getting as many single-byte offsets as possible on the heap. Obviously this only helps if your heap is bigger than 127 bytes. |
08 January 2010, 09:55 | #134 | |
move.l #$c0ff33,throat
Join Date: Dec 2005
Location: Berlin/Joymoney
Posts: 6,863
|
Quote:
If you are sure that the upper part of d0.l is unused you could also do: swap d0 and use d0.w for other things and to restore your value you'd just swap d0 again of course. |
|
08 January 2010, 14:14 | #135 | ||
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
OK chaps, after thinking on Leffman's advice I went away and coded another version of my linedraw routine (attached).
It now has no unnecessary sub.w / cmp.w combinations using only sub.w and neg.w as required instead. Also it now no longer has any unnecessary moves to or from memory locations and does everything with data registers. Judging from the speed tests I've run there's no real difference in execution time between this new version and the previous version I posted but I prefer this new version as it's much neater. I've not checked the routine Leffman posted (that would've been cheating ) against this one so maybe there's still some optimising I could do but if there is I can't see how at the moment. Of course, I'm always happy to be corrected and learn some more. Quote:
Quote:
Nice one. Last edited by pmc; 26 February 2010 at 12:23. |
||
19 January 2010, 15:39 | #136 |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Hello people.
Since fixing the linedraw code I've made a few additional, very minor, optimisations to the hidden line demo. The demo as a whole seems to be able to handle rotating, transforming and drawing objects with around a maximum of 48 points in one frame. This number would probably increase slightly if *all* the demo was doing was the 3D objects but I can't imagine there would be time for a vast number of additional points. So, my question is: how do the coders from way back when do routines that will handle literally hundreds of points (for example the hidden dot ball in Phenomena's Enigma demo) in one frame? Are they always done with precalcs and other cheats or is there some kind of "secret" I've completely missed to speed the 3D calcs up massively? |
21 January 2010, 13:25 | #137 | |
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
|
|
21 January 2010, 19:24 | #138 |
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
If you don't want to use any tricks or precalcs it's just a matter of optimization, and restricting the effect while still making it look good.
If you just want to do rotations then you can drop the matrix and vector multiplications and do planar rotations in the X and Y planes, and drop the Z rotation. Rotating in 2 axes will still look good as the Z rotation doesn't reveal any more of the object. Now you can also convert from cartesian to polar coordinates and reduce the amount of calculations further, and if you're doing a sphere like in the Enigma demo then you can drop the perspective calculations as well. I can get down to 4 multiplications and 5 memory look-ups per point like this, 19 instructions for the entire loop, plotting included. The next step (on a plain 68K) would be to unroll the loop, and to be able to do really many points you would go back to matrix and vector multiplications and quantize your object into f.ex a 256*256*256 grid, precalculate the 256 steps along your rotated X Y and Z axes and use the X Y and Z components of each point in your object as indices into these tables. |
21 January 2010, 19:36 | #139 | ||
gone
Join Date: Apr 2007
Location: completely gone
Posts: 1,596
|
Quote:
Quote:
What are polar coordinates and how do they differ from x,y,z cartesian coords? Also, why no perspective required for a sphere? Points that are "further away" still need to be drawn / plotted closer together no matter what the object don't they? |
||
21 January 2010, 20:17 | #140 | ||
Join Date: Jul 2008
Location: Sweden
Posts: 2,269
|
Quote:
Quote:
X' = X sin a - Y cos a Y' = X cos a + Y sin a with X = D cos (A + a) Y = D sin (A + a) which is obviously faster. You can add perspective to a sphere, but being what it is, especially when just made up of tiny points on the screen, it gives you a lesser impression of depth than perspective does on f.ex a cube. Try it and you'll see. At least it's the one shape that doesn't look completely wrong without perspective. |
||
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests) | |
Thread Tools | |
Similar Threads | ||||
Thread | Thread Starter | Forum | Replies | Last Post |
Learning AMOS - Beginners Guide Disks | Peter | Retrogaming General Discussion | 15 | 28 October 2015 17:17 |
DiskImage: When learning to read proves futile. | XDelusion | support.Apps | 19 | 20 October 2012 23:57 |
Wanting to start learning to code amiga in asm | fishyfish | Coders. Asm / Hardware | 5 | 03 March 2012 06:11 |
Playpower - 8 bit learning games for the developing world | girv | Retrogaming General Discussion | 5 | 24 March 2009 22:00 |
Learning assembler | bLAZER | Coders. General | 1 | 12 May 2007 05:00 |
|
|