DEFINT A-Z 'FLRMAP - simple floormapper with diagram and explanation. 'by Toshi Horie March 2001 'based on Floormapper Ecliptorial and 'Qasir's constant-z optimization explanation. SCREEN 13 CONST sc = 128 'fixed point scaling factor 'generate texture DIM tex(63, 63) FOR v = 0 TO 63 FOR u = 0 TO 63 tex(u, v) = u XOR v NEXT NEXT 'For coordinate system with the origin at the + sign, 'and up is +, and right is +, units in pixels. h = -18 CONST d = 300 CONST ytop = 0, ybot = 99 'For coordinate system with the origin at B, 'and up direction is +, and right is positive. ' 'eye at y = h * = screen pixel to be plotted with texel o. 'screen at z = d o = floormap texel hit by ray from eye. 'floor at y = 0 v = non-tiled v texel coordinate of floormap. ' ' eye screen ' : | \ # ' : | \ # ' : | \ # ' : | \# ' : +---d----* ' h | # \ ' : | # \ ' : | y # \ ' : | # \ ' : | # \ ' : B========#===========o================floor ' <---------- v -------> ' ' From this diagram, we can derive the equation for v ' using similar triangles. u can be derived likewise. ' u = x* h/(h-y) ' v = d* h/(h-y) ' In the lut!() array, we calculate the values for h/(h-y) ' for all y values inside the screen. The result is that ' only two (none if you use three tables) multiplications are ' needed per scanline. DIM lut!(ytop TO ybot) FOR y = ytop TO ybot lut!(y) = CSNG(h) / (h - y) NEXT DEF SEG = &HA7D0 'start at x=0,y=100 'move forward in the z direction FOR vofs = 0 TO 1000 p% = 0 FOR y = ytop TO ybot v! = vofs + d * lut!(y): vv = v! AND 63 u! = -160 * lut!(y): du! = lut!(y) FOR x = 0 TO 319 'PSET (x, y + 100), tex(u! AND 63, vv) POKE p%, tex(u! AND 63, vv) u! = u! + du! p% = p% + 1 NEXT x NEXT y 'WAIT &H3DA, 8 IF INKEY$ <> "" THEN END NEXT vofs END