Qbasicnews.com
Floormapper plus - Printable Version

+- Qbasicnews.com (http://qbasicnews.com/newforum)
+-- Forum: QBasic (http://qbasicnews.com/newforum/forum-4.html)
+--- Forum: QB Projects (http://qbasicnews.com/newforum/forum-12.html)
+--- Thread: Floormapper plus (/thread-4420.html)

Pages: 1 2


Floormapper plus - Antoni Gual - 08-03-2004

A base for a crappy flight simulator?
Code:
DECLARE SUB docloud (k%)
DECLARE SUB raytrace ()
'DECLARE SUB ffix ()

'rotating floormaper by Antoni Gual 8/2004      

'ffix
SCREEN 13

DIM SHARED tex(31, 31, 1) AS INTEGER       'texture array
DIM SHARED kbd(128) AS INTEGER              'keyboard reader array
DIM SHARED frames%
DIM SHARED persplut(-200 TO 200) AS SINGLE  'vertical offsets for roof and floor

'read map,do fixed part of persp lut (sky is always in the infinite)

FOR i% = -200 TO -1
    persplut(i%) = 25590 / i%
    persplut(-i%) = -25590 / i%
NEXT

'cloudy texture 1
docloud 1

'cloudy texture for sky
docloud 0

'set palette
OUT &H3C8, 0
'grey:walls
FOR i% = 0 TO 63
    OUT &H3C9, i% + 16: OUT &H3C9, i% + 16: OUT &H3C9, i% + 16
NEXT
'green:ground
FOR i% = 0 TO 63
    OUT &H3C9, 0: OUT &H3C9, 140 + 2 * i%: OUT &H3C9, 0
NEXT
'blue:sky
FOR i% = 0 TO 63
    OUT &H3C9, 63 - i% / 2: OUT &H3C9, 63 - i% / 2: OUT &H3C9, 63
NEXT

CLS
COLOR 128
PRINT "Floormapper by Antoni Gual"
PRINT
PRINT "number pad to move around"
PRINT "Q and A    to tilt horizon"
PRINT
PRINT "Press any key..."
a$ = INPUT$(1)

'erase key buffer and set num lock off
DEF SEG = &H40: POKE &H1C, PEEK(&H1A): POKE &H17, PEEK(&H17) AND NOT 32

'launch raytracer
tim! = TIMER
frames% = 0
raytrace
LOCATE 1, 1: PRINT frames% / (TIMER - tim!)
a$ = INPUT$(1)
END

SUB docloud (k%)
d1% = 64
d% = 32
tex(0, 0, k%) = 32
WHILE d% > 1
  d2% = d% \ 2
  FOR i% = 0 TO 31 STEP d%
    FOR j% = 0 TO 31 STEP d%
      tex((i% + d2%) AND 31, j%, k%) = (tex(i%, j%, k%) + tex((i% + d%) AND 31, j%, k%) + (RND - .5) * d1%) / 2
      tex(i%, (j% + d2%) AND 31, k%) = (tex(i%, j%, k%) + tex(i%, (j% + d%) AND 31, k%) + (RND - .5) * d1%) / 2
      tex((i% + d2%) AND 31, (j% + d2%) AND 31, k%) = (tex(i%, j%, k%) + tex((i% + d%) AND 31, (j% + d%) AND 31, k%) + (RND - .5) * d1%) / 2
  NEXT j%, i%
  d1% = d1% / 2
  d% = d2%
WEND

END SUB

SUB raytrace
CONST rtf = 2048
CONST rtl = .0001
CONST inf = 3000000
CONST incu = .05
xpos = 1.5
ypos = 1.5
angle = 0
tilt = 0
ini% = 1
'frames loop
d1% = -1
d2% = 1

DO
    frames% = frames% + 1
  
    'keyboard input
    k% = INP(&H60):
    IF k% THEN
      kbd(k% AND 127) = -((k% AND 128) = 0)
      DEF SEG = &H40: POKE &H1C, PEEK(&H1A)
      IF kbd(1) THEN EXIT DO
      turn% = kbd(&H4D) - kbd(&H4B)': kbd(&H4D) = 0: kbd(&H4B) = 0
      mov% = kbd(80) - kbd(72) + ini%': kbd(80) = 0: kbd(72) = 0
      dtilt% = kbd(16) - kbd(30) + ini%
    END IF
    'a movement has happened, update and collision detect
    IF turn% OR mov% OR dtilt% THEN
      
        angle = angle + turn% * .1
        tilt = tilt + dtilt% * .1
        dct = COS(tilt)
        dst = SIN(tilt)
        
        IF ini% THEN ini% = 0
        dys = SIN(angle) * incu
        dxs = dys / 160
        dxc = COS(angle) * incu
        dyc = dxc / 160
      
        xpos = xpos - dxc * mov%
        xpos32 = xpos * 32
      
        ypos = ypos - dys * mov%
        ypos32 = ypos * 32
     END IF
      'rendering  loop (too many products and divisions)
      DEF SEG = &HA000
      p1& = 0
      FOR y1% = -100 TO 99
        yc! = y1% * dct
        ys! = y1% * dst
        p& = p1&
        FOR x1% = -160 TO 159
        x% = x1% * dct - ys!
        y% = yc! + x1% * dst
        dx = dxc - x% * dxs
        dy = x% * dyc + dys
            pl = persplut(y%)
            SELECT CASE y%
            'sky
            CASE IS < d1%
                tt% = 128 + tex((xpos32 - dx * pl) AND 31, (ypos32 - dy * pl) AND 31, 0)
            'wall
            CASE IS < d2%
                tt% = 138
            'ground
            CASE ELSE
                tt% = 44 + tex((xpos32 + dx * pl) AND 31, (ypos32 + dy * pl) AND 31, 1)
            END SELECT
            POKE p&, tt%
            p& = p& + 1
        NEXT x1%
       p1& = p1& + 320
    NEXT y1%
LOOP
END SUB



Floormapper plus - relsoft - 08-03-2004

Hola Antoni!!! Where have you been?
Nice to see ya back. :*)


Floormapper plus - HQSneaker - 08-03-2004

Hey cool, looks just like the flight sims in the early days Smile


Floormapper plus - Antoni Gual - 08-03-2004

Quote:Hola Antoni!!! Where have you been?
Nice to see ya back. :*)

I was studying your tutorials Smile...Great work!


Hey, wonderful to have you back, Antoni Gual!! ^_- ! - Adigun A. Polack - 08-03-2004

To Antoni Gual:

Hello to you again, and look, it is GREAT to have you right back in action!! Big Grin !

When I ran your program on the 450mhz Pionex “Pentium III”-based computer, unfortunately, it ran VERY SLOOOOOW at no more than 1-2 frames per second ( Cry ! )! But, you do have a decent head-start in that it is a good looking program, though, I will give you that! Wink

Here is an important tip for you: if you would do the *exact* same program over again using at least one of the libs (such as RelLib and GSLib) instead of just doing it in pure QB, then the frame rate would QUITE improve, significantly! Cool And hey, if you want a “Mode-7”-based challenge in QB, hey, I’ve got one for you in one of the categories featured in the QuickBASIC Caliber Programming Compo 2004/2005 (please go to the link at the end of this post!), where it has just already been updated yesterday!! :wtnod:

Well Antoni, I wish you superbly well on your project, no matter what, and welcome back!!! ^_^ !!



MY BEST AND PASSIONATE REGARDS TO YOU,

Adigun Azikiwe Polack
One of the Founders of “Aura Flow”
Continuing Developer of “Frantic Journey”
Current Developer of “Star Angelic Slugger”
Webmaster of the “AAP Official Projects Squad”




______________________________________
T H E • T H I R D • C A L I B E R • H A S • C U R R E N T L Y • A R R I V E D ! ! ! Big Grin !!
The QuickBASIC Caliber Programming Compo 2004/2005.
Now encouraging even more positive originality than ever before, it is jam-packed with all-new and *NEVER-BEFORE-SEEN* QB challenges, bigger and breathtakingly intense excitement, and MORE REVOLUTIONARY FUN like you have never, ever experienced, even including stuff based on the new and upcoming 2004 Athens Olympic Games, too!!! ;*) !

Got game for all this? Then I challenge you to please visit http://dhost.hopto.org/aapproj/qbcpc/. That means YOU, pal! Wink


Floormapper plus - Blitz - 08-04-2004

Actually it wouldn't, becuase he' s only setting pixels, lib or no lib it won't make more then 1-2 fps of difference.


Floormapper plus - Antoni Gual - 08-04-2004

Quote:Actually it wouldn't, becuase he' s only setting pixels, lib or no lib it won't make more then 1-2 fps of difference.

Well, I could check for the positions of the corners of the tiles and let the library draw the whole tile. And read keyboard...Hmmmm...


Floormapper plus - Blitz - 08-04-2004

You could maybe only do the calcs at the end and start of the scanlines, the interpolate. Would be mucho faster.


Floormapper plus - relsoft - 08-04-2004

Quote:
relsoft Wrote:Hola Antoni!!! Where have you been?
Nice to see ya back. :*)

I was studying your tutorials Smile...Great work!

Pthh. :*)

I thought you were doing some Windows programming. :*)

AAP: Use FFIX and it would run fine. :*)


Floormapper plus - Antoni Gual - 08-04-2004

Rel: I have no time or patience to do Windows programming. So back to QB!

Blitz: Unfortuantely scanlines may have a discontinuity in the middle, they may start at the floor, cross the horizon and end in sky, how would you manage that?

AAP: In fact most libraries are good at two things: Put flat sprites into 2D screen and render texturized triangles. Floormapping and voxelmapping are not so often used and libraries have not routines for that Well, Rellib has it´s mode7 rutines, but they don't allow horizon tilt (at the moment...). So you must go pixel by pixel.
It would be good to port Didi Marfurt's QBManche to an appropiate library. Unfortunately it's a voxel mapper....

Using a library to set single pixels does not automatically provide a speed increment. See the tries to port my jpeg viewer to Future Lib by James Lewis, they are only a 20% faster