home *** CD-ROM | disk | FTP | other *** search
/ The Equalizer BBS / equalizer-bbs-collection_2004.zip / equalizer-bbs-collection / DEMOSCENE-STUFF / INCOMSRC.ZIP / 3D386V2.INC next >
Text File  |  1995-02-27  |  4KB  |  270 lines

  1. ;
  2. ;  incompatibility version - d_xeltol & d_yeltol are added
  3. ;
  4. ;  ByTeaM 80386 3D Rotation Calculator
  5. ;  Coded by KiNG RoByMuS
  6. ;  Fully optimized 32 bit calculations,
  7. ;  using extra fasten method (!)...
  8. ;  Only for using as INClude file (! Routines finished by RETN !)
  9. ;  You can copy this routine to everyone, it's Public Domain...
  10. ;
  11. ;Usage:
  12. ;------
  13. ; *Call InitRotate* function to calculate SINus/COSinus values
  14. ;  - Input: DS:SI buffer of XRot/YRot/ZRot (6 byte - Pro-radian [0..1023])
  15. ; *Call Calc3D* function for each point to calculation
  16. ;  - This function calculates 2D coordinates from 3D coordinates
  17. ;  - Input: DS:SI buffer of 3D-XCoord/3D-YCoord/3D-ZCoord (1 signed word each)
  18. ;           ES:DI buffer for calculated X/Y coordinates   (Same format...)
  19. ; *Call ProRotate* function to rotate at specified CenterPoint
  20. ;  - Works only if NOT perspective
  21. ;  - Input: Same as Calc3D + AX/BX/CX = X/Y/Z coordinates of rotation...
  22. ; *D_Perspective* control byte : 0 = Normal 3D, 1 = Perspective 3D
  23. ; *D_EyeDist* (DWord) controls the EyeDistance (effects only prespective 3D)
  24. ;
  25.  
  26. ;
  27. ;32 bit Sinus Table
  28. ;
  29. D_SinTable label dword
  30. include sintable.386
  31.  
  32. ;
  33. ;Definitions
  34. ;
  35. D_XC_ EQU word ptr DS:[SI]
  36. D_YC_ EQU word ptr DS:[SI+2]
  37. D_ZC_ EQU word ptr DS:[SI+4]
  38. D_X_  EQU word ptr ES:[DI]
  39. D_Y_  EQU word ptr ES:[DI+2]
  40. d_z_  equ word ptr es:[di+4]
  41.  
  42. ;
  43. ;Control Datas
  44. ;
  45. D_EyeDist dd 200
  46. D_Perspective db 0
  47. D_Xeltol dw 0
  48. D_Yeltol dw 0
  49. D_PersZEltol dd 0
  50. d_realxeltol dw 0
  51. d_realyeltol dw 0
  52.  
  53. ;
  54. ;Temporary datas for FAST calculus
  55. ;Used in main code...
  56. ;
  57. D_XC DD ?
  58. D_YC DD ?
  59. D_ZC DD ?
  60. D_X  DD ?
  61. D_Y  DD ?
  62. D_z  dd 0
  63. D_xa dd 0
  64. D_ya dd 0
  65. D_za dd 0
  66. ;
  67. ;Temporary datas for FAST calculus
  68. ;Filled in InitRotate
  69. ;
  70. D_sinx dd 0
  71. D_cosx dd 0
  72. D_siny dd 0
  73. D_cosy dd 0
  74. D_sinz dd 0
  75. D_cosz dd 0
  76. ;
  77. ;Code begin...
  78. ;
  79. .386
  80. ;
  81. ;Initialize Rotate -  see notes 
  82. ;
  83. InitRotate:
  84. push esi
  85. push eax
  86. push ebx
  87. push edi
  88. push ecx
  89. push es
  90. push cs
  91. pop es
  92. mov edi,offset D_sinx
  93. mov cx,3
  94. D_Cik1:
  95. lodsw
  96. push ax
  97. and ax,1023
  98. shl ax,2
  99. mov bx,ax
  100. assume es:code
  101. mov eax,dword ptr es:D_SinTable[bx]    ;Calculate SINus
  102. stosd
  103. pop ax
  104. add ax,256
  105. and ax,1023
  106. shl ax,2
  107. mov bx,ax
  108. mov eax,dword ptr es:D_SinTable[bx]    ;Calculate COSinus
  109. ;assume es:data1
  110. stosd
  111. loop D_Cik1
  112. pop es
  113. pop ecx
  114. pop edi
  115. pop ebx
  116. pop eax
  117. pop esi
  118. retn
  119.  
  120. ;
  121. ;Main Calculator -  see notes 
  122. ;
  123. Calc3D:
  124. push eax
  125. push ebx
  126. push ecx
  127. push edx
  128. mov ax,D_xc_
  129. add ax,cs:d_realxeltol
  130. cwd
  131. mov word ptr cs:D_xc,ax
  132. mov word ptr cs:D_xc+2,dx
  133. mov ax,D_yc_
  134. add ax,cs:d_realyeltol
  135. cwd
  136. mov word ptr cs:D_yc,ax
  137. mov word ptr cs:D_yc+2,dx
  138. mov ax,D_zc_
  139. cwd
  140. mov word ptr cs:D_zc,ax
  141. mov word ptr cs:D_zc+2,dx
  142. push ds
  143. push cs
  144. pop ds
  145. ;
  146. ;XA=XC*COS(Z)-YC*SIN(Z)
  147. ;
  148. mov eax,cs:D_YC
  149. imul cs:D_SinZ
  150. mov ebx,edx
  151. mov ecx,eax
  152. mov eax,cs:D_XC
  153. imul cs:D_CosZ
  154. sub eax,ecx
  155. sbb edx,ebx
  156. shrd eax,edx,16
  157. mov cs:D_XA,eax
  158. ;
  159. ;YA=XC*SIN(Z)+YC*COS(Z)
  160. ;
  161. mov eax,cs:D_XC
  162. imul cs:D_SinZ
  163. mov ebx,edx
  164. mov ecx,eax
  165. mov eax,cs:D_YC
  166. imul cs:D_CosZ
  167. add eax,ecx
  168. adc edx,ebx
  169. shrd eax,edx,16
  170. mov cs:D_YA,eax
  171. ;
  172. ;Y=YA*COS(X)-ZC*SIN(X)
  173. ;
  174. mov eax,cs:D_ZC
  175. imul cs:D_SinX
  176. mov ebx,edx
  177. mov ecx,eax
  178. mov eax,cs:D_YA
  179. imul cs:D_CosX
  180. sub eax,ecx
  181. sbb edx,ebx
  182. shrd eax,edx,16
  183. mov cs:D_Y,eax
  184. ;
  185. ;ZA=YA*SIN(X)+ZC*COS(X)
  186. ;
  187. mov eax,cs:D_YA
  188. imul cs:D_SinX
  189. mov ebx,edx
  190. mov ecx,eax
  191. mov eax,cs:D_ZC
  192. imul cs:D_CosX
  193. add eax,ecx
  194. adc edx,ebx
  195. shrd eax,edx,16
  196. mov cs:D_ZA,eax
  197. ;
  198. ;X=XA*COS(Y)+ZA*SIN(Y)
  199. ;
  200. mov eax,cs:D_XA
  201. imul cs:D_CosY
  202. mov ebx,edx
  203. mov ecx,eax
  204. mov eax,cs:D_ZA
  205. imul cs:D_SinY
  206. add eax,ecx
  207. adc edx,ebx
  208. shrd eax,edx,16
  209. mov cs:D_X,eax
  210. ;
  211. ;Check for perspective calculus
  212. ;
  213. ;Z=ZA*COS(Y)-XA*SIN(Y)
  214. ;
  215. mov eax,cs:D_XA
  216. imul cs:D_SinY
  217. mov ebx,edx
  218. mov ecx,eax
  219. mov eax,cs:D_ZA
  220. imul cs:D_CosY
  221. sub eax,ecx
  222. sbb edx,ebx
  223. shrd eax,edx,16
  224. ;
  225. ;ECX = Z
  226. ;
  227. mov ecx,eax         
  228. mov cs:D_z_,cx
  229. mov ebx,cs:D_EyeDist
  230. add ecx,cs:d_PersZEltol
  231.  
  232. cmp cs:D_perspective,0
  233. je D_NotPers
  234. ;
  235. ;X=(X*EYEDIST)/(EYEDIST-Z)
  236. ;
  237. mov eax,cs:D_X
  238. imul ebx
  239. push ebx
  240. sub ebx,ecx
  241. idiv ebx
  242. pop ebx
  243. mov cs:D_X,eax
  244. ;
  245. ;Y=(Y*EYEDIST)/(EYEDIST-Z)
  246. ;
  247. mov eax,cs:D_Y
  248. imul ebx
  249. sub ebx,ecx
  250. idiv ebx
  251. mov cs:D_Y,eax
  252. ;
  253. ;It's all dudes
  254. ;
  255. D_NotPers:
  256. pop ds
  257. mov eax,cs:D_X
  258. add ax,cs:D_xeltol
  259. mov cs:D_X_,ax
  260. mov eax,cs:D_Y
  261. add ax,cs:D_yeltol
  262. mov cs:D_Y_,ax
  263. pop edx
  264. pop ecx
  265. pop ebx
  266. pop eax
  267. retn
  268.  
  269.  
  270.