![这个程序是巧妙的利用了坐标的不断变化_第1页](http://file3.renrendoc.com/fileroot_temp3/2022-2/18/7f0178e0-4223-4b0c-b61a-91cee29d5d6a/7f0178e0-4223-4b0c-b61a-91cee29d5d6a1.gif)
![这个程序是巧妙的利用了坐标的不断变化_第2页](http://file3.renrendoc.com/fileroot_temp3/2022-2/18/7f0178e0-4223-4b0c-b61a-91cee29d5d6a/7f0178e0-4223-4b0c-b61a-91cee29d5d6a2.gif)
![这个程序是巧妙的利用了坐标的不断变化_第3页](http://file3.renrendoc.com/fileroot_temp3/2022-2/18/7f0178e0-4223-4b0c-b61a-91cee29d5d6a/7f0178e0-4223-4b0c-b61a-91cee29d5d6a3.gif)
![这个程序是巧妙的利用了坐标的不断变化_第4页](http://file3.renrendoc.com/fileroot_temp3/2022-2/18/7f0178e0-4223-4b0c-b61a-91cee29d5d6a/7f0178e0-4223-4b0c-b61a-91cee29d5d6a4.gif)
![这个程序是巧妙的利用了坐标的不断变化_第5页](http://file3.renrendoc.com/fileroot_temp3/2022-2/18/7f0178e0-4223-4b0c-b61a-91cee29d5d6a/7f0178e0-4223-4b0c-b61a-91cee29d5d6a5.gif)
版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领
文档简介
1、;这个程序是巧妙的利用了坐标的不断变化,从而实现了由星星构成的箱子3D转动!;编译方法: 1 tasm 3d.asm; 2 tlink 3d.obj; 3 exe2bin 3d.exe ; Assembler Program By Vulture.
2、160; ; 3D-system example. Use the following formulas to rotate a p
3、oint: ; Rotate around x-axis
4、160; ; YT = Y * COS(xang) - Z * SIN(xang) / 256 &
5、#160; ; ZT = Y * SIN(xang) + Z * COS(xang) / 256
6、 ; Y = YT
7、60; ; Z = ZT
8、
9、 ;
10、0; ; Rotate around y-axis
11、; ; XT = X * COS(yang) - Z * SIN(yan
12、g) / 256 ; ZT = X * SIN(yang) + Z * COS(yang) / 256
13、60; ; X = XT
14、 ;
15、0; Z = ZT
16、60; ; Rotate around z-axis
17、0; ; XT = X * COS(zang) - Y * SIN(zang) / 256
18、60; ; YT = X * SIN(zang) + Y * COS(zang) / 256
19、160; ; X = XT
20、; ; Y = YT
21、160;
22、160; ; 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.
23、; ; Current Date: 6-9-95 Vulture
24、0; ;IDEAL ; Ideal modeP386
25、0; ; Allow 80386 instructionsJUMPS ; Tasm handles out of ran
26、ge jumps (rulez!:) SEGMENT CODE ; Code segment startsASSUME cs:code,ds:code ; Let cs and ds point to code segment ORG 100
27、h ; Make a .COM file START:
28、0; ; Main program mov ax,0013h ; Init vga int 10h mov ax,cs mov
29、60; ds,ax ; ds points to codesegment mov ax,0a000h mov es,ax
30、 ; es points to vga lea si,Palette ; Set palette mov dx,3c8h xor al,al out
31、0; dx,al mov dx,3c9h mov cx,189*3 repz outsb; = Set some variables = mov DeltaX,1
32、60; ; Initial speed of rotation mov DeltaY,1 ; Change this and watch what mov DeltaZ,1 ; happens. It
33、39;s fun! mov Xoff,256 mov Yoff,256 ; Used for calculating vga-pos mov Zoff,300
34、; ; Distance from viewerMainLoop: call MainProgram ; Yep. do it all. ;-) in al,60h
35、160; ; Scan keyboard cmp al,1 ; Test on ESCAPE jne MainLoop
36、; Continue if not keypressed; = Quit to DOS = mov ax,0003h ; Back to textmode int 10h lea dx,Credits
37、160; mov ah,9 int 21h mov ax,4c00h ; Return control to DOS int 21h
38、 ; Call DOS interrupt; = Sub-routines = PROC WaitVrt
39、160; ; Waits for vertical retrace to reduce "snow" mov dx,3dahVrt: in al,dx test al,8 jnz Vrt
40、; ; Wait until Verticle Retrace startsNoVrt: in al,dx test al,8 jz NoVrt
41、 ; Wait until Verticle Retrace ends ret ; Return to main programENDP WaitVrtPR
42、OC UpdateAngles; Calculates new x,y,z angles; to rotate around mov ax,XAngle ; Load current angles mov bx,YAngle mov cx,ZAngle
43、 add ax,DeltaX ; Add velocity and ax,11111111b ; Range from 0.255
44、 mov XAngle,ax ; Update X add bx,DeltaY ; Add velocity and bx,11111111b &
45、#160; ; Range from 0.255 mov YAngle,bx ; Update Y add cx,DeltaZ ; Add velocity
46、 and cx,11111111b ; Range from 0.255 mov ZAngle,cx ; Update Z retENDP UpdateAnglesPROC GetSinCos; Needed : bx=angle (0.2
47、55); Returns: ax=Sin bx=Cos push bx ; Save angle (use as pointer) shl bx,1
48、0; ; Grab a word so bx=bx*2 mov ax,SinCos + bx ; Get sine pop bx
49、160; ; Restore pointer into bx push ax ; Save sine on stack add bx,64
50、60; ; Add 64 to get cosine and bx,11111111b ; Range from 0.255 shl bx,1 &
51、#160; ; *2 coz it's a word mov ax,SinCos + bx ; Get cosine mov bx,ax ; Save it
52、160; bx=Cos pop ax ; Restore ax=Sin retENDP GetSinCosPROC SetRotation; Set sine & cosine of x,y,z
53、mov bx,XAngle ; Grab angle call GetSinCos ; Get the sine&cosine mov Xsin,ax
54、; ; Save sin mov Xcos,bx ; Save cos mov bx,Yangle call GetSinCos
55、160; mov Ysin,ax mov Ycos,bx mov bx,Zangle call GetSinCos mov Zsin,ax mov
56、; Zcos,bx retENDP SetRotationPROC 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
57、160; (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
58、 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
59、; bx ; ax = Y * Cos(xang) mov bp,ax mov ax,Z mov bx,XSin imu
60、l bx ; ax = Z * Sin(xang) sub bp,ax ; bp = Y * Cos(xang) - Z * Sin(xang)
61、 sar bp,8 ; bp = Y * Cos(xang) - Z * Sin(xang) / 256 mov Yt,bp mov ax,Y mov bx
62、,XSin imul bx ; ax = Y * Sin(xang) mov bp,ax mov ax,Z mov
63、60; bx,XCos imul bx ; ax = Z * Cos(xang) add bp,ax ; bp = Y * SIN(xang)
64、+ Z * COS(xang) sar bp,8 ; bp = Y * SIN(xang) + Z * COS(xang) / 256 mov Zt,bp mov ax,Yt
65、60; ; 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 *
66、COS(yang) / 256; X = XT; Z = ZT mov ax,X mov bx,YCos imul bx ; ax = X * Cos(yang)
67、60; mov bp,ax mov ax,Z mov bx,YSin imul bx ; ax = Z * Sin(yang)
68、60; sub bp,ax ; bp = X * Cos(yang) - Z * Sin(yang) sar bp,8 ; bp = X * Cos(yang) - Z * Sin
69、(yang) / 256 mov Xt,bp mov ax,X mov bx,YSin imul bx ;
70、ax = X * Sin(yang) mov bp,ax mov ax,Z mov bx,YCos imul bx
71、60; ; ax = Z * Cos(yang) add bp,ax ; bp = X * SIN(yang) + Z * COS(yang) sar bp,8
72、0; ; bp = X * SIN(yang) + Z * COS(yang) / 256 mov Zt,bp mov ax,Xt ; Switch values mov X,ax mov
73、160; 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
74、 imul bx ; ax = X * Cos(zang) mov bp,ax mov ax,Y mov b
75、x,ZSin imul bx ; ax = Y * Sin(zang) sub bp,ax ; bp = X * Cos(zang) - Y *
76、 Sin(zang) sar bp,8 ; bp = X * Cos(zang) - Y * Sin(zang) / 256 mov Xt,bp mov ax,X mo
77、v bx,ZSin imul bx ; ax = X * Sin(zang) mov bp,ax mov ax,Y
78、60; mov bx,ZCos imul bx ; ax = Y * Cos(zang) add bp,ax
79、 ; bp = X * SIN(zang) + Y * COS(zang) sar bp,8 ; bp = X * SIN(zang) + Y * COS(zang) / 256 mov Yt,bp mov
80、; ax,Xt ; Switch values mov X,ax mov ax,Yt mov Y,ax retENDP RotatePoint &
81、#160; PROC ShowPoint; Calculates screenposition and; plots the point on the screen mov ax,Xoff ; Xoff*X / Z+Zoff = screen x mov
82、; bx,X imul bx mov bx,Z add bx,Zoff ; Distance idiv bx add
83、160; ax,Mx ; Center on screen mov bp,ax mov ax,Yoff ; Yoff*Y / Z+Zoff =
84、screen y mov bx,Y imul bx mov bx,Z add bx,Zoff ; Distance id
85、iv bx add ax,My ; Center on screen mov bx,320 i
86、mul bx add ax,bp ; ax = (y*320)+x mov di,ax mov ax,Z
87、160; ; Get color from Z add ax,100d ; (This piece of code could be improved) mov byte ptr
88、es:di,al ; Place a dot with color al mov Erase+si,di ; Save position for erase retENDP ShowPointPROC MainProgram call UpdateAngles
89、160; ; Calculate new angles call SetRotation ; Find sine & cosine of those angles xor si,si &
90、#160; ; First 3d-point mov cx,MaxPointsShowLoop: call RotatePoint ; Rotates the point using above formulas call ShowPoint
91、0; ; Shows the point add si,3 ; Next 3d-point loop ShowLoop call
92、160; WaitVrt ; Wait for retrace xor si,si ; Starting with point 0 xor
93、60; al,al ; Color = 0 = black mov cx,MaxPointsDeletion: mov di,Erase+si ; di =
94、 vgapos old point mov byte ptr es:di,al ; Delete it add si,3 ; Next point loop Deletion
95、60; retENDP MainProgram; = DATA = Credits DB 13,10,"Code by Vulture / Outlaw Triad",13,10,"$"Label SinCos Word ; 256 valuesdw 0,6,13,19,25,31,38,44,
96、50,56dw 62,68,74,80,86,92,98,104,109,115dw 121,126,132,137,142,147,152,157,162,167dw 172,177,181,185,190,194,198,202,206,209dw 213,216,220,223,226,229,231,234,237,239dw 241,243,245,247,248,250,251,252,253,254dw 255,255,256,256,256,256,256,255,255,254dw 253,252,251,250,248,247,245,243,241,239dw 237,2
97、34,231,229,226,223,220,216,213,209dw 206,202,198,194,190,185,181,177,172,167dw 162,157,152,147,142,137,132,126,121,115dw 109,104,98,92,86,80,74,68,62,56dw 50,44,38,31,25,19,13,6,0,-6dw -13,-19,-25,-31,-38,-44,-50,-56,-62,-68dw -74,-80,-86,-92,-98,-104,-109,-115,-121,-126dw -132,-137,-142,-147,-152,-
98、157,-162,-167,-172,-177dw -181,-185,-190,-194,-198,-202,-206,-209,-213,-216dw -220,-223,-226,-229,-231,-234,-237,-239,-241,-243dw -245,-247,-248,-250,-251,-252,-253,-254,-255,-255dw -256,-256,-256,-256,-256,-255,-255,-254,-253,-252dw -251,-250,-248,-247,-245,-243,-241,-239,-237,-234dw -231,-229,-226
99、,-223,-220,-216,-213,-209,-206,-202dw -198,-194,-190,-185,-181,-177,-172,-167,-162,-157dw -152,-147,-142,-137,-132,-126,-121,-115,-109,-104dw -98,-92,-86,-80,-74,-68,-62,-56,-50,-44dw -38,-31,-25,-19,-13,-6Label Cube Byte ; The 3d points
100、60; c = -35 ; 5x*5y*5z (=125) points rept 5 b = -35 rept 5 a = -35 rept 5
温馨提示
- 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
- 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
- 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
- 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
- 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
- 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
- 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。
最新文档
- 2025年全球及中国隐形渗透性密封剂行业头部企业市场占有率及排名调研报告
- 山东省日照市高三上学期期末考试语文试卷(含答案)
- 2025会议 展览合同
- 2025机动车买卖合同模板
- 运输类合同范本
- 南宁房屋租赁服务合同模板
- 2025建筑施工物资租赁合同示范文本无担保方
- 鸡蛋供货采购合同
- 借款用于投资合同
- 技能培训中的表达技巧训练
- 2024年资格考试-对外汉语教师资格证笔试参考题库含答案
- 2024年4月自考02382管理信息系统答案及评分参考
- (苏版)初三化学上册:第2单元课题1空气
- 2023年12月广东珠海市轨道交通局公开招聘工作人员1人笔试近6年高频考题难、易错点荟萃答案带详解附后
- 腹腔镜肾上腺肿瘤切除术查房护理课件
- 燃气罩式炉应急预案
- 专题23平抛运动临界问题相遇问题类平抛运和斜抛运动
- 超声科医德医风制度内容
- 高三开学收心班会课件
- 蒸汽换算计算表
- 四年级计算题大全(列竖式计算,可打印)
评论
0/150
提交评论