Author Topic: Floorcaster  (Read 21315 times)

0 Members and 1 Guest are viewing this topic.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Floorcaster
« on: July 23, 2010, 10:50:04 pm »
In case anyone is interested, here is the old floor casting code from Ncaster. Its rather rudimentary, but with a bit of modding you can cast a tilemap.
It might be useful for a racer or something.
To compile, drop main.c and rayheader.c/h into an standard Nspire dev directory, modify the Makefile appropriately, and compile as usual.
It is interesting to note that this is technically a real-time raytracer, albeit a very, very, very limited one. Madness! :)

Offline apcalc

  • The Game
  • CoT Emeritus
  • LV10 31337 u53r (Next: 2000)
  • *
  • Posts: 1393
  • Rating: +120/-2
  • VGhlIEdhbWUh (Base 64 :))
    • View Profile
Re: Floorcaster
« Reply #1 on: July 23, 2010, 11:51:37 pm »
This looks great bwang!

Thanks for posting! ;)


Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #2 on: July 24, 2010, 01:15:37 am »
Does it do the linear algebra for every pixel every frame?  Or does it precalculate the camera offsets and to rotation and translations transformations on them?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #3 on: July 24, 2010, 01:29:37 am »
It does the linear algebra for every pixel.
Here's are the loop contents:
Code: [Select]
float y1 = h - y;
float y2 = y - h/2;
float c = 1 + y1 / y2;
int floorX = (int) ((raydx * c) + px);
int floorY = (int) ((raydy * c) + py);
5 adds, 2 multiplies, and 2 divides.
If I did the pre-calculated method, I think it would be 4 adds and 4 multiplies. Definitely faster :)
However, that method does not easily allow vertical motion :(
If I draw every 4th pixel like I do now, I actually get quite a decent framerate. I wonder if this is worth continuing, or should I try to figure out how to do proper mode 7?

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #4 on: July 24, 2010, 01:35:35 am »
neither method allows vertical motion actually i think.  What kind of framerate do you get?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #5 on: July 24, 2010, 01:49:14 am »
20-30 at the moment.
This one does with minimal code changes.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #6 on: July 24, 2010, 01:56:00 am »
Thats really nice, is it pixel by pixel?  Or do you use 2x2 pixels.

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #7 on: July 24, 2010, 02:02:40 am »
2x2 pixels.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #8 on: July 24, 2010, 02:13:10 am »
Nice, we can has screenies?  You know we love our screenies :]

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #9 on: July 24, 2010, 02:36:53 am »
Sadly, my computer is not up to the task of running the emulator and encoding an AVI screen capture at the same time, and CalcCapture doesn't support Linux. I'll post some screenies when I get on Windows.
It doesn't look very exciting because I'm too lazy to make a good tilemap, so its just a checkboard right now.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #10 on: July 24, 2010, 02:38:28 am »
Even stills could be nice, but i can be patient ^^ I cant wait to see what could be done with this :)

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #11 on: July 24, 2010, 02:45:49 am »
Here's a still.
Really quite boring, but I think there's potential.
I need to figure out how to handle the ugliness that occurs when rendering far-away areas.
The checkerboard is not procedural; I'm actually scaling a 64x64 sprite up to a huge area. Yay giant pixels! :)
I think I have little enough code here so I can convert everything to fixed point without causing myself a debugging nightmare.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #12 on: July 24, 2010, 02:53:58 am »
That looks really nice :)  Maybe once you convert to fixed point, if you have enough speed maybe try what calc84 did with his Fzero engine and do 2x1 pixels?

Offline bwang

  • LV7 Elite (Next: 700)
  • *******
  • Posts: 634
  • Rating: +30/-11
    • View Profile
Re: Floorcaster
« Reply #13 on: July 24, 2010, 03:03:31 am »
Yeah, I'll probably do that, even if I have to sacrifice screen area.
2x1 looks sooooo much better than 2x2.

Offline Builderboy

  • Physics Guru
  • CoT Emeritus
  • LV13 Extreme Addict (Next: 9001)
  • *
  • Posts: 5673
  • Rating: +613/-9
  • Would you kindly?
    • View Profile
Re: Floorcaster
« Reply #14 on: July 24, 2010, 03:05:23 am »
yeah, at first i didnt even notice that calc84's engine wasn't full pixel by pixel graphics.  And hopefully converting to fixed point will give you enough speed so that you wont have to sacrifice speed.  Maybe 2x1 for the top half of the game area? ;D