So I experimented with Ray Casting

A spot for all things TestTube
Post Reply
User avatar
wtg62
Posts: 174
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

So I experimented with Ray Casting

Post by wtg62 »

And the results of rendering a 7x7 texture make me feel ashamed. (That 'F' on the F block means FPS drop)
The HTML5 canvas sure is efficient, isn't it?

https://dl.dropboxusercontent.com/u/556 ... ycast.html
This message has been brought to you by wtg62, duh!
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: So I experimented with Ray Casting

Post by testtubegames »

Says a lot about game conventions that it took me quite a few minutes to realize that I could walk through the 'walls.'

Is this built-from-scratch-html5? Did you honestly use ray-casting to create a 3d renderer? Respect.

(minor note: check your control-scheme instructions. Front-back is mislabeled)
User avatar
wtg62
Posts: 174
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

Re: So I experimented with Ray Casting

Post by wtg62 »

testtubegames wrote:Says a lot about game conventions that it took me quite a few minutes to realize that I could walk through the 'walls.'
Yeah, no collision engine yet, but I could easily add it now that I understand the AABB algorithm better.
testtubegames wrote:Is this built-from-scratch-html5? Did you honestly use ray-casting to create a 3d renderer? Respect.
This was written with some guidance, in JavaScript, aside from using keydrown.js to monitor user input.
Thank you for the respect :P
testtubegames wrote:(minor note: check your control-scheme instructions. Front-back is mislabeled)
HAHAHA! Wow! How did I mess that up? Fixed!
Oh man did that make me laugh!
This message has been brought to you by wtg62, duh!
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: So I experimented with Ray Casting

Post by testtubegames »

wtg62 wrote:This was written with some guidance, in JavaScript, aside from using keydrown.js to monitor user input.
Nice. When I first looked at it, I though... oh a 3d world, and maybe the raycasting is just drawing the 'sight-lines' in the mini-map. Cool.

...

And then I realized it was *ALL* made from scratch. :shock: I'm impressed.

(Clearly not a guy who does much in 3D over here... I stick to the simple world of 2D... or at most 2+1D :) )
User avatar
wtg62
Posts: 174
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

Re: So I experimented with Ray Casting

Post by wtg62 »

Not 100% from scratch, because I went somewhere to find out how to remove the fish-eye effect from my first attempt.
For some reason, if you use the actual-distance from the camera to the wall, it produces a fish-eye effect.
The best way to prevent this is treat the point on the wall that was hit by the ray as a line parallel to the camera's plane, and find the distance between said lines.
I looked at equations for this, so I can't say 100% scratch :(
This message has been brought to you by wtg62, duh!
A Random Player
Posts: 523
Joined: Mon Jun 03, 2013 4:54 pm

Re: So I experimented with Ray Casting

Post by A Random Player »

wtg62 wrote:Not 100% from scratch, because I went somewhere to find out how to remove the fish-eye effect from my first attempt.
For some reason, if you use the actual-distance from the camera to the wall, it produces a fish-eye effect.
The best way to prevent this is treat the point on the wall that was hit by the ray as a line parallel to the camera's plane, and find the distance between said lines.
I looked at equations for this, so I can't say 100% scratch :(
This happened to me before, when I tried a raycaster. An easy way to figure this out is that a square facing you should always look like a square, even though the distances between you and the parts of the square are different. Also, remember that an eye works basically like a pinhole camera, with perpendicular distances being proportionate.
$1 = 100¢ = (10¢)^2 = ($0.10)^2 = $0.01 = 1¢ [1]
Always check your units or you will have no money!
User avatar
testtubegames
Site Admin
Posts: 1148
Joined: Mon Nov 19, 2012 7:54 pm

Re: So I experimented with Ray Casting

Post by testtubegames »

wtg62 wrote:Not 100% from scratch, because I went somewhere to find out how to remove the fish-eye effect from my first attempt.
Well, if looking up equations while making a game/sim is wrong, I don't want to be right.

So yeah, looking up references is a good thing in my book.

And just to reiterate - well done!
User avatar
wtg62
Posts: 174
Joined: Mon Jan 27, 2014 11:30 pm
Location: Texas, United States

Re: So I experimented with Ray Casting

Post by wtg62 »

testtubegames wrote: Well, if looking up equations while making a game/sim is wrong, I don't want to be right.

So yeah, looking up references is a good thing in my book.
I think to clarify, I looked at C code for some help, sorry to have omitted that.
Other than that, yeah, it's mostly scratch!

I consider using references to decrease the amount of scratchiness, but not remove it all. :P
This message has been brought to you by wtg62, duh!
Post Reply