;本程序由国外的Vulture大哥编写,并公布了源码,这个是他95年的一个作品,可以说是在当时是非常成功的!
;这个程序是巧妙的利用了坐标的不断变化,从而实现了由星星构成的箱子3D转动!
;为了尊重版权,本人未对源码注释进行翻译,这样做也可以让国内的汇编爱好者自己琢磨国外的汇编编程的思维! 逆风编程精品
;编译方法: 1 tasm 3d.asm
; 2 tlink 3d.obj
; 3 exe2bin 3d.exe 3d.com
;本程序是站长精心收集的一个很经典的3D小动画. 站长的x86汇编小站:http://www.x86asm.com
; 永久域名:http://x86asm.yeah.net
;==============================================================================; ; ; ; Assembler Program By Vulture. ; ; 3D-system example. Use the following formulas to rotate a point: ; ; ; ; Rotate around x-axis ; ; YT = Y * COS(xang) - Z * SIN(xang) / 256 ; ; ZT = Y * SIN(xang) Z * COS(xang) / 256 ; ; Y = YT ; ; Z = ZT ; ; ; ; Rotate around y-axis ; ; XT = X * COS(yang) - Z * SIN(yang) / 256 ; ; ZT = X * SIN(yang) Z * COS(yang) / 256 ; ; X = XT ; ; Z = ZT ; ; ; ; Rotate around z-axis ; ; XT = X * COS(zang) - Y * SIN(zang) / 256 ; ; YT = X * SIN(zang) Y * COS(zang) / 256 ; ; X = XT ; ; Y = YT ; ; ; ; Divide by 256 coz we have multiplyd our sin values with 256 too. ; ; This example isn't too fast right now but it'll work just fine. ; ; ; ; Current Date: 6-9-95 Vulture ; ; ; ;==============================================================================;
IDEAL ; Ideal mode P386 ; Allow 80386 instructions JUMPS ; Tasm handles out of range jumps (rulez!:)) SEGMENT CODE ; Code segment starts ASSUME cs:code,ds:code ; Let cs and ds point to code segment
ORG 100h ; Make a .COM file
START: ; Main program
mov ax,0013h ; Init vga int 10h mov ax,cs mov ds,ax ; ds points to codesegment mov ax,0a000h mov es,ax ; es points to vga
lea si,[Palette] ; Set palette mov dx,3c8h xor al,al out dx,al mov dx,3c9h mov cx,189*3 repz outsb
; === Set some variables === mov [DeltaX],1 ; Initial speed of rotation mov [DeltaY],1 ; Change this and watch what mov [DeltaZ],1 ; happens. It's fun!
mov [Xoff],256 mov [Yoff],256 ; Used for calculating vga-pos mov [Zoff],300 ; Distance from viewer
MainLoop: call MainProgram ; Yep... do it all... ;-)
in al,60h ; Scan keyboard cmp al,1 ; Test on ESCAPE jne MainLoop ; Continue if not keypressed
; === Quit to DOS === mov ax,0003h ; Back to textmode int 10h lea dx,[Credits] mov ah,9 int 21h mov ax,4c00h ; Return control to DOS int 21h ; Call DOS interrupt
; === Sub-routines === PROC WaitVrt ; Waits for vertical retrace to reduce "snow" mov dx,3dah Vrt: in al,dx test al,8 jnz Vrt ; Wait until Verticle Retrace starts NoVrt: in al,dx test al,8 jz NoVrt ; Wait until Verticle Retrace ends ret ; Return to main program ENDP WaitVrt
PROC UpdateAngles ; Calculates new x,y,z angles ; to rotate around mov ax,[XAngle] ; Load current angles mov bx,[YAngle] mov cx,[ZAngle] add ax,[DeltaX] ; Add velocity and ax,11111111b ; Range from 0..255 mov [XAngle],ax ; Update X add bx,[DeltaY] ; Add velocity and bx,11111111b ; Range from 0..255 mov [YAngle],bx ; Update Y add cx,[DeltaZ] ; Add velocity and cx,11111111b ; Range from 0..255 mov [ZAngle],cx ; Update Z ret
本文章更多内容:1 - 2 - 3 - 4 - 下一页>> |