home *** CD-ROM | disk | FTP | other *** search
/ The Party 1994: Try This At Home / disk_image.bin / source / vexsrc / intrsect.asm < prev    next >
Assembly Source File  |  1995-03-29  |  5KB  |  313 lines

  1. comment #
  2. /*****************************************************************************
  3.                                   ATTENTION!
  4.                            this source is VOTEWARE,
  5.               you may only use it to the conditions listed below:
  6.  
  7.   -You may modify it, or use parts of it in your own source as long as
  8.     this header stays on top of all files containing this source.
  9.   -You must give proper credit to the author, Niklas Beisert / pascal.
  10.   -You may not use it in commercial productions without the written
  11.     permission of the author.
  12.   -AND MOST IMPORTANT: you have to buy an Assembly '94 CD-ROM
  13.     by Sound Solutions (if you don't have it already) and vote for VEX-InTrO
  14.     in the PC-64k-Intro-Compo! (if you have already sent your voting card,
  15.     buy another one and fill it out CORRECTLY!!!)
  16. *****************************************************************************/
  17. #
  18.  
  19.  
  20.  
  21. ;// intersection help functions
  22.  
  23. .model large,c
  24. .386
  25. locals
  26.  
  27. .code
  28.  
  29. public calcplane
  30. public chkplanecut
  31. public planecutv
  32. public planecuts2
  33. public planecutc2
  34.  
  35. calcplane proc uses ds si di,norm:dword, vert:dword, plane:dword
  36.   cld
  37.   lds si,norm
  38.   les di,plane
  39.   mov cx,3
  40.   rep movsd
  41.   lds si,vert
  42.   lodsd
  43.   imul dword ptr es:[di-12]
  44.   mov ecx,eax
  45.   mov ebx,edx
  46.   lodsd
  47.   imul dword ptr es:[di-8]
  48.   add ecx,eax
  49.   adc ebx,edx
  50.   lodsd
  51.   imul dword ptr es:[di-4]
  52.   add eax,ecx
  53.   adc edx,ebx
  54.   shrd eax,edx,16
  55.   neg eax
  56.   stosd
  57.   ret
  58. endp
  59.  
  60. chkplanecut proc uses ds si di, plane:dword, pts:dword, pl:dword, n:word, rt:dword
  61. local a:dword, b:dword, c:dword, d:dword, lst:dword, cur:dword, nl:word, nc:word, s:byte, ls:byte, pal:word, pac:word, pbl:word, pbc:word, vpal:dword, vpac:dword, vpbl:dword, vpbc:dword
  62.   cld
  63.   lds si,plane
  64.   lodsd
  65.   mov a,eax
  66.   lodsd
  67.   mov b,eax
  68.   lodsd
  69.   mov c,eax
  70.   lodsd
  71.   mov d,eax
  72.  
  73.   mov ax,n
  74.   dec ax
  75.   mov nl,ax
  76.  
  77.   les di,pts
  78.   lds si,pl
  79.  
  80.   mov s,0
  81.  
  82. @@lp1:
  83.     mov bx,n
  84.     shl bx,1
  85.     mov ax,[si+bx-2]
  86.  
  87.     shl ax,2
  88.     mov bx,ax
  89.     shl ax,1
  90.     add bx,ax
  91.     mov eax,es:[di+bx+0]
  92.     imul a
  93.     shrd eax,edx,16
  94.     mov ecx,eax
  95.     mov eax,es:[di+bx+4]
  96.     imul b
  97.     shrd eax,edx,16
  98.     add ecx,eax
  99.     mov eax,es:[di+bx+8]
  100.     imul c
  101.     shrd eax,edx,16
  102.     add ecx,eax
  103.     add ecx,d
  104.     cmp ecx,-20
  105.     jl @@ok1n
  106.     cmp ecx,20
  107.     jg @@ok1p
  108.     inc s
  109.     dec n
  110.     jnz @@lp1
  111.       mov ax,1
  112.     jmp @@end
  113. @@ok1n:
  114.     mov ls,-1
  115.   jmp @@ok1
  116. @@ok1p:
  117.     mov ls,0
  118. @@ok1:
  119.   cmp s,0
  120.   je @@yo
  121.     xor ecx,ecx
  122. @@yo:
  123.   mov lst,ecx
  124.  
  125.   mov s,0
  126.   mov nc,0
  127. @@lp:
  128.     lodsw
  129.     shl ax,2
  130.     mov bx,ax
  131.     shl ax,1
  132.     add bx,ax
  133.     mov eax,es:[di+bx+0]
  134.     imul a
  135.     shrd eax,edx,16
  136.     mov ecx,eax
  137.     mov eax,es:[di+bx+4]
  138.     imul b
  139.     shrd eax,edx,16
  140.     add ecx,eax
  141.     mov eax,es:[di+bx+8]
  142.     imul c
  143.     shrd eax,edx,16
  144.     add ecx,eax
  145.     add ecx,d
  146.     cmp ecx,-20
  147.     jl @@ok2n
  148.     cmp ecx,20
  149.     jg @@ok2p
  150.       mov al,ls
  151.     jmp @@ok2
  152.   @@ok2n:
  153.       mov al,-1
  154.     jmp @@ok2
  155.   @@ok2p:
  156.       mov al,0
  157.   @@ok2:
  158.     mov cur,ecx
  159.     mov ah,al
  160.     xchg ah,ls
  161.     xor al,ah
  162.     jz @@nocut
  163.       inc s
  164.       cmp cur,0
  165.       js @@b
  166.     mov ax,nl
  167.     mov pal,ax
  168.     mov ax,nc
  169.     mov pac,ax
  170.     mov eax,lst
  171.     mov vpal,eax
  172.     mov eax,cur
  173.     mov vpac,eax
  174.       jmp @@nocut
  175.     @@b:
  176.     mov ax,nl
  177.     mov pbl,ax
  178.     mov ax,nc
  179.     mov pbc,ax
  180.     mov eax,lst
  181.     mov vpbl,eax
  182.     mov eax,cur
  183.     mov vpbc,eax
  184.   @@nocut:
  185.     mov eax,cur
  186.     mov lst,eax
  187.     mov ax,nc
  188.     mov nl,ax
  189.     inc nc
  190.   dec n
  191.   jnz @@lp
  192.  
  193.   cmp s,0
  194.   jnz @@cut
  195.     cmp cur,0
  196.     js @@bh
  197.       mov ax,2
  198.       jmp @@end
  199.   @@bh:
  200.       mov ax,0
  201.       jmp @@end
  202. @@cut:
  203.     les di,rt
  204.  
  205.     mov ax,pal
  206.     stosw
  207.     mov ax,pac
  208.     stosw
  209.     mov eax,vpal
  210.     mov ecx,eax
  211.     sub ecx,vpac
  212.     cdq
  213.     shld edx,eax,16
  214.     shl eax,16
  215.     idiv ecx
  216.     stosd
  217.  
  218.     mov ax,pbl
  219.     stosw
  220.     mov ax,pbc
  221.     stosw
  222.     mov eax,vpbl
  223.     mov ecx,eax
  224.     sub ecx,vpbc
  225.     cdq
  226.     shld edx,eax,16
  227.     shl eax,16
  228.     idiv ecx
  229.     stosd
  230.  
  231.     mov ax,3
  232. @@end:
  233.   ret
  234. endp
  235.  
  236. planecutv proc uses ds si di, a:dword, dtl:dword, dtc:dword, dtr:dword
  237. local b:dword
  238.   mov eax,10000h
  239.   sub eax,a
  240.   mov b,eax
  241.  
  242.   cld
  243.   lds si,dtl
  244.   lfs bx,dtc
  245.   les di,dtr
  246.   i=0
  247.   rept 3
  248.     mov eax,ds:[si+i]
  249.     imul b
  250.     shrd eax,edx,16
  251.     mov ecx,eax
  252.     mov eax,fs:[bx+i]
  253.     imul a
  254.     shrd eax,edx,16
  255.     add eax,ecx
  256.     mov es:[di+i],eax
  257.     i=i+4
  258.   endm
  259.   ret
  260. endp
  261.  
  262. planecuts2 proc uses ds si di, a:dword, dtl:dword, dtc:dword, dtr:dword
  263. local b:dword
  264.   mov eax,10000h
  265.   sub eax,a
  266.   mov b,eax
  267.  
  268.   lds si,dtl
  269.   lfs bx,dtc
  270.   les di,dtr
  271.   i=0
  272.   rept 2
  273.     movzx eax,word ptr ds:[si+i]
  274.     mul b
  275.     shr eax,16
  276.     mov cx,ax
  277.     movzx eax,word ptr fs:[bx+i]
  278.     mul a
  279.     shr eax,16
  280.     add ax,cx
  281.     mov word ptr es:[di+i],ax
  282.     i=i+2
  283.   endm
  284.   ret
  285. endp
  286.  
  287. planecutc2 proc uses ds si di, a:dword, dtl:dword, dtc:dword, dtr:dword
  288. local b:dword
  289.   mov eax,10000h
  290.   sub eax,a
  291.   mov b,eax
  292.  
  293.   lds si,dtl
  294.   lfs bx,dtc
  295.   les di,dtr
  296.   i=0
  297.   rept 2
  298.     movzx eax,byte ptr ds:[si+i]
  299.     mul b
  300.     shr eax,16
  301.     mov cl,al
  302.     movzx eax,byte ptr fs:[bx+i]
  303.     mul a
  304.     shr eax,16
  305.     add al,cl
  306.     mov byte ptr es:[di+i],al
  307.     i=i+1
  308.   endm
  309.   ret
  310. endp
  311.  
  312. end
  313.