home *** CD-ROM | disk | FTP | other *** search
/ Crawly Crypt Collection 2 / crawlyvol2.bin / graphics / atsirds / atsirdsm.lst < prev    next >
File List  |  1994-08-10  |  4KB  |  164 lines

  1. ' **** Atari SIRDS program v2.0 ****
  2. '    routine from the SIRDS FAQ
  3. ' 640x400 monochrome display version
  4. '
  5. ' read *.red (raw) file into thedepth array
  6. ' write *.pic mono screen file
  7. '
  8. bkdepth%=-800             ! depth of background in pixels
  9. e%=180                    ! eye separation in pixels
  10. o%=700                    ! observer-screen distance in pixels
  11. oversam%=1                ! oversampling ratio -- can be 1, 2, 4, 6
  12. dohiddenrem!=FALSE        ! enable/disable SLOW hidden point removal
  13. xres%=640                 ! width of the picture in pixels
  14. yres%=390                 ! height of picture in pixels
  15. numcolors%=2
  16. '
  17. DIM thedepth|(xres%*yres%)
  18. depthofs%=VARPTR(thedepth|(0))
  19. DIM link%(xres%*oversam%)
  20. DIM pixels%(xres%*oversam%)
  21. DIM z%(xres%)
  22. '
  23. FILESELECT "\*.red","",dep$
  24. IF dep$=""
  25.   END
  26. ENDIF
  27. PRINT "Input RAW depth file: ";dep$
  28. OPEN "i",#1,dep$
  29. BGET #1,depthofs%,xres%*yres%
  30. CLOSE #1
  31. '
  32. PRINT "Res. ";xres%;"x";yres%;", ";numcolors%;" colors, ";
  33. IF oversam%=1
  34.   PRINT "no oversampling";
  35. ELSE
  36.   PRINT oversam%;" times oversampling";
  37. ENDIF
  38. IF dohiddenrem!
  39.   PRINT ", hidden point removal."
  40. ELSE
  41.   PRINT "."
  42. ENDIF
  43. CLS
  44. init_sirds
  45. do_sirds
  46. PRINT CHR$(7);
  47. '
  48. FILESELECT "\*.pic","",sir$
  49. IF sir$=""
  50.   END
  51. ENDIF
  52. BSAVE sir$,XBIOS(2),32000
  53. END
  54. '
  55. '
  56. '
  57. PROCEDURE init_sirds
  58.   ' add "help lines"
  59.   LOCAL x%,y%,helpdist,th%
  60.   helpdist=ABS(bkdepth%)*e%/(2*(ABS(bkdepth%)+o%))
  61.   th%=0
  62.   FOR y%=9 DOWNTO 0
  63.     FOR x%=xres%/2-helpdist-th% TO xres%/2-helpdist+th%
  64.       PLOT x%,y%
  65.     NEXT x%
  66.     FOR x%=xres%/2+helpdist-th% TO xres%/2+helpdist+th%
  67.       PLOT x%,y%
  68.     NEXT x%
  69.     INC th%
  70.   NEXT y%
  71. RETURN
  72. '
  73. PROCEDURE do_sirds
  74.   ' render the SIRDS
  75.   LOCAL x%,y%,h%,u%,dx%,c%,xx%,highest%,separation%,left%,right%,pp%,v,visible!
  76.   FOR y%=0 TO yres%-1
  77.     FOR x%=0 TO xres%*oversam%-1
  78.       link%(x%)=x%
  79.     NEXT x%
  80.     highest%=bkdepth%
  81.     FOR x%=0 TO xres%-1
  82.       ' h%=bkdepth%+128+63*(SIN(x%/70*PI)+COS(y%/70*PI))
  83.       h%=bkdepth%+thedepth|(y%*xres%+x%)
  84.       z%(x%)=h%
  85.       IF h%>highest%
  86.         highest%=h%
  87.       ENDIF
  88.     NEXT x%
  89.     FOR x%=0 TO xres%*oversam%-1
  90.       separation%=(e%*oversam%*z%(x%/oversam%))/(z%(x%/oversam%)-o%)
  91.       left%=x%-separation%/2
  92.       right%=left%+separation%
  93.       IF (left%>=0) AND (right%<xres%*oversam%)
  94.         visible!=TRUE
  95.         IF dohiddenrem!
  96.           v=2*(o%-z%(x%/oversam%))/e%
  97.           dx%=1
  98.           REPEAT
  99.             u%=z%(x%/oversam%)+dx%*v
  100.             IF (z%((x%+dx%)/oversam%)>=u%) OR (z%((x%-dx%)/oversam%)>=u%)
  101.               visible!=FALSE
  102.             ENDIF
  103.             INC dx%
  104.           UNTIL (u%>highest%) OR (NOT visible!)
  105.         ENDIF
  106.         IF visible!
  107.           link%(right%)=left%
  108.         ENDIF
  109.       ENDIF
  110.     NEXT x%
  111.     pp%=0
  112.     FOR x%=0 TO xres%*oversam%-1
  113.       IF link%(x%)=x%
  114.         IF (pp% MOD oversam%)=0
  115.           c%=RANDOM(numcolors%)
  116.         ENDIF
  117.         pixels%(x%)=c%
  118.         INC pp%
  119.       ELSE
  120.         pixels%(x%)=pixels%(link%(x%))
  121.       ENDIF
  122.     NEXT x%
  123.     FOR x%=0 TO xres%-1
  124.       xx%=x%*oversam%
  125.       SELECT oversam%
  126.       CASE 1
  127.         c%=pixels%(xx%)
  128.       CASE 2
  129.         IF (x%>0) AND (x%<xres%-1)
  130.           c%=pixels%(xx%)*42+(pixels%(xx%-1)+pixels%(xx%+1))*24
  131.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*5
  132.           c%=c%/100
  133.         ELSE
  134.           c%=pixels%(xx%)
  135.         ENDIF
  136.       CASE 4
  137.         IF (x%>0) AND (x%<xres%-1)
  138.           c%=pixels%(xx%)*26+(pixels%(xx%-1)+pixels%(xx%+1))*18
  139.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*12
  140.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*7
  141.           c%=c%/100
  142.         ELSE
  143.           c%=pixels%(xx%)
  144.         ENDIF
  145.       CASE 6
  146.         IF (x%>0) AND (x%<xres%-1)
  147.           c%=pixels%(xx%)*14+(pixels%(xx%-1)+pixels%(xx%+1))*14
  148.           c%=c%+(pixels%(xx%-2)+pixels%(xx%+2))*11
  149.           c%=c%+(pixels%(xx%-3)+pixels%(xx%+3))*8
  150.           c%=c%+(pixels%(xx%-4)+pixels%(xx%+4))*5
  151.           c%=c%+(pixels%(xx%-5)+pixels%(xx%+5))*3
  152.           c%=c%+(pixels%(xx%-6)+pixels%(xx%+6))*2
  153.           c%=c%/100
  154.         ELSE
  155.           c%=pixels%(xx%)
  156.         ENDIF
  157.       ENDSELECT
  158.       IF c%=0
  159.         PLOT x%,y%+10
  160.       ENDIF
  161.     NEXT x%
  162.   NEXT y%
  163. RETURN
  164.