'=========================================================================== ' Subject: 2D ROTATING TEXTURE MAPS Date: 03-22-96 (07:45) ' Author: Peder Brynolf Code: QB, QBasic, PDS ' Origin: pbrynolf@dataphone.se Packet: GRAPHICS.ABC '=========================================================================== 'Here's a little program showing how to 2d-rotate texture maps. DECLARE SUB TEXTLINE (X1, X2, Y, TX1, TY1, TX2, TY2) RANDOMIZE TIMER ZANM = 3.14159 / 180 SCREEN 13 NOP = 4 PRINT "01234567" PRINT "HEJSAN!" PRINT " FUNKAR" PRINT "DETTA S" PRINT "BLIR JAG" PRINT " GLAD!" PRINT " ALTER" PRINT " EGO" DIM X(NOP), Y(NOP) DIM TX(NOP), TY(NOP) DO RESTORE POLYCOORDS FOR I = 0 TO NOP - 1 READ X(I), Y(I) X(I) = SIN(ZANM * ((I * 90) + an)) * 50 + 160 Y(I) = COS(ZANM * ((I * 90) + an)) * 50 + 100 NEXT I an = an + 1 OX = X(3) OY = Y(3) FOR I = 0 TO 3 X = X(I) Y = Y(I) LINE (X, Y)-(OX, OY) OX = X OY = Y NEXT I RESTORE TEXTCOORDS FOR I = 0 TO NOP - 1 READ TX(I), TY(I) NEXT I DIM XP(199), TXP(199), TYP(199) FOR Y = 0 TO 199 XP(Y) = -1 NEXT Y OX = X(NOP - 1) OY = Y(NOP - 1) OTX = TX(NOP - 1) OTY = TY(NOP - 1) FOR I = 0 TO NOP - 1 X = X(I) Y = Y(I) TX = TX(I) TY = TY(I) XF = X YF = Y XT = OX YT = OY TXF = TX TYF = TY TXT = OTX TYT = OTY IF YF = YT THEN GOTO SKIPIT2 IF YF > YT THEN SWAP YF, YT: SWAP XF, XT: SWAP TYF, TYT: SWAP TXF, TXT XSK = (XT - XF) / (YT - YF) XC = XF TXSK = (TXT - TXF) / (YT - YF) TXC = TXF TYSK = (TYT - TYF) / (YT - YF) TYC = TYF FOR YC = YF TO YT - 1 IF XP(YC) = -1 THEN XP(YC) = XC TXP(YC) = TXC TYP(YC) = TYC ELSE OXC = XC OTXC = TXC OTYC = TYC REM LINE (XP(YC), YC)-(XC, YC), 4 TEXTLINE XP(YC), XC, YC, TXP(YC), TYP(YC), TXC, TYC XP(YC) = -1 XC = OXC TXC = OTXC TYC = OTYC END IF XC = XC + XSK TXC = TXC + TXSK TYC = TYC + TYSK NEXT YC SKIPIT2: OTX = TX OTY = TY OX = X OY = Y NEXT I LOOP UNTIL INKEY$ = " " SYSTEM POLYCOORDS: DATA 113,154 DATA 288,181 DATA 245,124 DATA 96,19 TEXTCOORDS: DATA 0,0 DATA 64,0 DATA 64,64 DATA 0,64 SUB TEXTLINE (X1, X2, Y, TX1, TY1, TX2, TY2) IF X1 = X2 GOTO SKIPIT IF X1 > X2 THEN SWAP X1, X2: SWAP TX1, TX2: SWAP TY1, TY2 XSK = (TX2 - TX1) / (X2 - X1) XC = TX1 YSK = (TY2 - TY1) / (X2 - X1) YC = TY1 FOR X = X1 TO X2 C = POINT(XC, YC) PSET (X, Y), C XC = XC + XSK YC = YC + YSK NEXT X SKIPIT: END SUB