home *** CD-ROM | disk | FTP | other *** search
/ Collection of Hack-Phreak Scene Programs / cleanhpvac.zip / cleanhpvac / TUT1-9.ZIP / TUT9.TXT < prev    next >
Text File  |  1994-02-26  |  11KB  |  268 lines

  1.                    ╒═══════════════════════════════╕
  2.                    │         W E L C O M E         │
  3.                    │  To the VGA Trainer Program   │ │
  4.                    │              By               │ │
  5.                    │      DENTHOR of ASPHYXIA      │ │ │
  6.                    ╘═══════════════════════════════╛ │ │
  7.                      ────────────────────────────────┘ │
  8.                        ────────────────────────────────┘
  9.  
  10.                            --==[ PART 9 ]==--
  11.  
  12.  
  13.  
  14. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  15. ■ Introduction
  16.  
  17. Hi there! ASPHYXIA is BACK with our first MegaDemo, Psycho Neurosis! A
  18. paltry 1.3MB download is all it takes to see the group from Durbs first
  19. major production! We are quite proud of it, and think you should see it
  20. ;)
  21.  
  22. Secondly, I released a small little trainer (a trainerette ;-)) on
  23. RsaPROG and Connexctix BBS mail, also on the ASPHYXIA BBS as COPPERS.ZIP
  24. It is a small Pascal program demonstrating how to display copper bars in
  25. text mode. Also includes a check for horizontal retrace (A lot of people
  26. wanted it, that is why I wrote the program) (ASPHYXIA ... first with the
  27. trainer goodies ;-)  aargh, sorry, had to be done ))
  28.  
  29. Thirdly, sorry about the problems with Tut 8! If you had all the
  30. checking on, the tutorial would probably die on the first points. The
  31. reason is this : in the first loop, we have DrawPoints then
  32. RotatePoints. The variables used in DrawPoints are set in RotatePoints,
  33. so if you put RotatePoints before DrawPoints, the program should work
  34. fine. Alternatively, turn off error checking 8-)
  35.  
  36. Fourthly, I have had a surprisingly large number of people saying that
  37. "I get this, like, strange '286 instructions not enabled' message!
  38. What's wrong with your code, dude?"  To all of you, get into Pascal, hit
  39. Alt-O (for options), hit enter and a 2 (for Enable 286 instructions). Hard
  40. hey? Doesn't anyone EVER set up their version of Pascal?
  41.  
  42. Now, on to todays tutorial! 3D solids. That is what the people wanted,
  43. that is what the people get! This tutorial is mainly on how to draw the
  44. polygon on screen. For details on how the 3D stuff works, check out tut
  45. 8.
  46.  
  47.  
  48.  
  49. If you would like to contact me, or the team, there are many ways you
  50. can do it : 1) Write a message to Grant Smith/Denthor/Asphyxia in private mail
  51.                   on the ASPHYXIA BBS.
  52.             2) Write to Denthor, EzE or Goth on Connectix.
  53.             3) Write to :  Grant Smith
  54.                            P.O.Box 270 Kloof
  55.                            3640
  56.                            Natal
  57.             4) Call me (Grant Smith) at (031) 73 2129 (leave a message if you
  58.                   call during varsity)
  59.             5) Write to mcphail@beastie.cs.und.ac.za on InterNet, and
  60.                   mention the word Denthor near the top of the letter.
  61.  
  62. NB : If you are a representative of a company or BBS, and want ASPHYXIA
  63.        to do you a demo, leave mail to me; we can discuss it.
  64. NNB : If you have done/attempted a demo, SEND IT TO ME! We are feeling
  65.         quite lonely and want to meet/help out/exchange code with other demo
  66.         groups. What do you have to lose? Leave a message here and we can work
  67.         out how to transfer it. We really want to hear from you!
  68.  
  69.  
  70.  
  71. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  72. ■ How to draw a polygon
  73.  
  74. Sounds easy enough, right? WRONG! There are many, many different ways to
  75. go about this, and today I'll only be showing you one. Please don't take
  76. what is written here as anything approaching the best method, it is just
  77. here to get you on your way...
  78.  
  79. The procedure I will be using here is based on something most of us
  80. learned in standard eight ... I think. I seem to recall doing something
  81. like this in Mrs. Reids maths class all those years ago ;)
  82.  
  83. Take two points, x1,y1 and x2,y2. Draw them :
  84.  
  85.                   + (x1,y1)
  86.                    \
  87.                      \  <-- Point a somewhere along the line
  88.                        \
  89.                          + (x2,y2)
  90.  
  91. Right, so what we have to do is this : if we know the y-coord of a, what
  92. is it's x-coord? To prove the method we will give the points random
  93. values.
  94.  
  95.                  + (2,10)
  96.                   \
  97.                     \  <-- a.y = 12
  98.                       \
  99.                         +  (15,30)
  100.  
  101. Right. Simple enough problem. This is how we do it :
  102.    (a.y-y1) = (12 - 10)  {to get a.y as though y1 was zero}
  103.    *(x2-x1) = *(15 - 2)  {the total x-length of the line}
  104.    /(y2-y1) = /(30 - 10) {the total y-length of the line}
  105.         +x1 = +2         { to get the equation back to real coords}
  106.  
  107. So our equation is :  (a.y-y1)*(x2-x1)/(y2-y1)+x4    or
  108.                       (12-10)*(15-2)/(30-10)+2
  109.       which gives you :
  110.                       2*13/20+2 = 26/20+2
  111.                                 = 3.3
  112.  
  113. That means that along the line with y=12, x is equal to 3.3. Since we
  114. are not concerned with the decimal place, we replace the  /  with a div,
  115. which in Pascal gives us an integer result, and is faster too. All well
  116. and good, I hear you cry, but what does this have to do with life and
  117. how it relates to polygons in general. The answer is simple. For each of
  118. the four sides of the polygon we do the above test for each y line. We
  119. store the smallest and the largest x values into separate variables for
  120. each line, and draw a horizontal line between them. Ta-Dah! We have a
  121. cool polygon!
  122.  
  123. For example : Two lines going down :
  124.     
  125.                 +             +
  126.                / <-x1     x2->|   <--For this y line
  127.              /                |
  128.            +                  +
  129.  
  130. Find x1 and x2 for that y, then draw a line between them. Repeat for all
  131. y values.
  132.  
  133. Of course, it's not as simple as that. We have to make sure we only
  134. check those y lines that contain the polygon (a simple min y, max y test
  135. for all the points). We also have to check that the line we are
  136. calculating actually extends as far as where our current y is (check
  137. that the point is between both y's). We have to compare each x to see
  138. weather it is smaller then the minimum x value so far, or bigger then
  139. the maximum (the original x min is set as a high number, and the x max
  140. is set as a small number). We must also check that we only draw to the
  141. place that we can see ( 0-319 on the x ; 0-199 on the y (the size of the
  142. MCGA screen))
  143.  
  144. To see how this looks in practice, have a look at the sample code
  145. provided. (Mrs. Reid would probably kill me for the above explanation,
  146. so when you learn it in school, split it up into thousands of smaller
  147. equations to get the same answer ;))
  148.  
  149. Okay, that's it! What's that? How do you draw a vertical line? Thats
  150. simple ...
  151.  
  152. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  153. ■ Drawing a vertical line
  154.  
  155. Right, this is a lot easier than drawing a normal line (Tut 5 .. I
  156. think), because you stay on the same y value. So, what you do is you set
  157. ES to the screen you want to write to, and get DI to the start of the
  158. y-line (see earlier trainers for a description of how SEGMENT:OFFSET
  159. works.
  160.  
  161. IN   : x1 , x2, y, color, where
  162.  
  163.            asm
  164.              mov    ax,where
  165.              mov    es,ax
  166.              mov    di,y
  167.              mov    ax,y
  168.              shl    di,8   { di:=di*256 }
  169.              shl    ax,6   { ax:=ax*64 }
  170.              add    di,ax  { di := (y*256)+(y*64) := y*320 Faster then a
  171.                              straight multiplication }
  172.  
  173. Right, now you add the first x value to get your startoff.
  174.              add    di,x1
  175. Move the color to store into ah and al
  176.              mov    al,color
  177.              mov    ah,al       { ah:=al:=color }
  178. then get CX equal to how many pixels across you want to go
  179.              mov    cx,x2
  180.              sub    cx,x1   { cx:=x2-x1 }
  181. Okay, as we all know, moving a word is a lot faster then moving a byte,
  182. so we halve CX
  183.              shr    cx,1    { cx:=cx/2 }
  184. but what happens if CX was an odd number. After a shift, the value of
  185. the last number is placed in the carry flag, so what we do is jump over
  186. a single byte move if the carry flag is zero, or execute it if it is
  187. one.
  188.             jnc     @Start  { If there is no carry, jump to label Start }
  189.             stosb           { ES:[DI]:=al ; increment DI }
  190.         @Start :            { Label Start }
  191.             rep     stosw   { ES:[DI]:=ax ; DI:=DI+2; repeat CX times }
  192.  
  193. Right, the finished product looks like this :
  194.  
  195. Procedure Hline (x1,x2,y:word;col:byte;where:word); assembler;
  196.   { This draws a horizontal line from x1 to x2 on line y in color col }
  197. asm
  198.   mov   ax,where
  199.   mov   es,ax
  200.   mov   ax,y
  201.   mov   di,ax
  202.   shl   ax,8
  203.   shl   di,6
  204.   add   di,ax
  205.   add   di,x1
  206.  
  207.   mov   al,col
  208.   mov   ah,al
  209.   mov   cx,x2
  210.   sub   cx,x1
  211.   shr   cx,1
  212.   jnc   @start
  213.   stosb
  214. @Start :
  215.   rep   stosw
  216. end;
  217.  
  218. Done!
  219.  
  220. =-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=
  221. ■  In closing
  222.  
  223. This 3D system is still not perfect. It needs to be faster, and now I
  224. have also dumped the problem of face-sorting on you! Nyahahahaha!
  225.  
  226.            [ My sister and I were driving along the other day when she
  227.                asked me, what would I like for my computer.
  228.              I thought long and hard about it, and came up with the
  229.                following hypothesis. When a girl gets a Barbie doll, she
  230.                then wants the extra ballgown for the doll, then the
  231.                hairbrush, and the car, and the house, and the friends
  232.                etc.
  233.              When a guy gets a computer, he wants the extra memory, the
  234.                bigger hard drive, the maths co-pro, the better
  235.                motherboard, the latest software, and the bigger monitor
  236.                etc.
  237.              I told my sister all of this, and finished up with : "So as
  238.                you can see, computers are Barbie dolls for MEN!"
  239.              She called me a chauvinist. And hit me. Hard.
  240.                                                                    ]
  241.                                                        - Grant Smith
  242.                                                            19:24
  243.                                                              26/2/94
  244.  
  245. See you next time!
  246.   - Denthor
  247.  
  248. These fine BBS's carry the ASPHYXIA DEMO TRAINER SERIES : (alphabetical)
  249.  
  250. ╔══════════════════════════╦════════════════╦═════╦═══╦════╦════╗
  251. ║BBS Name                  ║Telephone No.   ║Open ║Msg║File║Past║
  252. ╠══════════════════════════╬════════════════╬═════╬═══╬════╬════╣
  253. ║ASPHYXIA BBS #1           ║(031) 765-5312  ║ALL  ║ * ║ *  ║ *  ║
  254. ║ASPHYXIA BBS #2           ║(031) 765-6293  ║ALL  ║ * ║ *  ║ *  ║
  255. ║Connectix BBS             ║(031) 266-9992  ║ALL  ║   ║ *  ║ *  ║
  256. ╚══════════════════════════╩════════════════╩═════╩═══╩════╩════╝
  257.  
  258. Open = Open at all times or only A/H
  259. Msg  = Available in message base
  260. File = Available in file base
  261. Past = Previous Parts available
  262.  
  263. Does no other BBS's ANYWHERE carry the trainer? Am I writing this for
  264. three people who get it from one of these BBS's each week? Should I go
  265. on? (Hehehehe ... I was pleased to note that Tut 8 was THE most
  266. downloaded file from ASPHYXIA BBS last month ... )       
  267.  
  268.