home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / OTMORPH.ZIP / morphing.doc < prev    next >
Text File  |  1996-06-06  |  6KB  |  130 lines

  1.  
  2.                      - THE OUTLAW TRIAD DEMO-SERIES -
  3.  
  4. ────────────────────────────────■ PART VI ■───────────────────────────────────
  5.  
  6.                          Written by : Vulture/OT
  7.                          Code in    : Pascal/Asm
  8.                          Topic      : 3d morphing
  9.  
  10. ──────────────────────────────■ Introduction ■───────────────────────────────
  11.  
  12.  Welcome to the Outlaw Triad demo-series! In these series we will be talking
  13.  about programming demo-effects in either pascal or assembler. Theory behind
  14.  the effects shall be discussed while a full sourcecode is also provided.
  15.  This time we'll discuss 3d morphing. This type of morphing involves a 3d
  16.  object changing into another 3d object. The example pascalsource rotates
  17.  and morphs a number of 3d points and was coded in Pascal. Enjoy!
  18.  
  19. ─────────────────────────────────■ Theory ■──────────────────────────────────
  20.  
  21.  What does morphing mean exactly? Like said in the introduction, morphing
  22.  of 3d objects means that one 3d object is gradually changing into another
  23.  3d object. What I am about to show you is morphing of 3d objects which
  24.  consist of pixels only, not lines or anything. However, the principle is
  25.  the same when using lines or polygons. One of the basic properties of 3d
  26.  morphing is that all 3d points should reach their destination at the same
  27.  time. Like, in our example, it wouldn't be good to see some pixels already
  28.  at their destination while others are still on their way, right? In the
  29.  example all pixels (2d) arrive at the same time.
  30.  
  31.  Ok, how do we code this stuff? First of all I will assume you know the
  32.  basics of 3d coding, like, how to rotate and show a 3d point on the vga.
  33.  If you don't know that, this doc is probably of no use to you yet.
  34.  Anyway, with that clear, let's see the theory behind 3d morphing, ok?
  35.  Let's say x1,y1,z1 represent a 3d point and x2,y2,z2 form another one
  36.  (origin & destination). Observe this:
  37.  
  38.     x2-x1 = distance on the X axis between the twese points
  39.     y2-y1 = distance on the Y axis between the twese points
  40.     z2-z1 = distance on the Z axis between the twese points
  41.  
  42.  When we add the difference between the x values to x1, we get x2. BUT, we
  43.  don't want to get to x2 in just 1 step. So, let's divide that value by 64!
  44.  Then, if we add the resulting value to x1 64 times, we get x2. We also do
  45.  this for the y and the z:
  46.  
  47.     Xstep = (x2-x1) / 64
  48.     Ystep = (y2-y1) / 64
  49.     Zstep = (z2-z1) / 64
  50.  
  51.  This must be done for all 3d points in the objects. You will get as many
  52.  Xstep values as there are x values in the object. Same goes for y and z.
  53.  The method described here will only work for objects of equal size. In
  54.  other words, you can't have one 3d object of (for example) 100 points and
  55.  another 3d object of 120 points.
  56.  
  57.  Now for the pascalcode. What we are going to do is adding the stepsizes to
  58.  the x,y,z values of the original 3d point 64 times. While doing this, we
  59.  also rotate and display the point. So:
  60.  
  61.  For Loop1 := 1 to 64 Do
  62.  Begin
  63.    x1 := x1 + Xstep;
  64.    y1 := y1 + Ystep;
  65.    z1 := z1 + Zstep;
  66.    { rotate x1,y1,z1 }
  67.    { display point }
  68.  End
  69.  
  70.  Easy, huh? This will show a rotating 3d point changing from position 1 to
  71.  position 2. Now, of course we are not done yet. What we want is not just 1
  72.  morphing 3d point but an entire object changing into another. To do this,
  73.  simply store all stepvalues of all 3d points into an array and do the same
  74.  thing. So, code for a 100 3d points could look like:
  75.  
  76.  For Loop1 := 1 to 64 Do              { We want 64 steps }
  77.  Begin
  78.    For Loop2 := 1 to 100 Do           { And a 100 3d points }
  79.    Begin
  80.      x1 := x1 + StepArray[Loop1,1];   { StepArray contains all stepvalues }
  81.      y1 := y1 + StepArray[Loop1,2];
  82.      z1 := z1 + StepArray[Loop1,3];
  83.      { rotate x1,y1,z1 }
  84.      { display point }
  85.    End;
  86.  End;
  87.  
  88.  This is practically all there is to it! Just fool around a bit to get it to
  89.  work the way you want. Take a look at the example source to see how things
  90.  can be done. Luckily, the math behind 3d morphing is pretty easy. So easy
  91.  in fact, even I was able to understand it! And my math really stinks... :-)
  92.  The example provided needs a lot of optimizing as I wanted to keep it simple
  93.  and easy to understand. It should be enough to get you started, though, and
  94.  that's what these trainers are all about. Goodluck and if you encounter any
  95.  problems, mail me!
  96.  
  97.  Ok, this is all for now. Happy coding!
  98.  
  99.        - Vulture / Outlaw Triad -
  100.  
  101. ───────────────────────────────■ Distro Sites ■───────────────────────────────
  102.  
  103.  Call our distrobution sites! All our releases are available at:
  104.  
  105.   BlueNose      World HQ          +31 (0)345-619401
  106.   FireHouse     Distrosite        +31 (0)528-274176
  107.   The Force     Distrosite        +31 (0)36-5346967    More distros wanted!
  108.   Bugs'R'Us     Distrosite        +31 (0)252-686092    (preferably outside
  109.   MagicWare     Italian HQ        +39  6-52355532       of The Netherlands)
  110.   ShockWave     South African HQ  +27 (011)888-6345
  111.   Society HQ    United States HQ  +1  (518)465-6721
  112.  
  113.  Also check the major FTP sites for Outlaw Triad productions.
  114.  
  115. ──────────────────────────────────■ Contact ■─────────────────────────────────
  116.  
  117.  Want to contact Outlaw Triad for some reason? You can reach us at our
  118.  distrosites in Holland. Or if you have e-mail access, mail us:
  119.  
  120.    Vulture   (coder/pr)   comma400@tem.nhl.nl
  121.  
  122.  Our internet homepage:
  123.  
  124.    http://www.tem.nhl.nl/~comma400/vulture.html
  125.  
  126.  These internet adresses should be valid at least till june 1996.
  127.  
  128. ──────────────────────────────────────────────────────────────────────────────
  129.  
  130.                   Quote: I think ... therefore I am confused...