Omnimaga

Calculator Community => Other Calc-Related Projects and Ideas => Topic started by: bwang on July 23, 2010, 10:50:04 pm

Title: Floorcaster
Post by: bwang 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! :)
Title: Re: Floorcaster
Post by: apcalc on July 23, 2010, 11:51:37 pm
This looks great bwang!

Thanks for posting! ;)
Title: Re: Floorcaster
Post by: Builderboy 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?
Title: Re: Floorcaster
Post by: bwang 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?
Title: Re: Floorcaster
Post by: Builderboy on July 24, 2010, 01:35:35 am
neither method allows vertical motion actually i think.  What kind of framerate do you get?
Title: Re: Floorcaster
Post by: bwang on July 24, 2010, 01:49:14 am
20-30 at the moment.
This one does with minimal code changes.
Title: Re: Floorcaster
Post by: Builderboy on July 24, 2010, 01:56:00 am
Thats really nice, is it pixel by pixel?  Or do you use 2x2 pixels.
Title: Re: Floorcaster
Post by: bwang on July 24, 2010, 02:02:40 am
2x2 pixels.
Title: Re: Floorcaster
Post by: Builderboy on July 24, 2010, 02:13:10 am
Nice, we can has screenies?  You know we love our screenies :]
Title: Re: Floorcaster
Post by: bwang 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.
Title: Re: Floorcaster
Post by: Builderboy 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 :)
Title: Re: Floorcaster
Post by: bwang 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.
Title: Re: Floorcaster
Post by: Builderboy 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?
Title: Re: Floorcaster
Post by: bwang 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.
Title: Re: Floorcaster
Post by: Builderboy 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
Title: Re: Floorcaster
Post by: Galandros on July 24, 2010, 05:33:56 am
bwang continues to bring 3D to Nspire. We could make a racing game with the engine.

What are the differences between mode7 and floorcaster (raytracer)?
Title: Re: Floorcaster
Post by: Hot_Dog on July 24, 2010, 11:34:33 am
What are the differences between mode7 and floorcaster (raytracer)?

I was wondering about that myself.

Bwang, that sounds exciting!  Thanks for all the engines you're making!
Title: Re: Floorcaster
Post by: fb39ca4 on July 24, 2010, 02:08:20 pm
Nice work!

Also, to make this more efficient, I would recommend drawing to a half-size screenbuffer (19200 bytes) and copying that to the bottom half of the screen. Then, you could have a parallax background in the top section.
Title: Re: Floorcaster
Post by: bwang on July 24, 2010, 04:04:15 pm
I only draw half the screen right now.
What are the differences between mode7 and floorcaster (raytracer)?
Mode 7 takes a sprite, translates and rotates it, and then scales each horizontal line appropriately to give an illusion of perspective.
Floorcasting does a calculation for each pixel that determines the intersection between a ray and a plane.
They are completely different algorithms which give the same results.
Title: Re: Floorcaster
Post by: bwang on July 24, 2010, 06:40:08 pm
I converted everything to fixed point, and now I can draw twice the number of pixels and still get a 25% speed gain :)
Fixed point is amazing; I think my next project will be converting Ncaster to fixed point.
Title: Re: Floorcaster
Post by: Galandros on July 24, 2010, 06:56:12 pm
Thanks for the answer. ^^

That is a really cool speed up. The ARM cpu doesn't offer better support for floats than z80 for instance? Seems a dramatic speed up, never knew the difference on speed but I have read that is used for games for "desktop computer" games (x86).
Title: Re: Floorcaster
Post by: bwang on July 24, 2010, 07:02:04 pm
I'm not an ASM programmer, so I'm not sure whether the Nspire has an FPU.
Title: Re: Floorcaster
Post by: TIfanx1999 on July 25, 2010, 07:00:26 am
I converted everything to fixed point, and now I can draw twice the number of pixels and still get a 25% speed gain :)
Fixed point is amazing; I think my next project will be converting Ncaster to fixed point.
Very nice! I wonder how much of a speed gain Ncaster will get from this?
Title: Re: Floorcaster
Post by: fb39ca4 on July 25, 2010, 01:58:58 pm
I only draw half the screen right now.

What I mean is, since you only draw to the bottom half of the screen, you should only copy the bottom half of the screenbuffer.

Nice work with the fixed-point version. Could you have an option to change the quality in the next version? (2x2, 2x1, and single pixels.)
Title: Re: Floorcaster
Post by: bwang on July 25, 2010, 04:17:08 pm
I converted everything to fixed point, and now I can draw twice the number of pixels and still get a 25% speed gain :)
Fixed point is amazing; I think my next project will be converting Ncaster to fixed point.
Very nice! I wonder how much of a speed gain Ncaster will get from this?
Probably ~2x.
Title: Re: Floorcaster
Post by: bwang on July 25, 2010, 11:03:31 pm
Here's a small video of it in action on hardware, since I've given up trying to get screenshots to work.
Title: Re: Floorcaster
Post by: calcdude84se on July 25, 2010, 11:29:23 pm
Cool! Now for other textures besides a checkerboard ;D
Keep up the good work! :)
Title: Re: Floorcaster
Post by: TIfanx1999 on July 25, 2010, 11:49:04 pm
Excellent! You should be very pleased with the results! If only wish TI had put in a better LCD.
Title: Re: Floorcaster
Post by: bwang on July 26, 2010, 12:19:44 am
Yeah, this turned out to be a lot more usable than I thought it would be.
I should add tile mapping, so then I can write F-Zero Nspire Edition :D
Blarg, except I have several other projects I'm thinking about, and I'm busy with real life :(
Title: Re: Floorcaster
Post by: Builderboy on July 26, 2010, 01:32:26 am
Wow that looks excellent!  I cant wait to see what it will look like with a tilemapper working :D Especially greyscale ^^ Although the LCD kinda is no good :/
Title: Re: Floorcaster
Post by: bwang on July 26, 2010, 08:32:07 pm
OK, I got tilemapping working. I also replaced a bunch of subtractions and a division in the loop with a table lookup, so its even faster now.
The tile map is rather boring at the moment, since I don't have any good tiles to work with :( So I just stole a wall texture from Ncaster.
Title: Re: Floorcaster
Post by: willrandship on July 26, 2010, 11:04:33 pm
Wow! So...can ncaster and this run in tandem very well? also, how hard would it be to adapt it for the ceiling as well?

I hope I don't ask too much. I just had a crazy idea for a game used with this, and Ceilings would make it even better.

It's nice how much easier and faster greyscale is on the nspire....
Title: Re: Floorcaster
Post by: bwang on July 26, 2010, 11:46:10 pm
In theory, yes. In reality, due to speed concerns, Ncaster would definitely have to be converted to fixed-point in order to get enough FPS.
This is more useful for stuff like racing games. It basically does the same thing a Mode 7 engine would, only using a different method.
Title: Re: Floorcaster
Post by: AaroneusTheGreat on July 27, 2010, 12:03:18 am
This would only add a floor to the very most bottom level of the Ncaster level though, wouldn't it? Due to the fact that the floor casting is set to only do one level of height. It would definitely improve the visual aesthetics of the Ncaster, but on raised  up platforms and on stairs the floor would still be light gray correct? Or could you modify the engine to treat raised sections differently? Either way, if you can convert Ncaster to fixed point and get enough speed, I say go for the merging of this one with Ncaster because it will give the engine a feature that has never been done on a calculator before!

Oh also an optimization you could implement in the engine would be to only calculate and draw to pixels that don't have walls drawn there, therefore decreasing the amount of pixels that need to be calculated and drawn. There's no reason you would need to draw the floor there anyways, so it makes sense to avoid overdraw.
Title: Re: Floorcaster
Post by: apcalc on July 27, 2010, 12:04:36 am
bwang, this looks great!  It works very nicely on calc! :)
Title: Re: Floorcaster
Post by: bwang on July 27, 2010, 12:08:56 am
This would only to the bottom layer, but I agree it would still be nice.
I think I really will convert Ncaster to fixed point as soon as I find the time to do so. It'll be a bit tricky, but 2x speed increase with no algorithmic changes is well worth the work.
Title: Re: Floorcaster
Post by: AaroneusTheGreat on July 27, 2010, 12:20:45 am
Yeah I think so too. I didn't mention in my above post how awesome I think this is btw. It's epic. I really like how the perspective is so correct, that's often hard to do when texturing a floor real time. I don't know why but most of the time it looks as if the floor is warped on a ball or a curve of some kind, but yours is spot on. Well done.
Title: Re: Floorcaster
Post by: bwang on July 27, 2010, 12:33:31 am
Yep, ray-tracing has its advantages :)
Title: Re: Floorcaster
Post by: fb39ca4 on July 27, 2010, 10:21:43 am
Tilemaps and a fps increase? You've got to be kidding. :)

Are you going to release the source code for this version?
Title: Re: Floorcaster
Post by: bwang on July 27, 2010, 04:30:49 pm
Here you go.
Title: Re: Floorcaster
Post by: Silver Shadow on July 27, 2010, 04:49:27 pm
Woohoo! Looks awesome!
Maybe once I finish my other Nspire project, I'll start messing around with this engine...

And yeah, merging the two engines together would be epic!
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 29, 2010, 02:47:19 am
WOAH!

I just saw the video on the other page and this BLEW my mind. :O

Is the version with textures that fast? I wonder if a Mario Kart game could be possible? Or maybe combining both raycasting with floorcasting?

Darn I hope you finish this. You should make a demo with some sort of map like in F-Zero or Final Fantasy VI :)
Title: Re: Floorcaster
Post by: bwang on July 29, 2010, 02:53:10 am
The version with textures is even faster, thanks to a change in the code :)
Combining floorcasting with ray casting is certainly possible; however, much of the Ncaster code needs to be altered to support that (namely, the entire thing has to be converted to integer arithmetic). I originally intended for this to be part of a racing game engine (in the style of F-Zero).
I really need to go find some tiles and a map to render. That would make the demo look so much better.
The current map is 64x64 tiles. How big do you guys think a racing game's map should be? The map size is hard-coded for efficiency, so I need to know it if/when I make a release.
Title: Re: Floorcaster
Post by: Silver Shadow on July 29, 2010, 03:25:46 am
The bigger the better, I guess. :P
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 29, 2010, 04:10:43 am
I would really love a F-Zero or MK game. Also since you appear to use hi-res tiles, this would mean even better graphics than F-Zero :P

As for map size, I'm not too sure. Usually 64x64 is enough, but for a F-Zero game, it might need 128x128 since game usually goes pretty fast. I didn't like how a lap only lasted 8 seconds in some F-Zero 68K tracks.
Title: Re: Floorcaster
Post by: bwang on July 29, 2010, 04:27:14 am
The tiles are 64x64 pixels, in case you are interested.
The bigger the better, I guess. :P
But I think 128x128 may result in some icky accuracy issues in the integer arithmetic. I will check it out over the weekend (not tomorrow, since I am away). It also uses 4x the storage, but that's 16KB, hardly a concern with the Nspire's enormous 32 MB archive. Hooray for no more memory issues, ever!
Title: Re: Floorcaster
Post by: fb39ca4 on July 29, 2010, 03:45:46 pm
As for map size, I'm not too sure. Usually 64x64 is enough, but for a F-Zero game, it might need 128x128 since game usually goes pretty fast. I didn't like how a lap only lasted 8 seconds in some F-Zero 68K tracks.

I timed going from one end of the tilemap to the other, and it took 7 seconds, so we can expect laps to be 20 seconds at least.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 29, 2010, 06:29:00 pm
The tiles are 64x64 pixels, in case you are interested.
The bigger the better, I guess. :P
But I think 128x128 may result in some icky accuracy issues in the integer arithmetic. I will check it out over the weekend (not tomorrow, since I am away). It also uses 4x the storage, but that's 16KB, hardly a concern with the Nspire's enormous 32 MB archive. Hooray for no more memory issues, ever!
Aaah ok I see. As for size, I guess you could go with 64x64 if 128x128 poses too much issues. What about 96x96, btw?
Title: Re: Floorcaster
Post by: bwang on July 30, 2010, 12:02:11 am
The dimensions have to be a power of 2 in order for the bit-shifts and fast modulos to work.
Also, the final version will have a lower framerate, both due to the extra work involved in drawing sprites and the fact that right now, 40FPS on the Nspire's crappy screen causes blurring.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 30, 2010, 02:52:22 am
Aaah I see. And yeah I would reduce the framerate if I was you, since high framerate will be barely enjoyable x.x
Title: Re: Floorcaster
Post by: bwang on July 30, 2010, 03:01:05 am
Lowering the framerate is easy. It's increasing it that's hard :P
I think I'll write a fast sprite scaling routine next (basically, an integer version of the one in Ncaster). This might actually become a game :)
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 30, 2010, 03:03:06 am
I know, I wasn't saying it was hard :/
/me sighs
Title: Re: Floorcaster
Post by: calc84maniac on July 30, 2010, 03:06:47 am
Lowering the framerate is easy. It's increasing it that's hard :P
I think I'll write a fast sprite scaling routine next (basically, an integer version of the one in Ndless). This might actually become a game :)
You mean Ncaster? ;D All these "N" names get confusing after a while, I guess :P
Title: Re: Floorcaster
Post by: bwang on July 30, 2010, 03:37:53 am
Blarg, right. Fixed.
Today's typo was brought to you by the letter "N" :P
I know, I wasn't saying it was hard :/
/me sighs
I wasn't saying that you were saying it was hard :) What I meant was that the framerate will naturally decrease as more features are added.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 30, 2010, 03:44:45 am
Yeah I know. Plus if it's incredibly fast you can add much more stuff without needing to decrease it artificially too much.
Title: Re: Floorcaster
Post by: Hot_Dog on July 30, 2010, 12:10:06 pm
If you combine a wallcaster, ceiling caster and floor caster all in one, is that going to be slow?
Title: Re: Floorcaster
Post by: Silver Shadow on July 30, 2010, 01:32:24 pm
It all depends if the cosmic rays manage to mutate the blue lobsters.
Title: Re: Floorcaster
Post by: fb39ca4 on July 30, 2010, 02:35:43 pm
If you combine a wallcaster, ceiling caster and floor caster all in one, is that going to be slow?

Probably. Even the new features for the raycaster slowed it down majorly, from v0.0.1 all the way to v0.2.2. Though converting everything to fixed point will help.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 30, 2010, 03:03:57 pm
It all depends if the cosmic rays manage to mutate the blue lobsters.
wut?
Title: Re: Floorcaster
Post by: bwang on July 30, 2010, 03:24:10 pm
Actually, if I converted Ncaster to integer arithmetic and optimized it, a combined floorcaster + ray caster should get about 15 FPS.
It all depends if the cosmic rays manage to mutate the blue lobsters.
What will they mutate into?
Title: Re: Floorcaster
Post by: fb39ca4 on July 30, 2010, 03:32:57 pm
Even better: cosmic rays mutating ordinary code into machine-level optimized code :P
Title: Re: Floorcaster
Post by: TIfanx1999 on July 31, 2010, 07:52:42 am
Actually, if I converted Ncaster to integer arithmetic and optimized it, a combined floorcaster + ray caster should get about 15 FPS.
It all depends if the cosmic rays manage to mutate the blue lobsters.
What will they mutate into?
Rick Astley.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 31, 2010, 05:00:14 pm
Now you guys are gonna make Bwang create a racing game where the map is a pic of rick astley D:
Title: Re: Floorcaster
Post by: bwang on July 31, 2010, 05:38:07 pm
Lol, that would be one big picture of Rick Astley (4096x4096). It would be 8MB large.
Hey, that fits! Now if I only had a level editor... there's no way I'm going to manually enter 4096 tiles into a text file.
Title: Re: Floorcaster
Post by: DJ Omnimaga on July 31, 2010, 05:44:06 pm
yeah true :P.
Title: Re: Floorcaster
Post by: bwang on September 18, 2010, 03:08:33 pm
Code updated for the new Ndless and properly packaged.
I may start working on this again in the near future.
Title: Re: Floorcaster
Post by: critor on September 18, 2010, 03:49:07 pm
Code updated for the new Ndless and properly packaged.

Thanks!
Title: Re: Floorcaster
Post by: ztrumpet on September 18, 2010, 09:33:51 pm
This looks really cool from the still screenies.  Can all of us non-Nspire users have a moving screenie please?  Thanks! ;D
Title: Re: Floorcaster
Post by: bwang on September 18, 2010, 09:43:56 pm
I think there was a video several pages back, but it may have not been the current version.
Title: Re: Floorcaster
Post by: ztrumpet on September 18, 2010, 09:45:13 pm
Sorry, but there's not one.  * ZTrumpet looks on ticalc... ;D

Edit:  It appears that it's not on ticalc yet, so no chance of a screenie there either. ;D
Title: Re: Floorcaster
Post by: apcalc on September 18, 2010, 10:55:31 pm
I believe there is a video of this in the Omnimaga Ninth Anniversary Video.
Title: Re: Floorcaster
Post by: bwang on September 18, 2010, 10:59:42 pm
I'll post one in a bit, then.
Title: Re: Floorcaster
Post by: ztrumpet on September 18, 2010, 11:33:46 pm
I'll post one in a bit, then.
Thanks!  I can't wait to see this in action. :)
Title: Re: Floorcaster
Post by: DJ Omnimaga on September 18, 2010, 11:37:02 pm
Sorry, but there's not one.  * ZTrumpet looks on ticalc... ;D

Edit:  It appears that it's not on ticalc yet, so no chance of a screenie there either. ;D
There's a video of it in the 2010 Omnimaga tribute video. It even adds the Nspire blur effect so it looks closer to the real calc. It's very short, though.
(check around 00:50 in the video, right after Raylin's gravity game)
Title: Re: Floorcaster
Post by: critor on September 20, 2010, 03:21:24 pm
This would really be great including this floorcasting algorithm into Ncaster.

We could map a texture on the floor.
We could also map textures on the top and bottom of walls too!


Now what we all need is a new screen for the TI-Nspire.
Anybody working on such a "mod" ? ;)
Title: Re: Floorcaster
Post by: DJ Omnimaga on September 20, 2010, 03:51:41 pm
Hehe I wish the screen was better. A new screen would be very welcome x.x

Otherwise there could be the OTcalc project, one day, but it's not TI-related, so...