home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / rotate / rotate.txt < prev    next >
Text File  |  1993-02-13  |  4KB  |  146 lines

  1. ─────────────────────────────────────────────────────────────────────────────
  2. ;
  3. ;     TITLE: 2d rotate text file
  4. ;WRITTEN BY: DRAEDEN
  5. ;      DATE: 02/13/93
  6. ;
  7. ;     NOTES: None.
  8. ;
  9. ;ASSOCIATED FILES:
  10. ;
  11. ;       BWPRINT.ASM =>  Displays signed and unsigned bytes, words, or
  12. ;                    >  double words
  13. ;
  14. ;       SINCOS.DW   =>  Contains data for the sine and cosine operations
  15. ;
  16. ;       ROTATE.ASM  =>  The asm file.
  17. ;
  18. ;       MAKE.BAT    =>  The file that'll put it all together into an .EXE
  19. ;
  20. ────────────────────────────────────────────────────────────────────────────
  21.  
  22. Rotating a point around (0,0):
  23.  
  24.     Rotating an object is really easier than it sounds.  There is just a 
  25. simple formula for it, which is:
  26.  
  27.     Xt = X*COS(φ) - Y*SIN(φ)
  28.     Yt = X*SIN(φ) + Y*COS(φ)
  29.  
  30.     If you don't think this works, try a few values. For at instance φ = 0°,
  31.  
  32.     Xt = X*1 - Y*0 = X
  33.     Yt = X*0 + Y*1 = Y
  34.  
  35.     And at φ = 90°,
  36.     
  37.     Xt = X*0 - Y*1 = -Y
  38.     Yt = X*1 + Y*0 = X
  39.  
  40.     Both of which work.  Also note that the rotation is counter-clockwise. 
  41. If you wanted it to rotate clockwise in stead, the formula would be:
  42.  
  43.     Xt = X*COS(φ) + Y*SIN(φ)
  44.     Yt =-X*SIN(φ) + Y*COS(φ)
  45.  
  46.     Or you could just negate the angle.
  47.  
  48.  
  49.     Now, if you wanted to rotate in 3 demensions (I hope this is obvious),
  50. you would need 3 angles which I call Xan, Yan, and Zan.  The formula would
  51. be the same as above, but done 3 times.
  52.  
  53.     1st, rotate on the X axis
  54.     
  55.     Y = Y*COS(Xan) - Z*SIN(Xan)
  56.     Z = Y*SIN(Xan) + Z*COS(Xan)
  57.  
  58.     Next, rotate on the Y axis
  59.  
  60.     X = X*COS(Yan) - Z*SIN(Yan)
  61.     Z = X*SIN(Yan) + Z*COS(Yan)
  62.  
  63.     And finally, the Z axis
  64.  
  65.     Xt = X*COS(Zan) - Y*SIN(Zan)
  66.     Yt = X*SIN(Zan) + Y*COS(Zan)
  67.  
  68.     You should notice that the order in which you rotate the object DOES
  69. matter.  To see the how, grab a disk and rotate it 90° along the X axis,
  70. 90° along the Y axis, and then 90° on the Z axis. Now try the rotations in
  71. a different order.  Different results, eh?
  72.  
  73. ────────────────────────────────────────────────────────────────────────────
  74.  
  75. And now an explaination of SINCOS.DW
  76.  
  77.     SinCos.dw is a file which contians the sine of the 'angles' 0-255.  I
  78. used 256 angles because it is very convienent, and there just happens to 
  79. be a data structure that has a range of 0-255.  It's called a BYTE, denoted
  80. by 'DB'.
  81.     The bit of code (in BASIC) that would generate this sort of chart is:
  82.  
  83. ────────
  84.  
  85.     FOR i = 0 TO 255
  86.         an = i*2*pi/256
  87.         BYTE = INT( SIN( an )*256 +.5)
  88.         >> Store BYTE in a file <<
  89.     NEXT i
  90.  
  91. ────────
  92.  
  93.     Modifying the basic rotation formula for our data file would yield:
  94.  
  95.     Xt = (X*COS(φ) - Y*SIN(φ)) /256
  96.     Yt = (X*SIN(φ) + Y*COS(φ)) /256
  97.  
  98.     If you know your hexadecimal, you'd realise that dividing by 256 is 
  99. simply a "SAR XXX,8", where XXX is what you're dividing by 256.
  100.  
  101.     I expanded this into assembler, that not only works, but is very fast. 
  102. To see it, examine the RotateXY procedure.
  103.  
  104. ────────────────────────────────────────────────────────────────────────────
  105.  
  106. BWPRINT.ASM
  107.  
  108.     This file is just a little utility I put together many many years ago.
  109. Ok, maybe not years, but It seems that long.  I wrote it when I first got a
  110. 386.  No more CAVEMAN computer!  Oh well.  The basic functions are:
  111.  
  112.     PrintByte, PrintWord, and PrintBig. 
  113.  
  114.     They do this:
  115.  
  116.     PrintByte: decodes a byte (in AL) and displays it as 3 digits plus a
  117.             an optional sign.  If the carry is clear, it prints it as an
  118.             unsigned integer.  If the carry is set, it prints it signed.
  119.     ────
  120.         EXAMPLE:
  121.             mov     al,-50
  122.             stc
  123.             call    PrintByte
  124.     ────
  125.  
  126.     PrintWord: decodes and prints a WORD (in AX) in 5 digits.
  127.     ────
  128.         EXAMPLE:
  129.             mov     ax,50000
  130.             clc
  131.             call    PrintWord
  132.     ────
  133.     
  134.     PrintBig:  decodes and prints a DOUBLEWORD (in EAX) in 10 digits. 
  135.                 NOTE: PrintBig requires a 386 to use.
  136.     ────
  137.         EXAMPLE:
  138.             mov     eax,-1234567890
  139.             stc
  140.             call    PrintBig
  141.  
  142. ────────────────────────────────────────────────────────────────────────────
  143.  
  144.  
  145.    Well, that's it for now.  See INFO.VLA for information on contacting us.
  146.