BBC BASIC
Programming >> Graphics and Games >> Success !!
http://bbcbasic.conforums.com/index.cgi?board=graphics&action=display&num=1505261023

Success !!
Post by michael on Sep 13th, 2017, 12:03am

I think I have a stable cycle and no crash and no other issues !!

The editor can now be put into this program to instantly modify the triangles with the mouse.

Code:
      IF INKEY$(-256)="W" INSTALL @lib$+"D3DLIBA" ELSE INSTALL @lib$+"OGLLIB"
      
      MODE 8
      DIM l%(0), b%(1), n%(1), f%(1), s%(1), m%(1), t%(1), y(1), p(1), r(1), X(1), Y(1), Z(1), e(2), a(2)
      ON CLOSE PROCcleanup:QUIT
      ON ERROR PROCcleanup:PRINT REPORT$:END
      IF INKEY$(-256)="W" d% = FN_initd3d(@hwnd%, 1, 0) ELSE d% = FN_initgl(@hwnd%, 1, 0)
      IF d% = 0 ERROR 100, "Can't initialise Direct3D"
      e() = 0, 0, -6
      a() = 0, 0, 0
      l%()=1
      REPEAT
       PROCcreate3d 
b%(0) = FN_load3d(d%, @dir$+"TRIANGLE.B3D", n%(0), f%(0), s%(0))
        IF b%(0) = 0 ERROR 100, "Can't load TRIANGLE.B3D"
        REM  t%(1) = FN_loadtexture(d%, @dir$+"purple.JPG")
        REM  IF t%(1) = 0 ERROR 100, "Can't load face.JPG"
  
  
        y() +=.01:REM yaw (rotations around the Y axis)
        REM pitch
        p() =0:REM TIME/100 (pitch angles rotations around the X axis)
        REM roll
        r() = 0:REM TIME/40 (roll angles (rotations around the Z axis)
        REM X (right left)
        X() = 0:REM SIN(TIME/200)
        REM Y() up and down
        Y() = 0
        REM Z() depth
        Z() =  10:REM
  
        REM PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000)
        PROC_render(d%, &FF7F7F7F, 0, l%(), 2, m%(), t%(), b%(), n%(), f%(), s%(), y(), p(), r(), X(), Y(), Z(), e(), a(), PI/4, 5/4, 1, 1000, 0) :REM experimental
        REM          1     2       3   4    5   6     7     8     9     10    11   yaw pitch roll X    Y    Z eye0123  18   19   20   ^mcd  ^( cam to farplane dist)
        REM 1 Val returned from FN_init3D
        REM 2 back color   3 #of lights   4 light pointers
        REM t%() - holds texture
        REM mcd - minimum near cam distance
  
  WAIT 1
      UNTIL FALSE
      END

      DEF PROCcleanup
      t%(1) += 0:IF t%(1) PROC_release(t%(1))
      b%(0) += 0:IF b%(0) PROC_release(b%(0))
      b%(1) += 0:IF b%(1) PROC_release(b%(1))
      d% += 0   :IF d%    PROC_release(d%)
      ENDPROC
      DEF PROCcreate3d
      F% = OPENOUT"TRIANGLE.B3D"
      PROC4(6):REM 3 vertices
      PROC4(&100042):REM vertex size &10 and format &42
      REM       LL x            LL y            LL z
      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM PROC4(&FFFF0000)

      PROC4(FN_f4(-1.0)):PROC4(FN_f4(-1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM PROC4(&FF0000FF)
      REM       LR x            LR y            LR z
      PROC4(FN_f4(-1)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM PROC4(&FF00FF00)
      REM     PEAK X     PEAK Y             PEAK Z
      PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(FN_f4(1.0)):PROC4(&FF0000FF):REM PROC4(&FFFF0000)

      CLOSE #F%
      ENDPROC
      DEF PROC4(A%):BPUT#F%,A%:BPUT#F%,A%>>8:BPUT#F%,A%>>16:BPUT#F%,A%>>24:ENDPROC