home *** CD-ROM | disk | FTP | other *** search
- Do the BlitzMan...
-
- Reprinted from the magazine Amiga Down Under
-
- Things have been going absolutely mental in the office over the last
- few weeks. This article is some two weeks past deadline, the latest
- Blitz2 upgrade BUM5 is still not finished, SkidMarks release has
- been put off till the end of November due to too many perfectionists
- and not enough "let's just release it" types...
-
- Anyway, the good news is that Blitz2 now features GadTools and ASL
- support as well as a whole heap of new AGA commands to keep everyone
- happy. We're launching in the U.K. this month with what could be
- termed the promotional coup of the decade. All in all it's looking
- like the long hard years of work are starting to pay off.
-
- Dance BlitzMan, Dance!
-
- The wireframe editor in this month's column is an excellent
- introduction to using recursion to process 2 dimensional linked
- lists. The wireframe objects are drawn the same way as a fractal
- tree generator I included in issue 2 of ADU.
-
- The editor allows you to change the angle of any branch in the
- object so BlitzMan can be quickly redrawn in any position. Just
- select any of his pivot points such as a knee with the pointer,
- then holding the left button down drag the mouse left or right.
- These two directions give you the ability to make either
- clockwise or anticlockwise adjustments to his limbs, torso and head.
-
- The 16 square boxes on the right can each hold a different frame
- so you can position BlitzMan in a series of positions. I also
- included some Med commands so you can play a module to accompany
- BlitzMan strutting his stuff. At the moment it's all manual, if
- I get some time an automatic boogey mode will be added to work
- either with the Med player or with a sampler so he can dance
- to the stereo. The ability to save frames, edit number and
- length of limbs etc. is also rather lacking in v0.0, Acid
- Software is pretty hectic at the moment so I'm not making
- any promises.
-
- The double linked list.
-
- The .seg NewType has two pointers to other .segs, a kid and
- a bro. All segs linked by their bro field share the same parent.
- The kid field is used to link the seg to it's offspring
- (any segs that branch off).
-
- A diagram of this system not suprisingly looks just like a
- family tree (a very patriarcal one at that!). The data
- field at the end of the listing holds all the information
- about BlitzMan and his default position.
-
- The thigh bone's connected to the leg bone...
-
- The origin of the shape is the central pivot point, in BlitzMan's
- case it is his torso. If you grab his torso in the editor you
- can rotate his whole body around.
-
- The torso's kid field points to a thigh, it's bro's are the other
- thigh and the back.
-
- The readfigure{} routine read's the information from the data
- table into a series of segs linking them up as necessary. All the
- routine's in the listing are recursive in nature. If we were to
- trace through the routine it would read somthing like:
-
- 1. Read the seg from the data table (angle length and number of kids)
-
- 2. For each kid go back to step 1
-
- 3. Link all the kids added in 2 to current seg via it's kid pointer
-
- Hmm, only 3 steps, pretty simple. But aren't some of the kids going
- to have kids? No problems, the wonders of recursion will sort that
- out for us because each time we go back to step 1, our current
- position in the logic chart is pushed on the stack. This means the
- computer can return to that position after all the kid's kids
- have stopped having kids!
-
- Putting pen to paper.
-
- The drawfigure{} routine uses the same recursion method as the
- readfigure{} except of course instead of connecting the pointers
- it merely has to follow them. The other great thing about recursive
- routines is that local variables are restored after the program
- has gone away and dealt to the kids.
-
- The wireframe models all use delta angles to represent what orientation
- each limb is on. This in effect means that instead of recording BlitzMan's
- foot as pointing up we reach the same conclusion because we know
- instead that his foot is on a 30 degrees angle to his lower leg which
- is at such and such an angle to his upper leg. The angles are all
- local not global (as used in Imagine terminology). As variables
- in Blitz2 Statements are automatically classed as local implementing
- this system is quite simple.
-
- The variables aa, xx and yy are used to compound the angle and
- position of each limb. By storing these values in the seg's x,y
- and a fields the following editing routine can zip through all
- the segments checking where the draw command actually located
- each point.
-
- Locating a limb...
-
- As I just mentioned, the drawfigure{} routine also records the
- screen location of each seg. Thus, the routine to find which
- seg the mouse is pointing at simply needs to recursively
- traverse (thats a good word isn't it) the list checking to
- see if the pointer is anywhere near that location.
-
- 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
- e can help (good programmers have to be perfectionists).
-
-
- Then there's the user interface...
-
- A quick explanation of the rest of the program is probably in order.
- As usual I have attempted to add as many comments as possible so the
- code is self explanatory where ever possible.
-
- The angles 0 to 255 correspond to 0 to 360 degrees. A negative length
- for any seg means the editor will draw a circle not a line at that
- position.
-
- Blitz programmers will need no introduction to Menus, Gadgets and
- Windows. For those Amos programmers out there, these are what proper
- Amiga programmers use to build applications with. However, I must
- admit that the use of PropGadgets is pretty darn crude for the frames,
- a blank BoxGadget has been added in BUM5 for such effects.
-
- In fact it look's as though I've already run out of space, drop me
- a note care of ADU if you want me to send you the tween{} routine.
- This draws any inbetween frame allowing BlitzMan to smoothly animate
- between one pose and the next. I'll leave you with a data list for
- BlitzMan's horse.
-
- .horsedata
- Data.w 3,0,0 ;origin (bum)
- Data.w 1,32,40 ;back right thigh
- Data.w 0,48,40 ;back right calf
- Data.w 1,96,40 ;back left thigh
- Data.w 0,-48,40 ;back left calf
- Data.w 3,0,60 ;back bone
- Data.w 1,32,40 ;front right thigh
- Data.w 0,48,40 ;front right calf
- Data.w 1,96,40 ;front left thigh
- Data.w 0,-48,40 ;front left calf
- Data.w 1,-32,40 ;neck
- Data.w 0,128,-12 ;head
-