Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- ;calcul sur cette matrice:
- ;X_1 Z_2 Y_3 = \c_2 C_3 - S_2 c_2 S_3 \
- ; \ s_1 S_3 + c_1 C_3 S_2 c_1 c_2 c_1 S_2 S_3 - C_3 s_1 \
- ; \ C_3 s_1 S_2 - c_1 S_3 c_2 s_1 c_1 C_3 + s_1 S_2 S_3 \
- ;calcule la matris de rotation pour les angles x, y et z
- ;entrées: GRotateAngle_surX
- ; GRotateAngle_surY
- ; GRotateAngle_surZ
- ; SinTable : ta table de sinus
- gMatrix:
- .db 0,0,0,0,0,0,0,0,0,0,0,0,0,0,0,0 ;matrice 4*4
- gMatrixRotationCalcul:
- ;recherche des sinus et cosinus dans les tables
- ld d,0
- ld a,(GRotateAngle_surX)
- ld ixh,a
- ld a,(GRotateAngle_surY)
- ld ixl,a
- ld a,(GRotateAngle_surZ)
- ld c,a
- ld hl, SinTable
- ;sin x
- ld e, ixh
- add hl, de
- ld a, (hl)
- ld (gSin_X),a
- ;sin y
- ld hl, SinTable
- ld e, ixl
- add hl, de
- ld a, (hl)
- ld (gSin_Y),a
- ;sin z ; a revoir pour optimiser
- ld hl, SinTable
- ld e, c
- add hl, de
- ld a, (hl)
- ld (gSin_Z),a
- ;cos x
- ld hl, SinTable+128
- ld e, ixh
- sbc hl,de
- ld a, (hl)
- ld (gCos_X),a
- ;cos y
- ld hl, SinTable+128
- ld e, ixl
- sbc hl,de
- ld a, (hl)
- ld (gCos_Y),a
- ;cos z
- ld hl, SinTable+128
- ld e, c
- sbc hl,de
- ld a, (hl)
- ld (gCos_Z),a
- ;calculs
- ld hl, gCos_Y
- ld e , (hl)
- ld hl, gCos_Z
- ld h, (hl)
- call mult_h_e
- ld (gMatrix),a
- ld a,(gSin_Y)
- neg
- ld (gMatrix+1),a
- ld hl, gCos_Y
- ld e, (hl)
- inc hl
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+2),a
- ld hl, gSin_X
- ld e, (hl)
- ld hl, gSin_Z
- ld h,(hl)
- call mult_h_e
- ld a,c
- ld hl,gCos_X
- ld e, (hl)
- inc hl
- ld h, (hl)
- call mult_h_e
- ld e,a
- ld hl,gCos_Z
- ld h, (hl)
- call mult_h_e
- add a,c
- ld (gMatrix+4),a
- ld hl,gCos_X
- ld e,(hl)
- ld hl,gCos_Y
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+5),a
- ld hl, gCos_X
- ld e,(hl)
- inc hl ;gSin_Y
- ld h, (hl)
- call mult_h_e
- ld e,a
- ld hl, gSin_Z
- ld h, (hl)
- call mult_h_e
- ld c, a
- ld hl, gSin_X
- ld e, (hl)
- ld hl, gCos_Z
- ld h,(hl)
- call mult_h_e
- sub c
- ld (gMatrix+6),a
- ld hl,gSin_X
- ld e, (hl)
- ld hl,gSin_Y
- ld h, (hl)
- call mult_h_e
- ld e,a
- ld hl, gCos_Z
- ld h, (hl)
- call mult_h_e
- ld c, a
- ld hl, gCos_X
- ld e, (hl)
- ld hl, gSin_Z
- ld h, (hl)
- call mult_h_e
- sub c
- ld (gMatrix+8),a
- ld hl, gSin_X
- ld e, (hl)
- ld hl, gCos_Y
- ld h, (hl)
- call mult_h_e
- ld (gMatrix+9),a
- ld hl,gCos_X
- ld e,(hl)
- ld hl,gCos_Z
- ld h,(hl)
- call mult_h_e
- ld c,a
- ld hl, gSin_X
- ld e,(hl)
- ld hl, gSin_Y
- ld h, (hl)
- call mult_h_e
- ld e,a
- ld hl, gSin_Z
- ld h, (hl)
- call mult_h_e
- add a,c
- ld (gMatrix+10),a
- gSin_X:
- .db 0
- gCos_X:
- .db 0
- gSin_Y:
- .db 0
- gCos_Y:
- .db 0
- gSin_Z:
- .db 0
- gCos_Z:
- .db 0
- ;multiplie fixed point à 64 et retourne dans a
- mult_h_e
- ld l, 0
- ld d, l
- sla h ; optimised 1st iteration
- jr nc, $+3
- ld l, e
- ld b, 7
- _loop:
- add hl, hl
- jr nc, $+3
- add hl, de
- djnz _loop
- ;pour remettre au bon format fixed point
- ld a,l
- rla
- rla
- rla
- and 3
- ld l,a
- ld a,h
- rla
- rla
- or l
- ret
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement