Log inRegister an accountBrowse CSDbHelp & documentationFacts & StatisticsThe forumsAvailable RSS-feeds on CSDbSupport CSDb Commodore 64 Scene Database
You are not logged in 
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-25 21:06
Cybernator

Registered: Jun 2002
Posts: 154
> I think we talked about this and I had sent
> them either to you (or another guy?)

Yes, it was me. :) I have that somewhere on the HD, or maybe I've burnt it on CD.

> Last time, I couldn't understand how it works
> (and I was supposed to be the math student ;)

<weed_mode :P>There's one nasty thing about these sciences, you can't just sit and learn. It takes practise, and it's a pain to practise something you can't see a result of. Solving numbers is just so boring, unless you can use that in your demo (the result I'm talking about :)). It took me some time to understand how the rotation formulas are derived, after which I'm not coding this stuff blindly, or at least I feel so. It seems so simple now.. Or does it? One needs to know some of the fundamental trig identities in order to derive. I have no idea how these identities are derived. I just used them blindly. At uni I'm having quite some troubles with physics, electrotechincs (or whatever it's called in English), and with math as well. I'm having enough motivation to stop my LDAs and STAs for a while, and spend more time on linear algebra. Although I don't get much of WVL's explanation (even if it's veeery familiar :)), he gave me enough motivation to spend more time on physics as well. Hmm... Anyone's got any idea why should I learn electrotechincs? :P</weed_mode>

If I understood the article in Hugi, functions like sin, cos, ln, on a computer are actually calculated by some approximations. Quite interesting. In fact, this discussion turned pretty interesting. :) Another thing which I'm really curious about: how does one calculate the value of PI? All I know is that it's the ratio of the circumference of a circle and its diameter. Say the diameter is 1, the circumference would then equal PI. But how do I calculate PI? (they've stopped, let us continue :))
2004-11-25 21:27
WVL

Registered: Mar 2002
Posts: 840
calculating PI is a really tedious job. The best way might be to use some kind of series, derived from an integration in the imaginary/real plane around a point where the value of the function you want to integrate becomes infinite.

(this is real hard to explain, so i won't)

you get something like

PI/4 = 1 - 1/3 + 1/5 = 1/7 + 1/9 - etc..

but this converges very slowly -> you have to do a lot of calculations to get a reasonable accuracy!

just imagine adding 1/1001, which you do after 500 steps -> it still changes the calculated value in the 3rd decimal. So you need WAY MORE than 1000 steps, to get 3 decimals correctly!!

ofcourse there are faster ways, but in general, forget about it and just use PI=3.1415926536 ;)
2004-11-26 10:14
Graham
Account closed

Registered: Dec 2002
Posts: 990
there's countless ways to calculate pi. most formulas used to calculation millions of digits from pi involved some fast converging arctan formula. but in 1995 a completely new way and much more efficient way to calculate pi was found: the Bailey-Borwein-Plouffe algorithm. with that algorithm you can calculate the n-th hexadecimal digit of pi without calculating the previous ones. very interesting, especially because you can find similar formulas for other numbers like log(2) or sqrt(2).

http://mathworld.wolfram.com/bimg673.gif
2005-02-28 12:32
peskanov
Account closed

Registered: Mar 2004
Posts: 17
Spherical cords work very fast and are ok for using tables.
Of course you can not rotate an object in spherical cords just adding to the values. To understand it, just look to a earth globe; lattitude (ecuator) and longitude (greenwich) are very similar to spherical cords.
If you take two points in the opposite side of the sphere, and add a value to it's longitude coordinate, both will rotate correctly over earth axis.
However, if you add a value to the lattitude coordinate, both will rise to the north pole, converging there.

To rotate a point in spherical coordinates, the fastes way I know is to convert to normal xyz space, and then again to spherical coord, but this time using other axis as reference.
On Amiga we used to create a table 8:8. Something like Phi:Teta for axis Z -> Phi:Teta in axis Y.
The steps are then:
- Take coordinates, axis Z as reference, add longitude. (ADD)
- Convert angles to a space with axis Y as reference. (LOAD)
- Add longitude for axis Y. (ADD)
- Convert angles to a space with axis X as reference. (LOAD)
- Add longitude for axis X. (ADD)
- Convert to XYZ space and plot (a few LOADs)
Fast, but very tricky in terms of precission, and very memory hungry.

I am not sure now, but I think the intro "A500 homage" used this tech.
2005-02-28 18:55
Ben
Account closed

Registered: Feb 2003
Posts: 163

The big advantage of spherical coordinates is that one can refrain from thinking in cartesian coordinates.. so please feel free to do so :) There is little mysticism to it..

By incrementing radius degrees in each and every spherical vector, one should obtain rotation on a sphere in the cartesian system..
No back and forth conversion required, apart from a single conversion when plotting the vector in a 2D cartesian system..
2007-08-24 14:21
ready.

Registered: Feb 2003
Posts: 426
Hi,
I first I wanted to start a new thread, but then I though the title of this one suits my question properly.
I can't figure out the priciple of the code behind the rotating textured sphere in Boogie Factor by Fairlight:
http://noname.c64.org/csdb/release/?id=19296&show=review

How much is it pre-calculated and how much calculation does the 6510 really do?
Thanks for help!!

Ready.
2007-08-24 14:21
ready.

Registered: Feb 2003
Posts: 426
Oops, I should have clicked EDIT....
Of course the white glimmerings are sprites.
2007-08-24 14:31
Oswald

Registered: Apr 2002
Posts: 4291
code to calculate one byte is:

lda $xxxx,x
ora $xxxx,x
ora $xxxx,x
ora $xxxx,x
sta screen

as precalculated as it can get, its just table lookups in a speedcode.

basically you precalculate a sphere mapped with indexes, the indexes point into a 16x16 texture. then you offset the table lookups with ,x to get it moving.
2007-08-24 14:47
ready.

Registered: Feb 2003
Posts: 426
mmh, so I guess the thread title does not fit anymore :(
Anyways, thanks. I had looked at the code before posting first, but I was tricked by the ORAs, which I still don't get.

If it is just a matter of display what's in RAM into a 16x16 char matrix, why can't I use simply

LDA $xxxx,x
STA $xxxx,x

every n-frames?
2007-08-24 15:12
Oswald

Registered: Apr 2002
Posts: 4291
every byte contains 4 independent pixels, thus you need 4 texture lookups for each byte. the texture is stored 4 times in 4 table, so you dont need to shift the pixels into their place by hand.

lda texturatable1+currenttexturingoffset4thispixel,x
lda texturatable2+currenttexturingoffset4thispixel,x
lda texturatable3+currenttexturingoffset4thispixel,x
lda texturatable4+currenttexturingoffset4thispixel,x
sta bitmap

edit: also its not just copying bytes, this is a kind of very primitive (precalculated) texture mapping.
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
stephan-a
Kruthers
Guests online: 24
Top Demos
1 Uncensored  (9.7)
2 Comaland 100%  (9.7)
3 Edge of Disgrace  (9.7)
4 Coma Light 13  (9.6)
5 The Shores of Reflec..  (9.6)
6 Wonderland XII  (9.6)
7 Lunatico  (9.6)
8 We Come in Peace  (9.6)
9 Incoherent Nightmare  (9.5)
10 Wonderland XIII  (9.5)
Top onefile Demos
1 FMX Music Demo  (9.6)
2 Daah, Those Acid Pil..  (9.6)
3 Arok 20 Invitation  (9.6)
4 Merry Xmas 2017  (9.5)
5 Pandemoniac Part 2 o..  (9.5)
6 Party Horse  (9.4)
7 Dawnfall V1.1  (9.4)
8 In Memoriam BHF  (9.4)
9 Dawnfall  (9.4)
10 Synthesis  (9.4)
Top Groups
1 Oxyron  (9.4)
2 Booze Design  (9.4)
3 Censor Design  (9.4)
4 Finnish Gold  (9.3)
5 Crest  (9.3)
Top Graphicians
1 Facet  (10)
2 Razorback  (9.8)
3 Mirage  (9.8)
4 JonEgg  (9.7)
5 Archmage  (9.7)

Home - Disclaimer
Copyright © No Name 2001-2018
Page generated in: 0.07 sec.