home *** CD-ROM | disk | FTP | other *** search
/ Amiga ISO Collection / AmigaUtilCD2.iso / Programming / Basic / OTL-BBU3.DMS / in.adf / EXAMPLES / BMAN.DOC < prev    next >
Encoding:
Text File  |  1993-10-07  |  6.4 KB  |  151 lines

  1. Do the BlitzMan...
  2.  
  3. Reprinted from the magazine Amiga Down Under
  4.  
  5. Things have been going absolutely mental in the office over the last 
  6. few weeks. This article is some two weeks past deadline, the latest 
  7. Blitz2 upgrade BUM5 is still not finished, SkidMarks release has 
  8. been put off till the end of November due to too many perfectionists 
  9. and not enough "let's just release it" types...
  10.  
  11. Anyway, the good news is that Blitz2 now features GadTools and ASL 
  12. support as well as a whole heap of new AGA commands to keep everyone 
  13. happy. We're launching in the U.K. this month with what could be 
  14. termed the promotional coup of the decade. All in all it's looking 
  15. like the long hard years of work are starting to pay off.
  16.  
  17. Dance BlitzMan, Dance!
  18.  
  19. The wireframe editor in this month's column is an excellent 
  20. introduction to using recursion to process 2 dimensional linked 
  21. lists. The wireframe objects are drawn the same way as a fractal 
  22. tree generator I included in issue 2 of ADU. 
  23.  
  24. The editor allows you to change the angle of any branch in the 
  25. object so BlitzMan can be quickly redrawn in any position. Just 
  26. select any of his pivot points such as a knee with the pointer, 
  27. then holding the left button down drag the mouse left or right. 
  28. These two directions give you the ability to make either 
  29. clockwise or anticlockwise adjustments to his limbs, torso and head.
  30.  
  31. The 16 square boxes on the right can each hold a different frame 
  32. so you can position BlitzMan in a series of positions. I also 
  33. included some Med commands so you can play a module to accompany 
  34. BlitzMan strutting his stuff. At the moment it's all manual, if 
  35. I get some time an automatic boogey mode will be added to work 
  36. either with the Med player or with a sampler so he can dance 
  37. to the stereo. The ability to save frames, edit number and 
  38. length of limbs etc. is also rather lacking in v0.0, Acid 
  39. Software is pretty hectic at the moment so I'm not making 
  40. any promises.
  41.  
  42. The double linked list.
  43.  
  44. The .seg NewType has two pointers to other .segs, a kid and 
  45. a bro. All segs linked by their bro field share the same parent. 
  46. The kid field is used to link the seg to it's offspring 
  47. (any segs that branch off).
  48.  
  49. A diagram of this system not suprisingly looks just like a 
  50. family tree (a very patriarcal one at that!). The data 
  51. field at the end of the listing holds all the information 
  52. about BlitzMan and his default position.
  53.  
  54. The thigh bone's connected to the leg bone...
  55.  
  56. The origin of the shape is the central pivot point, in BlitzMan's 
  57. case it is his torso. If you grab his torso in the editor you 
  58. can rotate his whole body around. 
  59.  
  60. The torso's kid field points to a thigh, it's bro's are the other 
  61. thigh and the back.
  62.  
  63. The readfigure{} routine read's the information from the data 
  64. table into a series of segs linking them up as necessary. All the 
  65. routine's in the listing are recursive in nature. If we were to 
  66. trace through the routine it would read somthing like:
  67.  
  68. 1. Read the seg from the data table (angle length and number of kids)
  69.  
  70. 2. For each kid go back to step 1
  71.  
  72. 3. Link all the kids added in 2 to current seg via it's kid pointer
  73.  
  74. Hmm, only 3 steps, pretty simple. But aren't some of the kids going 
  75. to have kids? No problems, the wonders of recursion will sort that 
  76. out for us because each time we go back to step 1, our current 
  77. position in the logic chart is pushed on the stack. This means the 
  78. computer can return to that position after all the kid's kids 
  79. have stopped having kids!
  80.  
  81. Putting pen to paper.
  82.  
  83. The drawfigure{} routine uses the same recursion method as the 
  84. readfigure{} except of course instead of connecting the pointers 
  85. it merely has to follow them. The other great thing about recursive 
  86. routines is that local variables are restored after the program 
  87. has gone away and dealt to the kids.
  88.  
  89. The wireframe models all use delta angles to represent what orientation 
  90. each limb is on. This in effect means that instead of recording BlitzMan's 
  91. foot as pointing up we reach the same conclusion because we know 
  92. instead that his foot is on a 30 degrees angle to his lower leg which 
  93. is at such and such an angle to his upper leg. The angles are all 
  94. local not global (as used in Imagine terminology). As variables 
  95. in Blitz2 Statements are automatically classed as local implementing 
  96. this system is quite simple. 
  97.  
  98. The variables aa, xx and yy are used to compound the angle and 
  99. position of each limb. By storing these values in the seg's x,y 
  100. and a fields the following editing routine can zip through all 
  101. the segments checking where the draw command actually located 
  102. each point.  
  103.  
  104. Locating a limb...
  105.  
  106. As I just mentioned, the drawfigure{} routine also records the 
  107. screen location of each seg. Thus, the routine to find which 
  108. seg the mouse is pointing at simply needs to recursively 
  109. traverse (thats a good word isn't it) the list checking to 
  110. see if the pointer is anywhere near that location.
  111.  
  112. The only problem I found was how to exit the function once a hit had been recorded, my implementation is a little cludgey if an
  113. e can help (good programmers have to be perfectionists).
  114.  
  115.  
  116. Then there's the user interface...
  117.  
  118. A quick explanation of the rest of the program is probably in order. 
  119. As usual I have attempted to add as many comments as possible so the 
  120. code is self explanatory where ever possible.
  121.  
  122. The angles 0 to 255 correspond to 0 to 360 degrees. A negative length 
  123. for any seg means the editor will draw a circle not a line at that 
  124. position. 
  125.  
  126. Blitz programmers will need no introduction to Menus, Gadgets and 
  127. Windows. For those Amos programmers out there, these are what proper 
  128. Amiga programmers use to build applications with. However, I must 
  129. admit that the use of PropGadgets is pretty darn crude for the frames, 
  130. a blank BoxGadget has been added in BUM5 for such effects.
  131.  
  132. In fact it look's as though I've already run out of space, drop me 
  133. a note care of ADU if you want me to send you the tween{} routine. 
  134. This draws any inbetween frame allowing BlitzMan to smoothly animate 
  135. between one pose and the next. I'll leave you with a data list for 
  136. BlitzMan's horse.
  137.  
  138. .horsedata
  139.   Data.w 3,0,0           ;origin (bum)
  140.     Data.w 1,32,40       ;back right thigh
  141.       Data.w 0,48,40     ;back right calf
  142.     Data.w 1,96,40       ;back left thigh
  143.       Data.w 0,-48,40    ;back left calf
  144.     Data.w 3,0,60        ;back bone 
  145.       Data.w 1,32,40     ;front right thigh
  146.         Data.w 0,48,40   ;front right calf
  147.       Data.w 1,96,40     ;front left thigh
  148.         Data.w 0,-48,40  ;front left calf
  149.       Data.w 1,-32,40    ;neck
  150.         Data.w 0,128,-12 ;head
  151.