home *** CD-ROM | disk | FTP | other *** search
/ DTP Toolbox / DTPToolbox.iso / utilities / propage_pdraw / donsgenies / adproscripts.lha / AnimCube.adpro next >
Encoding:
Text File  |  1995-08-11  |  12.4 KB  |  421 lines

  1. /* Program to use ADPro to put images on the faces of a revolving cube. Needs rexxmathlib.library. Any anim file or any still image that can be recognised by the Universal loader may be used for the background and the six sides (seven image files altogether). To leave a side blank, simply click on "Forget it" when asked for the file name. Black areas in the images are transparent; to prevent this, use the Dynamic Range command and set the minimum to 1 instead of 0; or, for an anim, load it into DPaint and change black in the palette to dark grey.   */
  2.  
  3. /* $VER:AnimCube August 95 */
  4.  
  5. /* Careful - can make a very large trace file */
  6. /*call open("STDERR","ram:traceAC","W")
  7. trace r*/
  8.  
  9. address "ADPro"
  10.  
  11. if ~show("l", "rexxmathlib.library") then
  12.     if ~addlib("rexxmathlib.library", 0, -30,0) then
  13.     do
  14.         OKAY1 "Please install the rexxmathlib.library in your libs: directory before running this script."
  15.         exit
  16.         end
  17.  
  18. AA=6.2831853/360    /* 2pi divided by 360 */
  19.  
  20. OPTIONS RESULTS
  21.  
  22.  
  23. /* Use the current screen format and number of colours. */
  24. render_type
  25. colours = ADPro_result
  26. screen_type
  27. stype = ADPro_result
  28.  
  29.  
  30. getnumber '"Output width (pixels)"' 320 16 1280
  31. if rc~=0 then do
  32.     okay1 "User aborted program"
  33.     exit
  34.     end
  35. outwidth = ADPro_result
  36.  
  37. getnumber '"Output height (pixels)"' 256 16 1024
  38. if rc~=0 then do
  39.     okay1 "User aborted program"
  40.     exit
  41.     end
  42. outheight = ADPro_result
  43.  
  44. picsize = min(outwidth,outheight)
  45. picsize2 = max(outwidth,outheight)
  46. Xoffset = (outwidth-picsize)/2  /* for centring the cube in the display */
  47. Yoffset = (picsize2-outwidth)/2
  48.  
  49. /* These defaults could be changed to give different angles of view. */
  50. flength = 175  /* focal length */
  51. cameraY = 400
  52. cameraX = 0
  53. cameraZ = picsize*3
  54. lookatX = 0
  55. lookatY = -(picsize/4)
  56. lookatZ = -(picsize/2)
  57.  
  58.  
  59. sides.0 = "BACKGROUND"
  60. sides.1 = "FRONT"
  61. sides.2 = "RIGHT"
  62. sides.3 = "LEFT"
  63. sides.4 = "BACK"
  64. sides.5 = "TOP"
  65. sides.6 = "BOTTOM"
  66.  
  67.  
  68. getdir '"Select directory for temporary files"' "ADPro:"
  69. if rc ~= 0 then outdir = "ADPro:"
  70. else outdir = ADPro_result
  71.  
  72. getfile '"Select output anim file ..."' "ADPro:" '""'
  73. if rc~=0 then do
  74.     okay1 '"No output file selected"'
  75.     exit
  76.     end
  77.  
  78. outfile = ADPro_result
  79.  
  80. getnumber '"How many Frames?"' 36 3 1024
  81. if rc~=0 then do
  82.     okay1 '"User aborted program"'
  83.     exit
  84.     end
  85. numframes = ADPro_result
  86.  
  87.  
  88. /* Initialize the compound variables  */
  89. filename. = outdir||"temp.black"
  90. loadformat. = "UNIVERSAL"
  91. still. = 1
  92. framecount. = 1
  93. selected. = 0   /* for blanking undefined sides */
  94. filecount = 0
  95.  
  96. do s = 0 to 6 /* get the filenames for all the sides & the background */
  97.     side = sides.s
  98.     "GETFILE" '"Select 'side' image file ..."' /* Note the quotes! */
  99.     if rc=0 then do
  100.         filecount = filecount+1
  101.         selected.side = 1
  102.         filename.side = ADPro_result
  103.         call open("input",filename.side,"R")
  104.         filetype = right(readch("input",12),4)
  105.             if filetype = "ANIM" then do
  106.             loadformat.side = "ANIM"
  107.             still.side = 0
  108.             end
  109.         call close("input")
  110.         end
  111.     end
  112.  
  113. if filecount = 0 then do
  114.     OKAY1 "'No file selected'"
  115.     exit
  116.     end
  117.  
  118.  
  119. sformat "IFF"  /* make a couple of blank black images */
  120. lformat "BACKDROP"
  121. load "XXX" picsize picsize "COLOR"
  122. save outdir||"temp.black" "RAW"
  123. load "XXX" outwidth outheight "COLOR"
  124. save outdir||"temp.black2" "RAW"
  125. lformat "UNIVERSAL"
  126.  
  127.  
  128. load_type "REPLACE"
  129.  
  130. if still.background = 1 then do
  131.     "LOAD "||filename.background
  132.     ABS_SCALE outwidth outheight
  133.     save outdir||"temp.background.pic" "RAW"
  134.     end
  135.  
  136.  
  137. do s = 1 to 6   /* crop still images to square, & scale to uniform size */
  138.     side = sides.s
  139.     if still.side = 1 then do
  140.         infile = filename.side
  141.         call cropandscale
  142.         end
  143.     end
  144.  
  145.  
  146. do f = 1 to numframes
  147.  
  148.     i = (360/numframes)*f
  149.  
  150.     phaseangle.front = (i+360)//360
  151.     phaseangle.right = (i+90)//360
  152.     phaseangle.left = (i+270)//360
  153.     phaseangle.back = (i+180)//360
  154.  
  155.     do s = 1 to 4
  156.         side = sides.s
  157.         if selected.side ~=0 then do
  158.             radangle.side = phaseangle.side*AA
  159.             gammaangle.side = phaseangle.side+270
  160.             Zmoves.side.value = trunc(sin(radangle.side)*lookatZ)
  161.             Zmoves.side.pic = outdir||"temp."||side||".pers.pic"
  162.             lookatZZ.side = lookatZ+Zmoves.side.value
  163.             cameraZZ.side = cameraZ+Zmoves.side.value
  164.             Xmoves.side = (trunc(cos(radangle.side)*lookatZ))
  165.             cameraXX.side = cameraX+Xmoves.side
  166.             lookatXX.side = lookatX+Xmoves.side
  167.             cameraYY.side = cameraY
  168.             lookatYY.side = lookatY
  169.             end
  170.         else if selected.side = 0 then do
  171.             Zmoves.side.pic = outdir||"temp.black2"
  172.             Zmoves.side.value = 0
  173.             end
  174.         end
  175.  
  176.  
  177.     if selected.top ~=0 then do
  178.         Zmoves.top.value = 0  /* top & bottom are different */
  179.         Zmoves.top.pic = outdir||"temp.top.pers.pic"
  180.         lookatZZ.top = lookatZ+Zmoves.top.value
  181.         cameraZZ.top = cameraZ+Zmoves.top.value
  182.         Xmoves.top = 0
  183.         cameraXX.top = cameraX+Xmoves.top
  184.         lookatXX.top = lookatX+Xmoves.top
  185.         cameraYY.top = cameraY-(picsize/2)
  186.         lookatYY.top = lookatY-(picsize/2)
  187.         end
  188.     else if selected.top = 0 then do
  189.         Zmoves.top.pic = outdir||"temp.black2"
  190.         Zmoves.top.value = 0
  191.         end
  192.  
  193.  
  194.     if selected.bottom ~=0 then do
  195.         Zmoves.bottom.value = 0
  196.         Zmoves.bottom.pic = outdir||"temp.bottom.pers.pic"
  197.         lookatZZ.bottom = lookatZ+Zmoves.bottom.value
  198.         cameraZZ.bottom = cameraZ+Zmoves.bottom.value
  199.         Xmoves.bottom = 0
  200.         cameraXX.bottom = cameraX+Xmoves.bottom
  201.         lookatXX.bottom = lookatX+Xmoves.bottom
  202.         cameraYY.bottom = cameraY+(picsize/2)
  203.         lookatYY.bottom = lookatY+(picsize/2)
  204.         end
  205.     else if selected.bottom = 0 then do
  206.         Zmoves.bottom.pic = outdir||"temp.black2"
  207.         Zmoves.bottom.value = 0
  208.         end
  209.  
  210.  
  211. /* Sort faces into front-to-back order */
  212.  
  213. do j=1 to 6
  214.     select
  215.         when zmoves.front.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  216.             zfv = zmoves.front.value /* for program tracing */
  217.             zmoves.front.value = -70000
  218.             zmoves.front.order = j
  219.             end
  220.         when zmoves.right.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  221.             zrv = zmoves.right.value
  222.             zmoves.right.value = -70000
  223.             zmoves.right.order = j
  224.             end
  225.         when zmoves.left.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  226.             zlv = zmoves.left.value
  227.             zmoves.left.value = -70000
  228.             zmoves.left.order = j
  229.             end
  230.         when zmoves.back.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  231.             zbv = zmoves.back.value
  232.             zmoves.back.value = -70000
  233.             zmoves.back.order = j
  234.             end
  235.         when zmoves.top.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  236.             ztv = zmoves.top.value
  237.             zmoves.top.value = -70000
  238.             zmoves.top.order = j
  239.             end
  240.         when zmoves.bottom.value = max(zmoves.front.value, zmoves.right.value, zmoves.back.value, zmoves.left.value, zmoves.top.value, zmoves.bottom.value) then do
  241.             zmv = zmoves.bottom.value
  242.             zmoves.bottom.value = -7000
  243.             zmoves.bottom.order = j
  244.             end
  245.         otherwise NOP
  246.         end
  247.     end
  248.  
  249.  
  250.     load_type "REPLACE"
  251.  
  252. do s = 1 to 4     /* now the perspective rendering */
  253.     side = sides.s
  254.     if selected.side ~=0 then do
  255.         call imageload
  256.  
  257.         operator "PERSPECTIVE", 
  258.             "ROTATE_CENTER",
  259.             "FOCAL_LENGTH" flength,
  260.             "CAMERA_POSITION" cameraXX.side cameraYY.side cameraZZ.side,
  261.             "LOOKAT_POINT" lookatXX.side lookatYY.side lookatZZ.side,
  262.             "OUTPUT_SIZE" outwidth outheight,
  263.             "OUTPUT_OFFSET" Xoffset Yoffset,
  264.             "GAMMA" gammaangle.side
  265.  
  266.         sformat "IFF"
  267.         save Zmoves.side.pic "RAW"
  268.         tester = rc
  269.         errormessage = ADPRO_RESULT
  270.         end
  271.  
  272.     end  /* of 4 sides */
  273.  
  274.  
  275.     if selected.top ~=0 then do
  276.         side = "TOP"
  277.         call imageload
  278.  
  279.         rotangle = 360-i
  280.  
  281.         operator "PERSPECTIVE",
  282.             "ROTATE_CENTER",
  283.             "FOCAL_LENGTH" flength,
  284.             "CAMERA_POSITION" cameraXX.top cameraYY.top cameraZZ.top,
  285.             "LOOKAT_POINT" lookatXX.top lookatYY.top lookatZZ.top,
  286.             "OUTPUT_SIZE" outwidth outheight,
  287.             "OUTPUT_OFFSET" Xoffset Yoffset,
  288.             "PHI" 90,
  289.             "THETA" rotangle
  290.  
  291.         sformat "IFF"
  292.         save Zmoves.top.pic "RAW"
  293.         tester = rc
  294.         errormessage = ADPRO_RESULT
  295.         end
  296.  
  297.  
  298.     if selected.bottom ~=0 then do
  299.         side = "BOTTOM"
  300.         call imageload
  301.  
  302.         operator "PERSPECTIVE",
  303.             "ROTATE_CENTER",
  304.             "FOCAL_LENGTH" flength,
  305.             "CAMERA_POSITION" cameraXX.bottom cameraYY.bottom cameraZZ.bottom,
  306.             "LOOKAT_POINT" lookatXX.bottom lookatYY.bottom lookatZZ.bottom,
  307.             "OUTPUT_SIZE" outwidth outheight,
  308.             "OUTPUT_OFFSET" Xoffset Yoffset,
  309.             "PHI" 270,
  310.             "THETA" i
  311.  
  312.         sformat "IFF"
  313.         save Zmoves.bottom.pic "RAW"
  314.         tester = rc
  315.         errormessage = ADPRO_RESULT
  316.         end
  317.  
  318.  
  319. /* Assemble the background and six renders into one image */
  320.  
  321.     loadtype "REPLACE"
  322.  
  323.     if selected.background ~=0 then do
  324.         side = "BACKGROUND"
  325.         call imageload
  326.         if still.background = 0 then ABS_SCALE outwidth outheight /* anim frame must be scaled, but NOT cropped */
  327.         end
  328.     else if selected.background = 0 then do
  329.         lformat "IFF"
  330.         load outdir||"temp.black2"
  331.         end
  332.  
  333.     load_type "COMPOSE"  /* now bring back the other pictures */
  334.     lformat "IFF"
  335.  
  336.     load Zmoves.bottom.pic "0 0 100 0 0 0" /* always first if we are looking down */
  337.     tester = rc
  338.     errormessage = ADPRO_RESULT
  339.     do m = 1 to 6
  340.         select
  341.             when Zmoves.front.order = m then load Zmoves.front.pic "0 0 100 0 0 0"
  342.             when Zmoves.right.order = m then load Zmoves.right.pic "0 0 100 0 0 0"
  343.             when Zmoves.back.order = m then load Zmoves.back.pic "0 0 100 0 0 0"
  344.             when Zmoves.left.order = m then load Zmoves.left.pic "0 0 100 0 0 0"
  345.             otherwise NOP
  346.             end
  347.         end
  348.     load Zmoves.top.pic "0 0 100 0 0 0" /* always last if we are looking down */
  349.     tester = rc
  350.     errormessage = ADPRO_RESULT
  351.  
  352.     render_type colours   /* number of colours  */
  353.     screen_type stype  /* PAL/NTSC, overscan, etc */
  354.     execute
  355.     sformat "ANIM"
  356.     save outfile "IMAGE" "APPEND" "SMALLER" "LONG" /* LONG gives Anim-8 format */
  357.  
  358.     end
  359.  
  360. sformat "ANIM"
  361. save outfile "IMAGE" "WRAPUP"  /* looping closedown */
  362. tester = rc
  363. errormessage = ADPRO_RESULT
  364.  
  365. lformat "UNIVERSAL"
  366. load_type "REPLACE"
  367. okay1 "Finished ..."
  368. exit
  369.  
  370.  
  371. /* +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ */
  372.  
  373. cropandscale:
  374.  
  375. if infile = "ADPro:temp.black" then return
  376. if still.side = 0 then return
  377. "LOAD "||infile
  378. XSIZE
  379. width = ADPRO_RESULT
  380. YSIZE
  381. height = ADPRO_RESULT
  382. if width>height then OPERATOR "CROP_IMAGE" height height (width-height)/2 0
  383. if height>width then OPERATOR "CROP_IMAGE" width width (height-width)/2 0
  384. ABS_SCALE picsize picsize
  385. save outdir||"temp."||side||".pic" "RAW"
  386.  
  387. return
  388.  
  389.  
  390. cropandscaleframe:
  391. XSIZE
  392. width = ADPRO_RESULT
  393. YSIZE
  394. height = ADPRO_RESULT
  395. if width>height then OPERATOR "CROP_IMAGE" height height (width-height)/2 0
  396. if height>width then OPERATOR "CROP_IMAGE" width width (height-width)/2 0
  397. ABS_SCALE picsize picsize
  398.  
  399. return
  400.  
  401.  
  402. imageload:
  403. lformat loadformat.side  /* set load format for file */
  404. if still.side = 0 then do /* load new anim frames */
  405.     load filename.side "FRAME" framecount.side
  406.     if rc ~=0 then do   /* run out of frames? */
  407.         framecount.side = 3  /* loop the anim; if your anims are non-looping, this should be 1 not 3. */
  408.         load filename.side "FRAME" framecount.side
  409.         if rc ~=0 then leave f /* real dud load */
  410.         end
  411.     if side ~= "BACKGROUND" then call cropandscaleframe
  412.     framecount.side = framecount.side+1
  413.     end
  414.  
  415. else if still.side = 1 then do  /* still picture */
  416.     load outdir||"temp."||side||".pic"
  417.     end
  418.  
  419. return
  420.  
  421.