BBC BASIC for Windows
« Yet another starfield »

Welcome Guest. Please Login or Register.
Apr 6th, 2018, 12:24am



ATTENTION MEMBERS: Conforums will be closing it doors and discontinuing its service on April 15, 2018.
Ad-Free has been deactivated. Outstanding Ad-Free credits will be reimbursed to respective payment methods.

If you require a dump of the post on your message board, please come to the support board and request it.


Thank you Conforums members.

BBC BASIC for Windows Resources
Online BBC BASIC for Windows documentation
BBC BASIC for Windows Beginners' Tutorial
BBC BASIC Home Page
BBC BASIC on Rosetta Code
BBC BASIC discussion group
BBC BASIC for Windows Programmers' Reference

« Previous Topic | Next Topic »
Pages: 1  Notify Send Topic Print
 thread  Author  Topic: Yet another starfield  (Read 1556 times)
rtr2
Guest
xx Re: Yet another starfield
« Reply #6 on: Apr 2nd, 2015, 10:18pm »

on Apr 2nd, 2015, 5:20pm, David Williams wrote:
Here's another conversion from ARM BBC BASIC V (which is rather disingenuous of me because I developed most of it with BB4W!).

That's nice, and it would make a good demo program - except that I presume there are likely to be copyright/trademark issues with regard to the Raspberry Pi logo. Do you happen to know?

Quote:
If the perspective transform(s), which probably requires thousands of clock cycles per frame, can be offloaded to a matrix (and I believe it can!), then a performance boost will ensue.

I can't speak for RISC OS, but on my PC the plotting takes vastly longer than the perspective calculations (something like a factor of 20) so any improvement would be tiny.

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Yet another starfield
« Reply #7 on: Apr 2nd, 2015, 10:23pm »

on Apr 2nd, 2015, 10:18pm, g4bau wrote:
That's nice, and it would make a good demo program - except that I presume there are likely to be copyright/trademark issues with regard to the Raspberry Pi logo. Do you happen to know?


They have something to say about it here, I think:

http://www.raspberrypi.org/trademark-rules/


David.
--
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Yet another starfield
« Reply #8 on: Apr 28th, 2015, 9:30pm »

Code:
      REM 3D Starfield II

      *FLOAT 64
      MODE 8
      OFF

      N% = 1000

      DIM X%(N%-1), Y%(N%-1), Z%(N%-1)
      boxSz% = 40000
      boxSz_2% = boxSz% DIV 2
      maxZ_1 = 1 / boxSz%

      FOR I% = 0 TO N%-1
        X%(I%) = RND( boxSz% ) - boxSz_2% - 1
        Y%(I%) = RND( boxSz% ) - boxSz_2% - 1
        Z%(I%) = boxSz_2% * (1 - I%/(N%-1))
      NEXT I%

      REM Division table needed for ARM BBC BASIC version
      REM (using this is probably slower for BB4W)
      DIM divTbl( boxSz% )
      divTbl(0) = 0
      FOR I% = 1 TO boxSz%
        divTbl(I%) = 1/I%
      NEXT I%

      ORIGIN 640, 512
      GCOL 1
      TIME = 0

      *REFRESH OFF

      REPEAT
        CLS
        FOR J% = 1 TO 5
          T% = TIME
          X% = boxSz_2% * SIN(2*PI*T%/1700)*SIN(4*PI*T%/3000 + 1.5)*SIN(9*PI*T%/9022 - 2.3)
          Y% = boxSz_2% * COS(3*PI*T%/1830)*COS(3*PI*T%/3400 + 1.2)*SIN(5*PI*T%/9812 - 3.1)
          Z% = boxSz_2% * SIN(2*PI*T%/1455)*SIN(6*PI*T%/3702 - 2.1)*SIN(3*PI*T%/10800 + 1.2)
          FOR I% = 0 TO N%-1
            dZ% = Z%(I%) - Z%
            IF dZ% > 100 THEN
              z = 1000 * divTbl(dZ%)
              x% = (X%(I%) - X%) * z
              IF ABS(x%) < 640 THEN
                y% = (Y%(I%) - Y%) * z
                IF ABS(y%) < 512 THEN
                  i = 1 - dZ%*maxZ_1
                  col% = 256*i*i
                  COLOUR 1, col%, col%, col%
                  CIRCLE FILL 2*x%, 2*y%, 12
                ENDIF
              ENDIF
            ENDIF
          NEXT I%
        NEXT J%
        *REFRESH
        SYS "Sleep", 5
      UNTIL FALSE
 




User IP Logged

rtr2
Guest
xx Re: Yet another starfield
« Reply #9 on: Apr 30th, 2015, 09:08am »

on Apr 28th, 2015, 9:30pm, David Williams wrote:
REM Division table needed for ARM BBC BASIC version
REM (using this is probably slower for BB4W)

I tried to benchmark that:

Code:
      DIM divTbl(40000)
      FOR I% = 1 TO 40000
        divTbl(I%) = 1/I%
      NEXT I%

      TIME = 0
      FOR J%=1 TO 100 : FOR I%=1 TO 40000 : A = divTbl(I%) : NEXT : NEXT
      PRINT "Using lookup table: ";TIME

      TIME = 0
      FOR J%=1 TO 100 : FOR I%=1 TO 40000 : A = 1/I% : NEXT : NEXT
      PRINT "Using division    : ";TIME 

Which gave (using BB4W v6.00a):

Code:
Using lookup table: 311
Using division    : 270 

So although the table is a little slower, there's not much in it.

Richard.
User IP Logged

David Williams
Developer

member is offline

Avatar

meh


PM

Gender: Male
Posts: 452
xx Re: Yet another starfield
« Reply #10 on: Apr 30th, 2015, 4:34pm »

on Apr 30th, 2015, 09:08am, g4bau wrote:
Which gave (using BB4W v6.00a):

Code:
Using lookup table: 311
Using division    : 270 

So although the table is a little slower, there's not much in it.


Thanks.

Going by ARM BBC BASIC on a Raspberry Pi 2, using a division table is, at best, about 34% faster (which surprised me - I thought it would be faster than that - perhaps upwards of 50%). At worst, if reading essentially random entries (5-byte floats) from a large division table (too big to fit in the CPU's L1 (or L2?) cache), it's only 1 or 2% faster. So, in real-world use I'm guessing around 20 to 25% faster on average.

For really speed-critical stuff, I've found that a division table of fixed-point integers to be worthwhile (with ARM BBC BASIC), when accuracy isn't too important.


David.
--
« Last Edit: Apr 30th, 2015, 7:27pm by David Williams » User IP Logged

Pages: 1  Notify Send Topic Print
« Previous Topic | Next Topic »

| |

This forum powered for FREE by Conforums ©
Terms of Service | Privacy Policy | Conforums Support | Parental Controls