Raycasting Demo (like Wolfenstein3D, just veery basic)

Showcase your libraries, tools and other projects that help your fellow love users.
User avatar
TechnoCat
Inner party member
Posts: 1611
Joined: Thu Jul 30, 2009 12:31 am
Location: Denver, CO
Contact:

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by TechnoCat »

bartbes wrote:I certainly haven't, though I recently saw something about someone who calculated only one wall and used a trick to get all other walls from it.
The guy in that The Colony video?
User avatar
Jasoco
Inner party member
Posts: 3725
Joined: Mon Jun 22, 2009 9:35 am
Location: Pennsylvania, USA
Contact:

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by Jasoco »

Well, I recall him mentioning that the rooms in the warehouse were drawn by extending the wall up indefinitely. Don't know about calculating all walls.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by bartbes »

Yes, he, he was talking about some nice tricks.
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by pygy »

I have tweaked the ray_cast function a bit, and cleaned up the draw routine (I draw the sky and the floor as big rectangles, then the walls as an overlay).

I get 60 fps almost all the time with a sliver width of 3. It's a bit slower (56-58 when the field is wide and deep). I have a Core Duo 2GHz (a 3.5 year old beast).
raycast.png
raycast.png (17.23 KiB) Viewed 2082 times
The current algorithm is still linear, but a better breed of linear.

It used to be fn( distance * 1/ray_resolution ) ) with ray_resolution = 0.02

it's now fn( ( distance * ( 1/seek_step ) + log2( (1/ray_resolution) * ( 1/distance) )) with
  • seek_step = 0.1
  • ray_resolution = 1/64
  • a security to prevent distance from being < 1 in the calculation.
for pixels far enough, it's thus almost fn( ( distance * ( 1/seek_step ) ) : 5 times faster :-)

While typing this message, I thought of a way to make it faster and more accurate still. I'll post an update when I have the time.

We could implement fog by drawing a gradient on the floor and tweaking the wall colors as a function of distance.


Edit: new version with screen.vsync = false and love.load(dt) modified to move at the speed it had previously when hitting vsync.
Edit2: Love ignores the config file... weird.
Edit3: you can set VSync in main.lua if you want (love.graphics.setMode( config.width, config.height, false, true --[[set this to false]], 0 ))
Edit4: Now with screenshot. Notice the higher resolution and the FPS :-)
Attachments
raycast.love
(3.18 KiB) Downloaded 129 times
Last edited by pygy on Sat Feb 27, 2010 3:09 pm, edited 7 times in total.
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
User avatar
kalle2990
Party member
Posts: 245
Joined: Sat Sep 12, 2009 1:17 pm
Location: Sweden

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by kalle2990 »

I think you forgot using deltatime when moving the camera, because I move very fast...
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by pygy »

I didn't change anything to the load.update() logic. It still uses dt.

Edit: errr... well, actually, it takes a dt parameter, but it doesn't use it. I'll see what I can do :-)
Edit2: now it uses dt... and, yes, it's speedy :-)
Last edited by pygy on Sat Feb 27, 2010 12:36 pm, edited 3 times in total.
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
User avatar
bartbes
Sex machine
Posts: 4946
Joined: Fri Aug 29, 2008 10:35 am
Location: The Netherlands
Contact:

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by bartbes »

Woah.. good job, I'm hitting vsync!
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by pygy »

I tried to disable vsync, but love ignores the config file (both love.conf and conf.lua).
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
User avatar
Robin
The Omniscient
Posts: 6506
Joined: Fri Feb 20, 2009 4:29 pm
Location: The Netherlands
Contact:

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by Robin »

pygy wrote:I tried to disable vsync, but love ignores the config file (both love.conf and conf.lua).
You mean game.conf?

And LÖVE does not ignore conf.lua -- do you know the right syntax?
Help us help you: attach a .love.
User avatar
pygy
Citizen
Posts: 98
Joined: Mon Jan 25, 2010 4:06 pm

Re: Raycasting Demo (like Wolfenstein3D, just veery basic)

Post by pygy »

[snip] Edit... I read the wiki too fast...

But the problem was somewhere else:

love.graphics.setMode( 500, 400, false, true, 0 )

:D
Hermaphroditism is not a crime. -- LSB Superstar

All code published with this account is licensed under the Romantic WTF public license unless otherwise stated.
Post Reply

Who is online

Users browsing this forum: Google [Bot] and 55 guests