home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Collection of Hack-Phreak Scene Programs
/
cleanhpvac.zip
/
cleanhpvac
/
ML_3DROT.ZIP
/
SOURCES
/
ENGINE3D.ASM
next >
Wrap
Assembly Source File
|
1996-05-04
|
9KB
|
263 lines
COMMENT $
----- Engine 3D -----
3D to 2D mapping routine, by Maple Leaf - 1996
last update: 4th May 1996 (speedups)
$
.386c
DATA segment word public use16
extrn RotAngle:WORD
extrn TiltAngle:WORD
extrn Xt, Yt, Zt : DWORD
extrn _3DX, _3DY, _3DZ : DWORD
extrn _2DX, _2DY : DWORD
extrn CenterX, CenterY : DWORD
extrn SinTab:BYTE
extrn CosTab:BYTE
extrn ObserverX, ObserverY, ObserverDist : DWORD
extrn TmpEqu:DWORD
extrn Perspective:BYTE
extrn ZoomFactor:WORD
extrn CameraX, CameraY, CameraZ : DWORD
DATA ends
CODE segment byte public use16
assume ds:DATA,cs:CODE
public IntMapCoordinates
public IntMapCoordinates2
;*****************************************************************************
IntMapCoordinates proc far
mov si,RotAngle
mov di,TiltAngle
shl si,2
shl di,2
; ----- _3dx:=_3dx-CameraX -----
mov eax,dword ptr _3DX
sub eax,dword ptr CameraX
mov dword ptr _3DX,eax
; ----- _3dy:=_3dy-CameraY -----
mov eax,dword ptr _3DY
sub eax,dword ptr CameraY
mov dword ptr _3DY,eax
; ----- _3dz:=_3dz-CameraZ -----
mov eax,dword ptr _3DZ
sub eax,dword ptr CameraZ
mov dword ptr _3DZ,eax
; ----- Xt:=ObserverX+_3DX*CosA-_3DY*SinA -----
mov eax,dword ptr _3DY
imul dword ptr SinTab[si]
mov ebx,eax
mov eax,dword ptr _3DX
imul dword ptr CosTab[si]
sub eax,ebx
mov ebx,dword ptr ObserverX
sal ebx,8
add eax,ebx
sar eax,8
mov dword ptr Xt,eax
; -- Yt:= ObserverY + (_3DX*SinA + _3DY*CosA)*SinB + _3DZ*CosB; --
mov eax,dword ptr _3DX
imul dword ptr SinTab[si]
mov ebx,eax
mov eax,dword ptr _3DY
imul dword ptr CosTab[si]
add eax,ebx
sar eax,8
mov dword ptr TmpEqu,eax
imul dword ptr SinTab[di]
mov ebx,eax
mov eax,dword ptr _3DZ
imul dword ptr CosTab[di]
add eax,ebx
mov ebx,dword ptr ObserverY
sal ebx,8
add eax,ebx
sar eax,8
mov dword ptr Yt,eax
; --- if perspective then begin ---
cmp Perspective,1 ; Want perspective ? If yes, then another
jne @NoPerspective ; 6 more IMUL instructions will appear ... (half speed) - I really don't know how to optimize this shit ... ;=) f#$%^&* !!!
; --- Zt:=ObserverDist+(_3DX*SinA+_3DY*CosA)*CosB-(_3DZ*SinB); ---
mov eax,TmpEqu
imul dword ptr CosTab[di]
mov ebx,eax
mov eax,dword ptr _3DZ ;<--; This could be erased if ya want
imul dword ptr SinTab[di] ; ; more speed, but some parts of the perspective will be lost ...
sub ebx,eax ;<--; (e.g. One running-point)
mov eax,dword ptr ObserverDist
sal eax,8
add eax,ebx
sar eax,8
jnz short @@1
mov eax,1 ; To prevent division by 0 ...
@@1:mov dword ptr Zt,eax
; ---- _2DX:=CenterX+Trunc(Xt*ZoomFactor/Zt); ----
mov eax,dword ptr Xt
imul dword ptr ZoomFactor
idiv dword ptr Zt
add eax,dword ptr CenterX
mov dword ptr _2DX,eax
; ---- _2DY:=CenterY-Trunc(Yt*ZoomFactor/Zt*13/16); ----
mov eax,dword ptr Yt
imul dword ptr ZoomFactor
idiv dword ptr Zt
;
add eax,eax ; This part is the equivalent of:
mov ebx,eax ; -----------
add eax,eax ; mov ecx,13
add ebx,eax ; imul ecx
add eax,eax ; -----------
add eax,ebx ;
;
sar eax,4
mov ebx,dword ptr CenterY
sub ebx,eax
mov dword ptr _2DY,ebx
jmp short @Outta
@NoPerspective:
; ---- _2DX:=CenterX+Trunc(Xt); ----
mov eax,dword ptr Xt
add eax,dword ptr CenterX
mov dword ptr _2DX,eax
; ---- _2DY:=CenterY-Trunc(Yt*13/16); ----
mov eax,dword ptr Yt
;
add eax,eax ; This part is the equivalent of:
mov ebx,eax ; -----------
add eax,eax ; mov ecx,13
add ebx,eax ; imul ecx
add eax,eax ; -----------
add eax,ebx ;
;
sar eax,4
mov ebx,dword ptr CenterY
sub ebx,eax
mov dword ptr _2DY,ebx
@Outta:
retf
IntMapCoordinates endp
;*****************************************************************************
IntMapCoordinates2 proc far
mov si,RotAngle
mov di,TiltAngle
shl si,2
shl di,2
; ----- _3dx:=_3dx-CameraX -----
mov eax,dword ptr _3DX
sub eax,dword ptr CameraX
mov dword ptr _3DX,eax
; ----- _3dy:=_3dy-CameraY -----
mov eax,dword ptr _3DY
sub eax,dword ptr CameraY
mov dword ptr _3DY,eax
; ----- _3dz:=_3dz-CameraZ -----
mov eax,dword ptr _3DZ
sub eax,dword ptr CameraZ
mov dword ptr _3DZ,eax
; ----- Xt:=ObserverX+_3DX*CosA-_3DY*SinA -----
mov eax,dword ptr _3DY
imul dword ptr SinTab[si]
mov ebx,eax
mov eax,dword ptr _3DX
imul dword ptr CosTab[si]
sub eax,ebx
mov ebx,dword ptr ObserverX
sal ebx,8
add eax,ebx
sar eax,8
mov dword ptr Xt,eax
; -- Yt:= ObserverY + (_3DX*SinA + _3DY*CosA)*SinB + _3DZ*CosB; --
mov eax,dword ptr _3DX
imul dword ptr SinTab[si]
mov ebx,eax
mov eax,dword ptr _3DY
imul dword ptr CosTab[si]
add eax,ebx
sar eax,8
mov dword ptr TmpEqu,eax
imul dword ptr SinTab[di]
mov ebx,eax
mov eax,dword ptr _3DZ
imul dword ptr CosTab[di]
add eax,ebx
mov ebx,dword ptr ObserverY
sal ebx,8
add eax,ebx
sar eax,8
mov dword ptr Yt,eax
; --- if perspective then begin ---
cmp Perspective,1 ; Want perspective ? If yes, then another
jne @NoPerspective2 ; 6 more IMUL instructions will appear ... (half speed) - I really don't know how to optimize this shit ... ;=) f#$%^&* !!!
; --- Zt:=ObserverDist+(_3DX*SinA+_3DY*CosA)*CosB-(_3DZ*SinB); ---
mov eax,TmpEqu
imul dword ptr CosTab[di]
mov ebx,eax
mov eax,dword ptr _3DZ ;<--; This could be erased if ya want
imul dword ptr SinTab[di] ; ; more speed, but some parts of the perspective will be lost...
sub ebx,eax ;<--; (e.g. One running-point)
mov eax,dword ptr ObserverDist
sal eax,8
add eax,ebx
sar eax,8
jnz short @@2
mov eax,1 ; To prevent division by 0 ...
@@2:mov dword ptr Zt,eax
; ---- _2DX:=CenterX+Trunc(Xt*ZoomFactor/Zt); ----
mov eax,dword ptr Xt
; imul dword ptr ZoomFactor
cdq
shl eax,8 ; ZoomFactor is 256 by default
idiv dword ptr Zt
add eax,dword ptr CenterX
mov dword ptr _2DX,eax
; ---- _2DY:=CenterY-Trunc(Yt*ZoomFactor/Zt*13/16); ----
mov eax,dword ptr Yt
; imul dword ptr ZoomFactor
cdq
shl eax,8 ; ZoomFactor is 256 by default
idiv dword ptr Zt
;
add eax,eax ; This part is the equivalent of:
mov ebx,eax ; -----------
add eax,eax ; mov ecx,13
add ebx,eax ; imul ecx
add eax,eax ; -----------
add eax,ebx ;
;
sar eax,4
mov ebx,dword ptr CenterY
sub ebx,eax
mov dword ptr _2DY,ebx
jmp short @Outta2
@NoPerspective2:
; ---- _2DX:=CenterX+Trunc(Xt); ----
mov eax,dword ptr Xt
add eax,dword ptr CenterX
mov dword ptr _2DX,eax
; ---- _2DY:=CenterY-Trunc(Yt*13/16); ----
mov eax,dword ptr Yt
;
add eax,eax ; This part is the equivalent of:
mov ebx,eax ; -----------
add eax,eax ; mov ecx,13
add ebx,eax ; imul ecx
add eax,eax ; -----------
add eax,ebx ;
;
sar eax,4
mov ebx,dword ptr CenterY
sub ebx,eax
mov dword ptr _2DY,ebx
@Outta2:
retf
IntMapCoordinates2 endp
CODE ends
end