Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in - nap
CSDb User Forums


Forums > C64 Coding > 3D projection on the C=64 (or...how do I divide?)
2004-02-13 08:51
Scout

Registered: Dec 2002
Posts: 1570
3D projection on the C=64 (or...how do I divide?)

Hi!

After 12 years I picked up coding again on the C=64.
What I want to make is a simple 3D starfield.
I know something about 3D programming, so that's no issue.

The only thing I stumbled on is how to implement 3D projection (X1=X/Z) and especially the dividing part of it.
How can I implement this on the C=64?

Any hints, tips?

Thanx!

R.
(Asm on the PC is so much easier ;-)
 
... 25 posts hidden. Click here to view all posts....
 
2004-02-13 13:35
Scout

Registered: Dec 2002
Posts: 1570
Quote: the lacking accuracy of this approach is not to be ignored with 3d code. i might add that the best accuracy with this algorithm can be achieved by using the binary logarithm, but i guess you've already taken that one.
for more accuracy, the best thing is a plain binary division routine that calculates one bit of the result per loop pass, being as exact as you want it to be.
if you never coded such a thing, wait for some future issue of one of the disk mags where there are further chapters of my tutorial on maths in assembler published. i don't want to get into further detail here but i can send you sample routines or the chapter of that tutorial in german language, as i did not translate it to english yet.


Hi

I appreciate if you could send those routines/info.
It's no problem if the text is in German coz I can read it a bit (I'm dutch).

Thanx.

R.

2004-02-13 14:58
Cruzer

Registered: Dec 2001
Posts: 1048
I have always precalculated everything => no need for division and other nasty realtime stuff :)

But if I'm going to make something in realtime one day, Perffs algorithm seems pretty smart... But if it's inaccurate how about this:

x/y = x*(1/y)

Then you just need a table of 1/x and to do a multiply. The latter can be done with this algorithm...

Let f(x) = x^2 / 4.

Then a*b = f(a+b) - f(a-b)

So with a table of squares/4 and 1/x you should be able to divide using adc and sbc.
2004-05-12 09:02
Nightlord
Account closed

Registered: Jan 2003
Posts: 131
cruzer:

i have thought of division using your approach but i ran into a problem that 1/x table starts to get inacurate for large x values. besides the f(a+b) and f(a-b) also becomes troublesome. since now typical a values are decimals and typical b values are fixed point reals between 0 and 1

i have the feeling that this should be fixable by playing with the tables but couldn't figure out how? so how do you handle these issues.

thanx in advance
2004-05-12 09:28
Cruzer

Registered: Dec 2001
Posts: 1048
Nightlord: Do you need to divide by large numbers when doing 3d projections?

Any division routine on c64 is bound to be inaccurate or slow, so I guess you'll have to live with some inaccuracy. Then the trick is to make it just accurate enough to suit your particular need.

But as I said, I always precalculate everything, so I haven't got any experience with implementing a division routine myself.

And btw, I think Perff's routine looks smarter than mine.
2004-05-13 02:47
SIDWAVE
Account closed

Registered: Apr 2002
Posts: 2238
If you only want to make a 3D starfield end nothing else, just do like the game DELTA.

set a sprite and give it a different X position every rasterline.

The sprite is just made of a single vertical line in 1 color.

Do different sinus tables for each sprite, and it will look quite real to you.

2004-05-13 11:44
Nightlord
Account closed

Registered: Jan 2003
Posts: 131
cruzer:

at the moment i am using division for 2d line slope calculation. it is precalculated in my engine which makes it bound between 0 to $40 and i store slopes as $xx.xx so i spend $40 x $40 x 2 = $2000 bytes which hurts my mind. since i don't use eors to fill and i fill line by line (this lets me to make surfaces with dithered patterns unlike eor)i need to take one step in y everyline and left/right slope steps in left and right boundaries of line. for this reason i could not find a way to use stephen judd's add-dx-until-bigger-than-dy approach. (it isnot applicable for me when dx > dy)

can any body give some fresh ideas.
2004-05-13 14:20
Oswald

Registered: Apr 2002
Posts: 5094
nightlord: my guess is, that using logs and exps is accurate enough for your routine, either u use this one, or the bloody slow, but hell accurate bit shifter killer one. (you can find this on steve judd's page)

and speaking of patterns, you can have 13 different ones if you use eorfilling a bit more trickyer: have 2 eor buffers, one with the odd, one with the even lines of your screen. then you draw each line into both of them, but with a different colour pattern for the pixelmasks. then you just eor to the screen in 2 go the odd and even lines, and voila you have patterns :)
2004-05-13 18:56
Cruzer

Registered: Dec 2001
Posts: 1048
When dx>dy I guess you need to do an integer division for the Bresenham algorithm, although I have never tried to implement it on the c64. Maybe you can make some LUT-stuff for this, that doesn't fill too much.
2004-05-13 20:40
White Flame

Registered: Sep 2002
Posts: 136
You technically don't need to do a divide.

All's that Bresenham does is keep track of the slope's fraction in a numerator/denominator pair instead of in fixed point. When the numerator gets bigger than the denominator, you bump by 1 pixel and subtract the denominator from the numerator. If you change that comparison to a "while(num>=denom) { ++x; num-=denom; }" loop (with --x for the other direction obviously), the same general code will work no matter the slope. Whether that's faster or slower than doing a divide before-hand (to figure out the integer portion of the delta so you don't need to loop the num>demon compare) depends on the slope of the line. Where the delta is large, a divide is faster. However, if the delta is large, the line won't be very long, so it sort of evens out. The code is a lot shorter and easier to manage if you do a compare loop.
2004-05-17 11:41
Nightlord
Account closed

Registered: Jan 2003
Posts: 131
oswald: you are the master of odd/even lines

thx everyone
Previous - 1 | 2 | 3 | 4 - Next
RefreshSubscribe to this thread:

You need to be logged in to post in the forum.

Search the forum:
Search   for   in  
All times are CET.
Search CSDb
Advanced
Users Online
Courage
Benson/Tristar & Red..
The Syndrom/TIA/Pret..
Unlock/Padua/Albion
Durandal
MaD ][/Starship
Andy/AEG
Malmix/Fatzone
Guests online: 109
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 The Demo Coder  (9.6)
6 Edge of Disgrace  (9.6)
7 What Is The Matrix 2  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.7)
2 Layers  (9.6)
3 Cubic Dream  (9.6)
4 Party Elk 2  (9.6)
5 Copper Booze  (9.6)
6 X-Mas Demo 2024  (9.5)
7 Dawnfall V1.1  (9.5)
8 Rainbow Connection  (9.5)
9 Onscreen 5k  (9.5)
10 Morph  (9.5)
Top Groups
1 Performers  (9.3)
2 Booze Design  (9.3)
3 Oxyron  (9.3)
4 Censor Design  (9.3)
5 Triad  (9.3)
Top Fullscreen Graphicians
1 Joe  (9.7)
2 Sulevi  (9.6)
3 The Sarge  (9.6)
4 Veto  (9.6)
5 Facet  (9.6)

Home - Disclaimer
Copyright © No Name 2001-2024
Page generated in: 0.048 sec.