'=========================================================================== ' Subject: 2D TEXTURE ZOOM/ROTATION DEMO Date: 04-10-97 (19:58) ' Author: Toshihiro Horie Code: QB, QBasic, PDS ' Origin: comp.lang.basic.misc Packet: GRAPHICS.ABC '=========================================================================== '2d texture zoom/rotation demo 'seriously fast now 30+ fps on 486 'by Toshihiro Horie 'toshiman@uclink4.berkeley.edu DEFINT A-Z 'possible modifications: '3) reverse rotation mapping xh = 40: yh = 30: ch = 16 xd = 160: yd = 100 v = 0: w = 1 DIM C(360): DIM S(360) 'set up sinus tables deg2rad# = .01745329# PRINT "Calculating sinus tables..." FOR t = 0 TO 179 C(t) = COS(t * deg2rad#) * 128 S(t) = SIN(t * deg2rad#) * 128 NEXT FOR t = 180 TO 359 S(t) = -S(t - 180) C(t) = C(360 - t) NEXT SCREEN 7, , v, w 'plot some points in a box 'LINE (0, 0)-(xh, yh), 15, B DIM block(xh, yh) FOR t = 1 TO 100 x = INT(RND * xh): y = INT(RND * yh) C = INT(RND * ch) 'PSET (x, y), C block(x, y) = C NEXT 'rotate it about its center z = 2: num = 1: ST = 1 DO A = (A + ST) MOD 360 k$ = INKEY$ IF k$ = "8 " THEN z = z + 1 IF k$ = "2" THEN z = z - 1 IF k$ = "6" THEN ST = ST + 1 IF k$ = "4" THEN ST = ST - 1 ST = ST + 1: 'FOR COOL KALIDESCOPE IF ST < 1 THEN ST = 1 IF k$ = CHR$(27) THEN END IF z > 8 THEN z = 8 IF z < -8 THEN z = -8 Ca = C(A) Sa = S(A) FOR x = 0 TO xh xo = (x - xh \ 2) FOR y = 0 TO yh IF block(x, y) = 0 THEN GOTO skip yo = (y - yh \ 2) xp = xo * Ca * z \ 128 - yo * Sa * z \ 128 yp = yo * Ca * z \ 128 + xo * Sa * z \ 128 PSET (xp + xd, yd - yp), block(x, y) skip: NEXT: NEXT SWAP v, w: SCREEN 7, , v, w: WAIT &H3DA, 8: CLS 2 LOOP