Path: utzoo!utgpu!news-server.csri.toronto.edu!cs.utexas.edu!swrinde!zaphod.mps.ohio-state.edu!samsung!munnari.oz.au!bruce!labtam!eyrie!phoenix!static From: static@phoenix.pub.uu.oz.au (geoff c wing) Newsgroups: comp.sys.amiga.tech Subject: Re: Integer sine calculations? Keywords: assembly integer sine Message-ID: <1990Nov25.171154.8065@phoenix.pub.uu.oz.au> Date: 25 Nov 90 17:11:54 GMT References: <7336@hub.ucsb.edu> Distribution: comp Organization: Phoenix ComSystem. Public UNIX Melbourne Australia. Lines: 148 In <7336@hub.ucsb.edu> 6600mage@ucsbuxa.ucsb.edu (Orion Wilson the Passable) writes: > .. Have you seen these hacker demos where >the balls or whatever follow sinusoidal paths around >the screen? And where there are HUNDREDS of balls ^^^^^^^^^^ It depends on the size of the "balls", and how many planes. Most I've seen is 240 or so, 16*11(?)*2bp "balls". >all going very smoothly through what appear to be >complex hypo-cycloids and such? >My question is how these paths are computed. The >number of objects and their speed incidates that >they aren't being done by floating-point techniques, Don't do it with FFP. It takes way too long. Since you have to recalculate every frame and redraw(use the blitter), you can only calculate about 30 points. >and i'm pretty sure the numbers are not >pre-calculated, so it seems that smooth curves like >the sin and cos can be done using integer (native >MC68000) arithmatic. > > Is this so? Does anybody out there know what >these algorythms are? Am i posting in the wrong >area? And why hasn't my mouse come home? > For the answers to these questions and more, > please write me so i may learn. Do you want to start up a new newsgroup - "amiga.teachme68k" ? Here's some code for a 3d rotation. The blitter line drawing routine can be found on pages 163-165 of Abacus' "Amiga System Programmer's Guide" or you could easily find someone to tell you. I've used the code below for a filled vector graphic demo(still not yet released though). I can't find many other ways to optimize the code(with respect to speed,not size). I assume you know about swapping which planes are being displayed(eg.work on one, display other). Don't use rubbish like the Taylor series to work out angles. People who recommend it have been studying Mathematics too long and obviously don't code much. You don't need to change the base positions. Just use pointers to places within the sine table. Well, actually, this is untrue for some routines, and some other nice effects(of course), like merging from one shape to another. You'll need to do a bit more work to get the nice hyperboloid effects, but we wouldn't want you to get there too easily. Put some effort it. Anyway here's some text I wrote a while back: ANGLETABLE: 360 Sine words stored multiplied by 32767. All cosine angles are sin(angle+90degrees). One pair for each angle stored here. eg. 0.8386 is [(8386*32767)/10000] = 27478 ($6b56) -0.4324 is [(-4324*32767)/10000] = -14168 ($c8a8) They are thus used : (see rotation example at end) A0: pointer to angle table D1: offset of angle move.w number,d0 muls (a0,d1.w),d0 lsr.l #8,d0 lsr.l #7,d0 bclr #16,d0 ; often unnecessary D0: now contains integer position Storage: blk.w 360,0 Angles : 91 words (for sine angles 0-90 degrees). All other angles in the angletable can be made from these, so leave block storage at end. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** dc.l $0000023b,$047706b2,$08ed0b27,$0d610f99 ; 0 - 7 dc.l $11d01405,$1639186c,$1a9c1cca,$1ef72120 ; 8 - 15 dc.l $2347256c,$278d29ab,$2bc62dde,$2ff23203 ; 16 - 23 dc.l $340f3617,$381c3a1b,$3c173e0d,$3fff41ec ; 24 - 31 dc.l $43d345b6,$4793496a,$4b3b4d07,$4ecd508c ; 32 - 39 dc.l $524653f9,$55a5574b,$58e95a81,$5c125d9c ; 40 - 47 dc.l $5f1e6099,$620c6378,$64dc6638,$678d68d9 ; 48 - 55 dc.l $6a1d6b58,$6c8b6db6,$6ed96ff2,$7103720b ; 56 - 63 dc.l $730a7400,$74ee75d2,$76ad777e,$78467905 ; 64 - 71 dc.l $79bb7a67,$7b097ba2,$7c317cb7,$7d327da4 ; 72 - 79 dc.l $7e0d7e6b,$7ec07f0a,$7f4b7f82,$7faf7fd2 ; 80 - 87 dc.l $7feb7ffa,$7fff0000 ; 88 - 90 ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** THREE DIMENSIONAL ROTATION -------------------------- (x,y,z) must be rotated with matrices (in any order) : |cos -sin 0||x| |cos 0 -sin||x| |1 0 0 ||x| |sin cos 0||y| | 0 1 0 ||y| |0 cos -sin||y| | 0 0 1||z| |sin 0 cos||z| |0 sin cos||z| however this can be done with the standard rotation matrix A : A =|cos -sin| A|x| A|x| A|y| NB. Make sure the correct |sin cos| |y| |z| |z| angle is used each time. ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** A0: pointer to angle table A1: x position A2: y position A3: z position D0-D2/D4-D7: work ROTATION: -getangle(d6,d7) ; D6: sine offset about Z axis move.w a1,d4 ; D7: cosine offset about Z axis move.w a2,d5 bsr.S MATRIX move.w d0,a1 move.w d1,a2 -getangle(d6,d7) ; D6: sine offset about Y axis move.w a1,d4 ; D7: cosine offset about Y axis move.w a3,d5 bsr.S MATRIX move.w d0,a1 move.w d1,a3 -getangle(d6,d7) ; D6: sine offset about X axis move.w a2,d4 ; D7: cosine offset about X axis move.w a3,d5 bsr.S MATRIX move.w d0,a2 move.w d0,a3 ...... ...... rts MATRIX: move.w d4,d0 muls (a0,d7.w),d0 lsr.l #8,d0 add.l #64,d0 (round off properly-remove if unnecessary) lsr.l #7,d0 move.w d5,d1 muls (a0,d6.w),d1 lsr.l #8,d1 add.l #64,d1 (round off properly-remove if unnecessary) lsr.l #7,d1 sub.w d1,d0 move.w d4,d1 muls (a0,d6.w),d1 lsr.l #8,d1 add.l #64,d1 (round off properly-remove if unnecessary) lsr.l #7,d1 move.w d5,d2 muls (a0,d7.w),d2 lsr.l #8,d2 add.l #64,d2 (round off properly-remove if unnecessary) lsr.l #7,d2 add.w d2,d1 rts ***** ***** ***** ***** ***** ***** ***** ***** ***** ***** -- +---------------------------------+ _ _ _ _ __ | Geoff //| /\ |\/| | / _ /\ | static@phoenix.pub.uu.oz.au \X/ | //\\ | | _|_ \__| //\\ +---------------------------------+