Mac Professional Member

Joined: 08 Jul 2000 Posts: 1585 Location: Oklahoma USA
|
Posted: Sat Jun 15, 2002 11:52 pm Post subject: 3D Raycasting In Pure VDS.. |
|
|
Finally got a simple raycasting procedure to work in pure VDS,
but it's pretty slow (the code is from a DOS Qbasic program).
I'm no math wizard, so maybe some of you trig experts can
improve the speed (it'd be somewhat faster using DRAW.DLL).
Maybe it'll give you guys some ideas. Have fun...
_______________________________________________________________________________________________________________________________________________________________________________________
| Code: |
rem -- Simple (and slow) raycasting engine in pure VDS.
rem -- Use UP/DOWN/LEFT/RIGHT arrow keys to move around.
rem -- Use keys 1/2/3/4 for 0/90/180/270 degree view angle.
rem -- No collision detection, use R to reset if you get lost.
OPTION SCALE, 96
OPTION DECIMALSEP, "."
TITLE By Mac
DIALOG CREATE,"Simple 3D Raycasting Demo",-1,-1,300,300
DIALOG ADD,STYLE,SkyColor,,,,CYAN
DIALOG ADD,STYLE,GrndColor,,,,LTGREEN
DIALOG ADD,STYLE,Line1,,,,BROWN
DIALOG ADD,STYLE,Line2,,,,BLACK
DIALOG ADD,MENU,Options,&Reset|R,-,0 Degrees|1,90 Degrees|2,180 Degrees|3,270 Degrees|4,-,Forward|UP,Back|DOWN,Left|LEFT,Right|RIGHT
DIALOG ADD,TEXT,Sky,0,0,300,100,,,SkyColor
DIALOG ADD,TEXT,Grnd,100,0,300,200,,,GrndColor
rem -- Add 60 vertical lines (offscreen) for field of view in 2 colors --
%x = 0
REPEAT
if @equal(@mod(%x, 3), 0)
DIALOG ADD,TEXT,Slice%x,0,-10,0,0,,,Line1
else
DIALOG ADD,TEXT,Slice%x,0,-10,0,0,,,Line2
end
%x = @succ(%x)
UNTIL @equal(%x, 60)
DIALOG ADD,STATUS,Stat,"LOADING DATA. PLEASE WAIT..."
DIALOG SHOW
rem -- Map. Add blank line so Y (@item) starts at 1 like X (@pos) does.
LIST CREATE, 1
LIST LOADTEXT, 1,
"
"xxxxxxxxxx
"x--------x
"x-x-xxx--x
"xxx---x--x
"x-----x--x
"x--------x
"x--------x
"x--------x
"x----xxx-x
"x----x---x
"xxxxxxxxxx
rem -- Create sine and cosine tables, round off to whole numbers --
LIST CREATE, 2
LIST CREATE, 3
%x = 0
REPEAT
LIST ADD, 2, @format(@fmul(@fsin(@fmul(%x, .0174)), 100), 3.0)
LIST ADD, 3, @format(@fmul(@fcos(@fmul(%x, .0174)), 100), 3.0)
%x = @succ(%x)
UNTIL @greater(%x, 360)
rem -- Player field of view (degrees) --
%%fov = 60
:ResetMENU
rem -- Player X, Player Y, Player Angle --
%%px = 45
%%py = 60
%%pa = 0
:START
rem -- Screen slice number --
%%ss = 0
%x = %%pa
REPEAT
rem -- For current ray angle --
%%xb = @fdiv(@item(2, @mod(%x, 360)), 100)
%%yb = @fdiv(@item(3, @mod(%x, 360)), 100)
rem -- Always start ray at player XY --
%%bx = %%px
%%by = %%py
rem -- Reset distance to wall --
%d = 0
rem -- Cast a single ray until we find a wall --
REPEAT
%%bx = @fadd(%%bx, %%xb)
%%by = @fadd(%%by, %%yb)
%d = @succ(%d)
%%my = @format(@fdiv(%%by, 10), 5.0)
%%mx = @format(@fdiv(%%bx, 10), 5.0)
%m = @substr(@item(1, %%my), %%mx)
UNTIL @not(@equal(%m, "-"))
rem -- Slice X, and corrected distance to wall --
%%sx = @prod(@diff(%x, %%pa), 5)
%%dd = @div(1000, %d)
rem -- Draw the wall slice --
DIALOG SETPOS,Slice%%ss,@diff(100, %%dd),%%sx,5,@prod(%%dd,4)
%%ss = @succ(%%ss)
%x = @succ(%x)
UNTIL @equal(%x, @sum(%%pa, %%fov))
:EVLOOP
DIALOG SET, Stat, Player X = %%px Player Y= %%py Player Angle = %%pa
WAIT EVENT
goto @event()
:0 DegreesMENU
%%pa = 0
goto START
:90 DegreesMENU
%%pa = 90
goto START
:180 DegreesMENU
%%pa = 180
goto START
:270 DegreesMENU
%%pa = 270
goto START
:ForwardMENU
%%px = @format(@fadd(%%px, @fdiv(@item(2, @mod(%x, 360)), 50)), 5.0)
%%py = @format(@fadd(%%py, @fdiv(@item(3, @mod(%x, 360)), 50)), 5.0)
goto START
:BackMENU
%%px = @format(@fsub(%%px, @fdiv(@item(2, @mod(%x, 360)), 50)), 5.0)
%%py = @format(@fsub(%%py, @fdiv(@item(3, @mod(%x, 360)), 50)), 5.0)
goto START
:LeftMENU
%%pa = @mod(@sum(%%pa, 358), 360)
goto START
:RightMENU
%%pa = @sum(%%pa, 2)
goto START
:CLOSE
EXIT
|
_________________ VDSug.dll does file IO, check/disable menu items,
non-VDS dlls, draw functions and more...
Free download (30k dll size) at:
http://www.vdsworld.com/download.php?id=361
 |
|