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 > Spherical Coords
2004-11-19 20:27
Cybernator

Registered: Jun 2002
Posts: 154
Spherical Coords

I was doing 3D plots like those in Oneder, +H2K, Late Ejaculation, etc.. It all works a-ok, except that it's pretty slow. :) Took the liberty to disassemble the above mentioned demos and I ended up nowhere. The speedcode relies on some values stored on zeropage, but I can't realize what these values are. What follows is part of the speedcode from Oneder which handles one single plot.

The X reg is either 00 or 80 (which points to the bank I think), which doesn't really matter.
,8000 a5 7a LDA $7a
,8002 e5 94 SBC $94
,8004 e5 ac SBC $ac
,8006 a8 TAY
,8007 b1 e4 LDA ($e4),Y
,8009 85 e1 STA $e1 ; absolute ypos on screen (?)
,800b 9d 02 a4 STA $a402,X ; modifies a separate speedcode to clear the plot later
,800e a5 17 LDA $17
,8010 e5 31 SBC $31
,8012 e5 49 SBC $49
,8014 8d 21 80 STA $8021
,8017 29 f8 AND #$f8
,8019 19 00 41 ORA $4100,Y
,801c 9d 01 a4 STA $a401,X ; modifies a separate speedcode to clear the plot later
,801f a8 TAY ; absolute xpos on screen (?)
,8020 ad 71 43 LDA $4371 ; bitmask ($80, $40, $20, $10, 8, 4, 2, 1)
,8023 91 e0 STA ($e0),Y ; hit it! :)

Now what the hell are eg. the first three instructions?

--

I wonder if this is handled with spherical coordinates. Conversion from spherical to cartesian should be fairly simple to implement: x=r*sin(theta)*cos(phi); y=r*sin(theta)*sin(phi); z=r*cos(theta)

Now the cool stuff about the multiplication of the trig. functions:
sin(theta)*cos(phi)=(sin(theta+phi)+sin(theta-phi))/2
sin(theta)*sin(phi)=(cos(theta-phi)-cos(theta+phi))/2
Which is simply a matter of ADC/SBC. As for the multiplication of the radius, I guess several tables would do the job. I still haven't thought of a fast way to handle the projection, though.

Now, all this is cool, but I've got some trouble. I made a PC proggy to test these conversions. It loads a file containing vertices in cartesian coord. system. Then converts them to spherical, which means that the rotation is simple INC/DEC on the angles. These rotated angles are converted back to cartesian and plotted on screen. But something is wrong: incrementing of one of the angles works a-ok, but if I increment the other one, the object distorts. This shouldn't happen, rite? I mean, it's logical. Or maybe there's another way to handle this rotation (still hadn't reached this topic at university :)). Afterall, perhaps there's some bug in the proggy, but I can't find out what it is.

In case you wanna see the proggy, here it is: http://www.geocities.com/lazeristoski/polar.zip
Arrows handle the angles. A/Z handles the radius, but that is not important.

Is it a good idea to handle this with spherical coordinates?
 
... 27 posts hidden. Click here to view all posts....
 
2004-11-24 14:06
Krill

Registered: Apr 2002
Posts: 2980
hmm, linear approximation using a 256-stepped 16-bit sine worked well enough for me. check bar4kode, i generated a $0800-stepped 24 bit sine with it there for the twisting bar, and i dont think one would notice any difference compared to a taylor-generated sine at all.
2004-11-24 15:22
Ben
Account closed

Registered: Feb 2003
Posts: 163
@Krill:
I guess you mean inter/extrapolation with linear approximation. I reckon 256 steps should indeed do a good job. I guess the number of steps can even be drastically reduced by mirroring and removing redundancy. I guess all it would take is running some test and stretch the limits.

I guess I am mistaking the C64 to be used for scientific applications ;) Damn.. I am getting old :)
2004-11-24 16:59
Krill

Registered: Apr 2002
Posts: 2980
ben:

of course i did not store the full 256 steps sine in the 4k, but instead just the first 64 steps (0 to pi/2) =)
2004-11-24 17:19
Cybernator

Registered: Jun 2002
Posts: 154
Hugi's such a great piece. Thanks for the link Optimus! Btw, was the sinus generator by Baze using Taylor's stuff?

Ben wrote:
> Can you describe the type of distortion
> you experience?

Erm... Hardly! :) If possible, take a look at the distortion yourself. Uhm, something crossed my mind.. If I wanted to make such a distortion on purpose, I wouldn't have been able to. :P

> However, are you sure your projection
> functionality properly handles sign/phase
> changes?

There's no projection implemented. The X and Y coords of the rotated object are directly used, Z is thrown out. According to the book from where I've taken the formulas, Y axis goes right, Z goes up, and X comes out. So practically I mix them, 'coz on monitor X goes right and Y goes down, but I don't think that can cause a distortion. It must be a very stupid bug. I'll write the thing from scratch. In fact, as soon as Oswald said that Oneder wasn't using spherical coords, I've just thrown the idea. :)

All these maths and floats (thanx for the PDFs, White Flame) freak me out sometimes. I'll just have to dive in the PC-scene as well. Lotsa stuff can be learnt from there. (now I deserve an asskick :P)

Btw, the fire-ish effect in "Halfway There" (the very first one) by Dekadence.. Does it have a formal name? I'd like to google for some info.
2004-11-25 12:27
Optimus

Registered: Jan 2002
Posts: 122
>optimus, on c64 sines are not generated runtime, but are precalculated.

Do you mean that this is how the Kernel ROM sin routine does it? (Else, of course I am aware that democoders are using precalculated sines and don't generate them in realtime, the link was just interesting for people who want to pregenerate them in 256b intros or so)
2004-11-25 12:35
Optimus

Registered: Jan 2002
Posts: 122
>Btw, was the sinus generator by Baze using Taylor's stuff?

Baze's words: "well I'm not quite sure but that algorithm simulates a harmonic oscillator"

I had his emails with further explanations which I can't find for the moment, I think we talked about this and I had sent them either to you (or another guy?) a long time ago. Last time, I couldn't understand how it works (and I was supposed to be the math student ;), perhaps in the future I will. There are lessons in my uni I keep loosing, having a lot of connections with maths from demomaking I read around here.. ;P
2004-11-25 14:46
Oswald

Registered: Apr 2002
Posts: 5094
Optimus: I meant that demos use precalced sine tabs, iirc the kernal uses same tables but not much... but really no idea how it calx the sine... this also a way to precalc sinetabs, simply use the kernals floating point accumulator and its sine routine.. :)
2004-11-25 15:13
WVL

Registered: Mar 2002
Posts: 902
emulating an oscillator would be pretty easy.

the math :

let's say you've got a pendulum moving around, you can write the forces acting on the pendulum like :

F = -k*x (x being the offset from the center, k being the spring constant).

the equation of motion becomes :
d2 x(t)    -k*x
------- = ------
  dt2        M

the solution to this is that x ~ some sine

an emulation would be :

have the variables x,v,a,t

set x to -1, v&t to 0,a to whatever

loop :
1 store the value of x in the sine at position t
1b t=t+1
2 a=-k*x
3 v=v+a/M*dt (make dt=1 ;)
4 x=x+v
5 check if x is -1 again ,in which case the sine ends and the loop stops.. 
(a better check would be that x< -0.99 and speed is negative or something)

that's it..

btw, the amplitude of the sine is set by choosing the correct starting value for x at t=0.

the frequency of the sine is set by (sqrt(k/m)) (iirc) ;)

2004-11-25 15:19
Graham
Account closed

Registered: Dec 2002
Posts: 990
some amiga and pc coders used oscilators for their sine calculation. i remember sanity had one in their amige demo-os too. but you need lots of bits and on c64 its propably smaller to just store a quater of the sine and mirror the rest.
2004-11-25 15:51
WVL

Registered: Mar 2002
Posts: 902
it's true that you need lotsa bits. but in return you only have to do add's. if you want a large difference in the sines you need to calc, oscillators are pretty good IMO.

ofcourse my favorite way is to add 2 sines to get new sines with different amplitudes (amplitude ranging from 0x to 2x the original sine).
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
CreaMD/React
Guests online: 105
Top Demos
1 Next Level  (9.7)
2 13:37  (9.7)
3 Mojo  (9.7)
4 Coma Light 13  (9.6)
5 Edge of Disgrace  (9.6)
6 What Is The Matrix 2  (9.6)
7 The Demo Coder  (9.6)
8 Uncensored  (9.6)
9 Comaland 100%  (9.6)
10 Wonderland XIV  (9.6)
Top onefile Demos
1 No Listen  (9.6)
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 Webmasters
1 Slaygon  (9.6)
2 Perff  (9.6)
3 Sabbi  (9.5)
4 Morpheus  (9.4)
5 CreaMD  (9.1)

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