Двух- и трехмерное вращение
Двухмерное и трехмерное вращение. Исходники маленьких программ на ассемблере. Прилагаются таблицы синусов и косинусов
Двухмерное вращение
;
; 2d Rotation, Coded by Ash [NLB/BD]
; Allmost no comments.. I'm sorry :(
;
p386
ideal
segment code
assume cs:code
org 100h
start:
mov ax,13h
int 10h
push 0a000h
pop es
mainloop: call docordz ; mainloop
call keyc
call vwait
call killthem
jmp mainloop
outnow: mov ax,3 ; the end
int 10h
mov ax,4c00h
int 21h
docordz: add [angle],2
and [angle],255
xor bp,bp
mov si,[angle] ; get sin(a) & cos(a)
movsx ax,[sincos+si]
mov [sinval],ax
add si,64
and si,255
movsx ax,[sincos+si]
mov [cosval],ax
dumpnow: mov ax,[cordz+bp] ; x
imul [cosval]
mov di,ax
mov ax,[cordz+bp+2] ; y
imul [sinval] ; sin + angle
sub di,ax
sar di,7
add di,160
mov bx,di
mov ax,[cordz+bp] ; x
imul [sinval]
mov di,ax
mov ax,[cordz+bp+2] ; y
imul [cosval]
add di,ax
sar di,7
add di,100
mov ax,320
imul di
add ax,bx
mov di,ax
mov [deltable+bp],di
mov [byte es:di],15
add bp,4
cmp bp,points*4
jne dumpnow
ret
killthem: xor bp,bp
mov cx,points
killem: mov di,[deltable+bp]
mov [byte es:di],0
add bp,4
loop killem
ret
vwait: mov dx,3dah ; vertical retrace
in al,dx
test al,8
jne $-3
in al,dx
test al,8
je $-3
ret
keyc: in al,60h ; last key scan
cmp al,1
je outnow
ret
label cordz word
b = -50
rept 12
a = -55
rept 12
dw a,b
a = a + 10
endm
b = b + 10
endm
angle dw 0
cosval dw ?
sinval dw ?
points equ 12*12
include "sincos.db"
deltable dw points*4 dup (?)
ends code
end start
Трехмерное вращение
;
; 3d Rotation, coded by Ash [NLB/BD]
; Sorry that did'nt commented it too well :(
;
ideal
p386n
segment code
assume cs:code
org 100h
start:
mov ax,13h ; init vga
int 10h
push 0a000h
pop es
mainloop: add [xangle],1 ; increase x,y,z-angles
and [xangle],255
add [yangle],1
and [yangle],255
add [zangle],1
and [zangle],255
mov bx,[xangle] ; get x,y,z,-sin/cos value
movsx bp,[sincos+bx]
mov [xsin],bp
add bx,64
and bx,255
movsx bp,[sincos+bx]
mov [xcos],bp
mov bx,[yangle]
movsx bp,[sincos+bx]
mov [ysin],bp
add bx,64
and bx,255
movsx bp,[sincos+bx]
mov [ycos],bp
mov bx,[zangle]
movsx bp,[sincos+bx]
mov [zsin],bp
add bx,64
and bx,255
movsx bp,[sincos+bx]
mov [zcos],bp
xor si,si
morepoints: mov ax,[coords+si+2] ; do calculations
imul [xcos]
mov bp,ax
mov ax,[coords+si+4]
imul [xsin]
sub bp,ax
mov [yt],bp
mov ax,[coords+si+2]
imul [xsin]
mov bp,ax
mov ax,[coords+si+4]
imul [xcos]
add bp,ax
mov [zt],bp
mov ax,[yt]
sar ax,7
mov [y],ax
mov ax,[zt]
sar ax,7
mov [z],ax
mov ax,[coords+si]
imul [ycos]
mov bp,ax
mov ax,[z]
imul [ysin]
sub bp,ax
mov [xt],bp
mov ax,[coords+si]
imul [ysin]
mov bp,ax
mov ax,[z]
imul [ycos]
add bp,ax
mov [zt],bp
mov ax,[xt]
sar ax,7
mov [x],ax
mov ax,[zt]
sar ax,7
mov [z],ax
mov ax,[x]
imul [zcos]
mov bp,ax
mov ax,[y]
imul [zsin]
sub bp,ax
mov [xt],bp
mov ax,[x]
imul [zsin]
mov bp,ax
mov ax,[y]
imul [zcos]
add bp,ax
mov [yt],bp
mov ax,[xt]
sar ax,7
mov [x],ax
mov ax,[yt]
sar ax,7
mov [y],ax
mov ax,200
imul [x]
mov bp,[z]
add bp,200
idiv bp
add ax,160
mov cx,ax
mov ax,200
imul [y]
mov bp,[z]
add bp,200
idiv bp
add ax,100
mov di,ax
shl di,8
shl ax,6
add di,ax
add di,cx
mov [erase+si],di
mov [byte es:di],15
add si,6
cmp si,points
jne morepoints
mov dx,3dah
in al,dx
test al,8
jne $-3
in al,dx
test al,8
je $-3
xor si,si ; erase the points again
killem: mov di,[erase+si]
mov [byte es:di],0
add si,6
cmp si,points
jne killem
in al,60h
cmp al,1
jne mainloop
mov ax,3
int 10h
mov ax,4c00h
int 21h
points equ 200*3
xangle dw 0
yangle dw 0
zangle dw 0
xsin dw ?
xcos dw ?
ysin dw ?
ycos dw ?
zsin dw ?
zcos dw ?
xt dw ?
yt dw ?
zt dw ?
x dw ?
y dw ?
z dw ?
include "sincos.db"
include "coords.db"
erase dw points dup (?)
ends code
end start
Таблица координат точек
label coords word DB 0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0 DB 0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0 DB 60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0 DB 0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0 DB 0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0 DB 60,0,0,0,0,0,60,0,0,0,0,0,60,0,0,0,0,0,60,0 DB 0,0,42,0,42,0,14,0,40,0,42,0,26,0,33,0,42,0,36,0 DB 23,0,42,0,41,0,10,0,42,0,42,0,252,255,42,0,39,0,239,255 DB 42,0,31,0,227,255,42,0,20,0,219,255,42,0,7,0,214,255,42,0 DB 249,255,214,255,42,0,236,255,219,255,42,0,225,255,227,255,42,0,217,255 DB 239,255,42,0,214,255,252,255,42,0,215,255,10,0,42,0,220,255,23,0 DB 42,0,230,255,33,0,42,0,242,255,40,0,42,0,0,0,42,0,42,0 DB 0,0,60,0,0,0,19,0,57,0,0,0,37,0,47,0,0,0,50,0 DB 33,0,0,0,58,0,15,0,0,0,60,0,251,255,0,0,55,0,232,255 DB 0,0,44,0,215,255,0,0,29,0,203,255,0,0,10,0,197,255,0,0 DB 246,255,197,255,0,0,227,255,203,255,0,0,212,255,215,255,0,0,201,255 DB 232,255,0,0,196,255,251,255,0,0,198,255,15,0,0,0,206,255,33,0 DB 0,0,219,255,47,0,0,0,237,255,57,0,0,0,0,0,60,0,0,0 DB 0,0,42,0,214,255,14,0,40,0,214,255,26,0,34,0,214,255,36,0 DB 23,0,214,255,41,0,10,0,214,255,42,0,252,255,214,255,39,0,239,255 DB 214,255,31,0,227,255,214,255,20,0,219,255,214,255,7,0,214,255,214,255 DB 249,255,214,255,214,255,236,255,219,255,214,255,225,255,227,255,214,255,217,255 DB 239,255,214,255,214,255,252,255,214,255,215,255,10,0,214,255,220,255,23,0 DB 214,255,230,255,34,0,214,255,242,255,40,0,214,255,0,0,42,0,214,255 DB 0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0 DB 0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0 DB 196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255 DB 0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0 DB 0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0 DB 196,255,0,0,0,0,196,255,0,0,0,0,196,255,0,0,0,0,196,255
Таблица синусов и косинусов
label sincos byte DB 0,3,6,9,12,16,19,22,25,28,31,34,37,40,43,46,49,51,54,57 DB 60,63,65,68,71,73,76,78,81,83,85,88,90,92,94,96,98,100,102,104 DB 106,107,109,111,112,113,115,116,117,118,120,121,122,122,123,124,125,125,126,126 DB 126,127,127,127,127,127,127,127,126,126,126,125,125,124,123,122,122,121,120,118 DB 117,116,115,113,112,111,109,107,106,104,102,100,98,96,94,92,90,88,85,83 DB 81,78,76,73,71,68,65,63,60,57,54,51,49,46,43,40,37,34,31,28 DB 25,22,19,16,12,9,6,3,0,253,250,247,244,240,237,234,231,228,225,222 DB 219,216,213,210,207,205,202,199,196,193,191,188,185,183,180,178,175,173,171,168 DB 166,164,162,160,158,156,154,152,150,149,147,145,144,143,141,140,139,138,136,135 DB 134,134,133,132,131,131,130,130,130,129,129,129,129,129,129,129,130,130,130,131 DB 131,132,133,134,134,135,136,138,139,140,141,143,144,145,147,149,150,152,154,156 DB 158,160,162,164,166,168,171,173,175,178,180,183,185,188,191,193,196,199,202,205 DB 207,210,213,216,219,222,225,228,231,234,237,240,244,247,250,253
Оставить комментарий
Комментарии
1.


28 апреля 2021, 08:37:31
извините, что не по теме, но если вам нужны услуги по продвижению сайтов, то вам сюда https://incatalog.kz/
[Ссылка]
О нас
http://www.incatalog.kz
[Ссылка]
О нас
http://www.incatalog.kz
2.
+1 / -0


24 октября 2009, 18:17:11
Надо будет попробовать набрать)
3.
+1 / -0


30 апреля 2006, 14:21:28
Выборка из памяти намного быстрее чем прямое вычисление тригонометрической функции. Даже на языках высокого уровня иногда прибегают и такому методу. В частности таблицы синусов используются в коде Quake2
4.
+1 / -0


26 апреля 2006, 21:20:55
Может я не прав, но почему бы не использовать математический сопроцессор. В частности команду высчитывающую тангенс?
5.
+2 / -0


20 марта 2005, 03:57:23
Самое лучшее вращение - матричное преобразование!
