;本程序由国外的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
ENDP UpdateAngles
PROC GetSinCos
; Needed : bx=angle (0..255)
; Returns: ax=Sin bx=Cos
push bx ; Save angle (use as pointer)
shl bx,1 ; Grab a word so bx=bx*2
mov ax,[SinCos + bx] ; Get sine
pop bx ; Restore pointer into bx
push ax ; Save sine on stack
add bx,64 ; Add 64 to get cosine
and bx,11111111b ; Range from 0..255
shl bx,1 ; *2 coz it's a word
mov ax,[SinCos + bx] ; Get cosine
mov bx,ax ; Save it bx=Cos
pop ax ; Restore ax=Sin
ret
ENDP GetSinCos
PROC SetRotation
; Set sine & cosine of x,y,z
mov bx,[XAngle] ; Grab angle
call GetSinCos ; Get the sine&cosine
mov [Xsin],ax ; Save sin
mov [Xcos],bx ; Save cos
mov bx,[Yangle]
call GetSinCos
mov [Ysin],ax
mov [Ycos],bx
mov bx,[Zangle]
call GetSinCos
mov [Zsin],ax
mov [Zcos],bx
ret
ENDP SetRotation
PROC RotatePoint ; Rotates the point around x,y,z
; Gets original x,y,z values
; This can be done elsewhere
movsx ax,[Cube+si] ; si = X (movsx coz of byte)
mov [X],ax
movsx ax,[Cube+si+1] ; si+1 = Y
mov [Y],ax
movsx ax,[Cube+si+2] ; si+2 = Z
mov [Z],ax
; Rotate around x-axis
; YT = Y * COS(xang) - Z * SIN(xang) / 256
; ZT = Y * SIN(xang) + Z * COS(xang) / 256
; Y = YT
; Z = ZT
mov ax,[Y]
mov bx,[XCos]
imul bx ; ax = Y * Cos(xang)
mov bp,ax
mov ax,[Z]
mov bx,[XSin]
imul bx ; ax = Z * Sin(xang)
sub bp,ax ; bp = Y * Cos(xang) - Z * Sin(xang)
sar bp,8 ; bp = Y * Cos(xang) - Z * Sin(xang) / 256
mov [Yt],bp
mov ax,[Y]
mov bx,[XSin]
imul bx ; ax = Y * Sin(xang)
mov bp,ax
mov ax,[Z]
mov bx,[XCos]
imul bx ; ax = Z * Cos(xang)
add bp,ax ; bp = Y * SIN(xang) + Z * COS(xang)
sar bp,8 ; bp = Y * SIN(xang) + Z * COS(xang) / 256
mov [Zt],bp
mov ax,[Yt] ; Switch values
mov [Y],ax
mov ax,[Zt]
mov [Z],ax
; Rotate around y-axis
; XT = X * COS(yang) - Z * SIN(yang) / 256
; ZT = X * SIN(yang) + Z * COS(yang) / 256
; X = XT
; Z = ZT
mov ax,[X]
mov bx,[YCos]
imul bx ; ax = X * Cos(yang)
mov bp,ax
mov ax,[Z]
mov bx,[YSin]
imul bx ; ax = Z * Sin(yang)
sub bp,ax ; bp = X * Cos(yang) - Z * Sin(yang)
sar bp,8 ; bp = X * Cos(yang) - Z * Sin(yang) / 256
mov [Xt],bp
mov ax,[X]
mov bx,[YSin]
imul bx ; ax = X * Sin(yang)
mov bp,ax
mov ax,[Z]
mov bx,[YCos]
imul bx ; ax = Z * Cos(yang)
add bp,ax ; bp = X * SIN(yang) + Z * COS(yang)
sar bp,8 ; bp = X * SIN(yang) + Z * COS(yang) / 256
mov [Zt],bp
mov ax,[Xt] ; Switch values
mov [X],ax
mov ax,[Zt]
mov [Z],ax
; Rotate around z-axis
; XT = X * COS(zang) - Y * SIN(zang) / 256
; YT = X * SIN(zang) + Y * COS(zang) / 256
; X = XT
; Y = YT
mov ax,[X]
mov bx,[ZCos]
imul bx ; ax = X * Cos(zang)
mov bp,ax
mov ax,[Y]
mov bx,[ZSin]
imul bx ; ax = Y * Sin(zang)
sub bp,ax ; bp = X * Cos(zang) - Y * Sin(zang)
sar bp,8 ; bp = X * Cos(zang) - Y * Sin(zang) / 256
mov [Xt],bp
mov ax,[X]
mov bx,[ZSin]
imul bx ; ax = X * Sin(zang)
mov bp,ax
mov ax,[Y]
mov bx,[ZCos]
imul bx ; ax = Y * Cos(zang)
add bp,ax ; bp = X * SIN(zang) + Y * COS(zang)
sar bp,8 ; bp = X * SIN(zang) + Y * COS(zang) / 256
mov [Yt],bp
mov ax,[Xt] ; Switch values
mov [X],ax
mov ax,[Yt]
mov [Y],ax
ret
ENDP RotatePoint
PROC ShowPoint
; Calculates screenposition and
; plots the point on the screen
mov ax,[Xoff] ; Xoff*X / Z+Zoff = screen x
mov bx,[X]
imul bx
mov bx,[Z]
add bx,[Zoff] ; Distance
idiv bx
add ax,[Mx] ; Center on screen
mov bp,ax
mov ax,[Yoff] ; Yoff*Y / Z+Zoff = screen y
mov bx,[Y]
imul bx
mov bx,[Z]
add bx,[Zoff] ; Distance
idiv bx
add ax,[My] ; Center on screen
mov bx,320
imul bx
add ax,bp ; ax = (y*320)+x
mov di,ax
mov ax,[Z] ; Get color from Z
add ax,100d ; (This piece of code could be improved)
mov [byte ptr es:di],al ; Place a dot with color al
mov [Erase+si],di ; Save position for erase
ret
ENDP ShowPoint
PROC MainProgram
call UpdateAngles ; Calculate new angles
call SetRotation ; Find sine & cosine of those angles
xor si,si ; First 3d-point
mov cx,MaxPoints
ShowLoop:
call RotatePoint ; Rotates the point using above formulas
call ShowPoint ; Shows the point
add si,3 ; Next 3d-point
loop ShowLoop
call WaitVrt ; Wait for retrace
xor si,si ; Starting with point 0
xor al,al ; Color = 0 = black
mov cx,MaxPoints
Deletion:
mov di,[Erase+si] ; di = vgapos old point
mov [byte ptr es:di],al ; Delete it
add si,3 ; Next point
loop Deletion
ret
ENDP MainProgram
; === DATA ===
Credits DB 13,10,"Code by Vulture / Outlaw Triad",13,10,"$"
Label SinCos Word ; 256 values
dw 0,6,13,19,25,31,38,44,50,56
dw 62,68,74,80,86,92,98,104,109,115
dw 121,126,132,137,142,147,152,157,162,167
dw 172,177,181,185,190,194,198,202,206,209
dw 213,216,220,223,226,229,231,234,237,239
dw 241,243,245,247,248,250,251,252,253,254
dw 255,255,256,256,256,256,256,255,255,254
dw 253,252,251,250,248,247,245,243,241,239
dw 237,234,231,229,226,223,220,216,213,209
dw 206,202,198,194,190,185,181,177,172,167
dw 162,157,152,147,142,137,132,126,121,115
dw 109,104,98,92,86,80,74,68,62,56
dw 50,44,38,31,25,19,13,6,0,-6
dw -13,-19,-25,-31,-38,-44,-50,-56,-62,-68
dw -74,-80,-86,-92,-98,-104,-109,-115,-121,-126
dw -132,-137,-142,-147,-152,-157,-162,-167,-172,-177
dw -181,-185,-190,-194,-198,-202,-206,-209,-213,-216
dw -220,-223,-226,-229,-231,-234,-237,-239,-241,-243
dw -245,-247,-248,-250,-251,-252,-253,-254,-255,-255
dw -256,-256,-256,-256,-256,-255,-255,-254,-253,-252
dw -251,-250,-248,-247,-245,-243,-241,-239,-237,-234
dw -231,-229,-226,-223,-220,-216,-213,-209,-206,-202
dw -198,-194,-190,-185,-181,-177,-172,-167,-162,-157
dw -152,-147,-142,-137,-132,-126,-121,-115,-109,-104
dw -98,-92,-86,-80,-74,-68,-62,-56,-50,-44
dw -38,-31,-25,-19,-13,-6
Label Cube Byte ; The 3d points
c = -35 ; 5x*5y*5z (=125) points
rept 5
b = -35
rept 5
a = -35
rept 5
db a,b,c
a = a + 20
endm
b = b + 20
endm
c = c + 20
endm
Label Palette Byte ; The palette to use
db 0,0,0 ; 63*3 gray-tint
d = 63
rept 63
db d,d,d
db d,d,d
db d,d,d
d = d - 1
endm
X DW ? ; X variable for formula
Y DW ?
Z DW ?
Xt DW ? ; Temporary variable for x
Yt DW ?
Zt DW ?
XAngle DW 0 ; Angle to rotate around x
YAngle DW 0
ZAngle DW 0
DeltaX DW ? ; Amound Xangle is increased each time
DeltaY DW ?
DeltaZ DW ?
Xoff DW ?
Yoff DW ?
Zoff DW ? ; Distance from viewer
XSin DW ? ; Sine and cosine of angle to rotate around
XCos DW ?
YSin DW ?
YCos DW ?
ZSin DW ?
ZCos DW ?
Mx DW 160 ; Middle of the screen
My DW 100
MaxPoints EQU 125 ; Number of 3d Points
Erase DW MaxPoints DUP (?) ; Array for deletion screenpoints
ENDS CODE ; End of codesegment
END START ; The definite end.... :)
; You may use this code in your own productions but
; give credit where credit is due. Only lamers steal
; code so try to create your own 3d-engine and use
; this code as an example.
; Thanx must go to Arno Brouwer and Ash for releasing
; example sources.
;
; Ciao dudoz,
;
; Vulture / Outlaw Triad
汇编源代码之一个旋转的3D箱子(动画)
时间: 2024-08-22 10:12:04
汇编源代码之一个旋转的3D箱子(动画)的相关文章
Flash 3D旋转和3D位移
核心提示:Flash CS4的3D工具很容易上手.在工具栏里有两个处理3D变形的工具:3D旋转和3D位移. Flash CS4的3D工具很容易上手.在工具栏里有两个处理3D变形的工具:3D旋转和3D位移. 这两个工具都可以切换全局坐标模式和个体坐标模式,上图为个体坐标模式. 另外,也可以通过属性面板和变形面板来调整3D变形的参数.其中值得注意的是灭点(消失点)和相机范围角度(不是焦距)的设置.这两个参数对整个场景内的所有元件,以及嵌套的元件都产生影响.也就是说,一个场景的灭点和相机范围角是唯一的
FLASH3D旋转和3D位移
Flash CS4的3D工具很容易上手.在工具栏里有两个处理3D变形的工具:3D旋转和3D位移. 这两个工具都可以切换全局坐标模式和个体坐标模式,上图为个体坐标模式. 另外,也可以通过属性面板和变形面板来调整3D变形的参数.其中值得注意的是灭点(消失点)和相机范围角度(不是焦距)的设置.这两个参数对整个场景内的所有元件,以及嵌套的元件都产生影响.也就是说,一个场景的灭点和相机范围角是唯一的.灭点的默认位置是Stage的正中间. 如果一个元件(MovieClip)已经被施加了3D变形,那么进入
介绍一种作仿3D flash动画的方法
flash动画 引言严格来说,这不是一篇教程,这篇文章的旨在目的是向还没有接触过Vector类的闪友介绍.推荐Vector类,利用它的方便,简洁以及它的强大功能作出更加完美的动画,特别是模仿3D的动画,说到Vector类,必须说到一个人--Robert Penner,是他在<Flash Mx编程与创意实现>一书中为它赋予了生命与灵魂(我是这么认为的)(先声明这不是做广告).这本书在几年前就出版了,应该很多闪友已经看过了,我是在几个月前才知道和看到的(有点井底之蛙,可别取笑我),当我看到其中的V
原生javascript+css3编写的3D魔方动画旋扭特效_javascript技巧
一直从事于后端编程工作,工作中也经常接触和使用一些前端技术,但大多数还是用于操作和控制数据与客户端交互工作.随着互联网技术的发展以及硬件性能的不断提升,人们对于交互式体验已变得越来越重视,进而前端技术已经越来越突显出它的重要性,特别是一些炫酷的特效,精美的UI设计,都使人眼前一亮,顿时觉得网站平台都高大上不少,很博人们眼球,给人们以很好的视觉冲击,特别是现在的css3,HTML5技术的更新,使得以更小的代价就可以轻松实现这些效果,故此,顿时膜拜起前端技术,悠然起了兴趣,跃跃欲试,随机利用css3
PhotoShop CS5制作转动的3D地球动画教程
教程主要使用Photoshop制作转动的3D地球动画教程,制作方法并不难,但是Photoshop CS5中的3D功能它对显卡的要求比较高, 大家也可以动手尝试制作一下属于自己的东东. 最终效果: 1.打开素材,使用矩形选框工具,绘制选区后,执行-编辑-填充,使用内容填充可以快速的把素材中的文字给处理掉,如图. 2.简单的处理完文字之后,复制一层,把背景层填充黑色,因为我们需要对地球素材还要做进一步调整.选择背景副本图层,点击鼠标右键, 选择图层的混合选项,找到混合颜色带,按住ALT键,移动滑块到
小白也会:如何用Photoshop制作3D人物动画
为了降低使用Photoshop制作3D人物动画的操作难度和学习成本,Adobe正式宣布收购了3D角色与动画在线生成平台Mixamo.这意味着,在未来,我们看到的3D电影.3D游戏动画将极有可能出自"制图神器",小白用户都可以把自己的脸套到3D人物动画中! 随着3D技术以及VR的发展,未来对高质量3D内容的需求会逐渐增多;而硬件的发展也让3D内容编辑越来越方便,甚至在平板电脑上就可以进行. Adobe去年开始着手在Photosho CC中加入一些3D创建的功能,近日这家创意工具巨头在
ios弃用故事板之后就设备旋转就不再有动画了,怎么破
问题描述 ios弃用故事板之后就设备旋转就不再有动画了,怎么破 解决方案 响应设备旋转事件,然后再次调用动画
国内首部以三国历史为背景的3D微动画系列剧
<三国游侠>3D微动画系列剧<涂墙三国>于今日爆笑登场.这将是国内首部以三国历史为背景的3D微动画系列剧.该剧由曾经打造过魔兽世界大型连载动画片<联盟的勇士>而闻名业界,著名的虚拟印象动画工作室倾心制作,故事风格幽默.轻松.搞笑,将为大家展现一个妙趣横生的别样三国. <涂墙三国>刘关张三兄弟起兵征伐黄巾军 <涂墙三国>简介 <涂墙三国>以三国历史为背景,剧本取材于玩家们喜闻乐见的三国历史.典故.演义,以幽默.轻松.搞笑的故事风格,演绎
Groboto一款3D建模动画应用软件概述及安装指南
Braid Art Labs推出3D建模动画应用软件GroBoto.这款软件可以创建复杂的动画效果,易于使用.它的http://www.aliyun.com/zixun/aggregation/8437.html">目标群体为十岁以上的人群. 透过groBoto可以快速且直观地在数分钟里创建出三维图象,也可以很快在数分钟内看见令人激动和愉快的三维图象,可以完全支持MAC和PC作业平台.智能算法绘图工具:可以创建几何形态,包括抽象和现实的:可以调整Bot性能,用户可以创建并保存没有限制的改变