forum.vdsworld.com Forum Index forum.vdsworld.com
Visit VDSWORLD.com
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 


3D Raycasting In Pure VDS..

 
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code
View previous topic :: View next topic  
Author Message
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Sat Jun 15, 2002 11:52 pm    Post subject: 3D Raycasting In Pure VDS.. Reply with quote

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
Back to top
View user's profile Send private message Send e-mail
LiquidCode
Moderator Team


Joined: 05 Dec 2000
Posts: 1753
Location: Space and Time

PostPosted: Sun Jun 16, 2002 12:08 pm    Post subject: Reply with quote

No way! Very cool Mac! It may be slow, but it's a great start.

Way to go. Very Happy

_________________
Chris
Http://theblindhouse.com
Back to top
View user's profile Send private message Send e-mail Visit poster's website
Tommy
Admin Team


Joined: 16 Nov 2002
Posts: 746
Location: The Netherlands

PostPosted: Sun Jun 16, 2002 5:48 pm    Post subject: Reply with quote

And you call that simple! 8O

Amazing Mac, it's great. Very Happy

Tommy
Back to top
View user's profile Send private message Send e-mail Visit poster's website
marty
Professional Member
Professional Member


Joined: 10 May 2001
Posts: 789

PostPosted: Mon Jun 17, 2002 2:10 am    Post subject: Reply with quote

Impressive Mac!

You amaze me with your VDS coding!

Smile Very Happy Razz
Back to top
View user's profile Send private message Send e-mail Visit poster's website MSN Messenger
Mac
Professional Member
Professional Member


Joined: 08 Jul 2000
Posts: 1585
Location: Oklahoma USA

PostPosted: Mon Jun 17, 2002 5:21 pm    Post subject: Reply with quote

Thanks guys... Smile
_________________
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
Back to top
View user's profile Send private message Send e-mail
Display posts from previous:   
Post new topic   Reply to topic    forum.vdsworld.com Forum Index -> Visual DialogScript 3 Source Code All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You can attach files in this forum
You can download files in this forum

Twitter@vdsworld       RSS

Powered by phpBB © 2001, 2005 phpBB Group