DECLARE SUB fastcharput (y!, x!, a$, vg!, ag!) DECLARE SUB txtLINE (x1!, y1!, x2!, y2!, col!, res!) ' this is a routine of the first demo of BaseD ' it's supposed to be a txt LINE routine that has speed ' and has weird stuff ' demonstrate RANDOMIZE TIMER WIDTH 80, 50 ' this cube rotation stuff is just copied of phobia's 3D_FLAM.BAS ' it wasn't such an important part of that program , so I ripped it ' i also added lots of extra stuff to it , such as the random movement ' and better support for text-mode. xoff = 40 ' Center of the cube in x yoff = 25 ' Same but in y zoff = 25 ' Same but in z xang = 0 ' Don't change these... they control the rotation. yang = 0 zang = 0 xadd = .01 yadd = .01 zadd = .01 randiv = 8 points = 8 ' Amount of vertexes in the cube... DIM cube(points * 3) ' All coordinates of the cube DIM scr(points * 2) ' Coordinates of where the vertexes should be on the screen FOR a = 1 TO points * 3 READ cube(a) NEXT a inc = 1 ' This is the current cube() pos the calculate start! = TIMER DO ' The following lines are matrixes (misspelled?), do NOT try to understand them... REM ********** Rotate around z-axis ********** oldx = cube(inc) oldy = cube(inc + 1) xtemp = oldx * COS(zang) - oldy * SIN(zang) ytemp = oldx * SIN(zang) + oldy * COS(zang) cube(inc) = xtemp cube(inc + 1) = ytemp REM ********** Rotate around y-axis ********** oldx = cube(inc) oldz = cube(inc + 2) xtemp = oldx * COS(yang) - oldz * SIN(yang) ztemp = oldx * SIN(yang) + oldz * COS(yang) cube(inc) = xtemp cube(inc + 2) = ztemp REM ********** Rotate around x-axis ********** oldy = cube(inc + 1) oldz = cube(inc + 2) ytemp = oldy * COS(xang) - oldz * SIN(xang) ztemp = oldy * SIN(xang) + oldz * COS(xang) cube(inc + 1) = ytemp cube(inc + 2) = ztemp REM *********************************** inc = inc + 3 ' Go to next x position IF inc > points * 3 THEN inc = 1 inc2 = 1 DO ' This do-loop calculates the screen coordinates of the cube... y = (cube(inc) * 64) / (cube(inc + 2) - zoff) + xoff x = (cube(inc + 1) * 64) / (cube(inc + 2) - zoff) + yoff scr(inc2) = y scr(inc2 + 1) = x inc2 = inc2 + 2 inc = inc + 3 LOOP WHILE inc < (points * 3) SCREEN 0, 0, 0, 1 frames = frames + 1 CLS txtLINE scr(1), scr(2), scr(3), scr(4), 9, 0 txtLINE scr(1), scr(2), scr(5), scr(6), 9, 0 txtLINE scr(13), scr(14), scr(3), scr(4), 1, 0 txtLINE scr(13), scr(14), scr(5), scr(6), 1, 0 txtLINE scr(5), scr(6), scr(9), scr(10), 9, 0 txtLINE scr(1), scr(2), scr(7), scr(8), 1, 0 txtLINE scr(11), scr(12), scr(7), scr(8), 1, 0 txtLINE scr(15), scr(16), scr(11), scr(12), 9, 0 txtLINE scr(15), scr(16), scr(13), scr(14), 1, 0 txtLINE scr(15), scr(16), scr(9), scr(10), 9, 0 txtLINE scr(3), scr(4), scr(11), scr(12), 9, 0 txtLINE scr(7), scr(8), scr(9), scr(10), 1, 0 PCOPY 0, 1 zang = zang + zadd IF zang < -RND / randiv THEN zadd = -zadd IF zang > RND / randiv THEN zadd = -zadd yang = yang + yadd IF yang < -RND / randiv THEN yadd = -yadd IF yang > RND / randiv THEN yadd = -yadd xang = xang + xadd IF xang < -RND / randiv THEN xadd = -xadd IF xang > RND / randiv THEN xadd = -xadd inc = 1 END IF i$ = INKEY$ IF i$ = CHR$(27) THEN GOTO piep: LOOP piep: finish! = TIMER CLS SCREEN 0, 1, 0, 0 WIDTH 80, 25: COLOR 7, 0: CLS fps! = frames / (finish! - start!) PRINT "Frames per second: ", fps! END REM *** Coordinates of the cube *** REM x y z DATA 5,5,5 DATA 5,5,-5 DATA 5,-5,5 DATA -5,5,5 DATA -5,-5,5 DATA -5,5,-5 DATA 5,-5,-5 DATA -5,-5,-5 SUB fastcharput (y, x, a$, vg, ag) 'duh , ' YES it's faster ' NO it's not safe ' you must call DEF SEG=&HB800 before calling this routine ' that isn't done here 'cause of the speed loss. ' (c) buzz '96 ' buzz@cyber-wizard.com b = ((((INT(y) - 1) * 80) + INT(x) - 1) * 2) a = ASC(a$) col = (ag * 16) + vg POKE b, a POKE b + 1, col END SUB SUB txtLINE (x1, y1, x2, y2, col, res) 'translate : ' LINE (x1,y1)-(x2,y2),col ' res is the resolution , ' if res=0 then calculate_resolution_needed_for_clear_line ' yeah , lower resolution , higher speed ' (c) buzz '96 ' buzz@cyber-wizard.com xdiff = x2 - x1 ydiff = y2 - y1 IF res > 0 THEN steps = res: GOTO prrr: xsteps = xdiff ysteps = ydiff IF xsteps < 0 THEN xsteps = -xsteps IF ysteps < 0 THEN ysteps = -ysteps IF xsteps > ysteps THEN steps = xsteps ELSE steps = ysteps prrr: xd = xdiff ' uncomment all these | to add some sort of IF xd < 0 THEN xd = -xd ' | lighting yd = ydiff ' | IF yd < 0 THEN yd = -yd ' | IF yd > xd THEN d = yd ELSE d = xd ' v IF d < 24 THEN col = 1 ELSE col = 9 ' helps you 2 see the perspective xadd = xdiff / steps yadd = ydiff / steps xvar = x1 yvar = y1 DEF SEG = &HB800 FOR i = 1 TO steps + 1 yv = INT(yvar) xv = INT(xvar) char$ = "Û" IF yv > 50 THEN yv = 50: char$ = " " IF yv < 1 THEN yv = 1: char$ = " " IF xv > 80 THEN xv = 80: char$ = " " IF xv < 1 THEN xv = 1: char$ = " " ' LOCATE yv, xv 'bios gedoe ' COLOR col, 0 ' PRINT char$; fastcharput yv, xv, char$, col, 0 'sneller yvar = yvar + yadd xvar = xvar + xadd NEXT i DEF SEG END SUB