Omnimaga
Calculator Community => Other Calc-Related Projects and Ideas => Topic started 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! :)
-
This looks great bwang!
Thanks for posting! ;)
-
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?
-
It does the linear algebra for every pixel.
Here's are the loop contents:
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?
-
neither method allows vertical motion actually i think. What kind of framerate do you get?
-
20-30 at the moment.
This one does with minimal code changes.
-
Thats really nice, is it pixel by pixel? Or do you use 2x2 pixels.
-
2x2 pixels.
-
Nice, we can has screenies? You know we love our screenies :]
-
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.
-
Even stills could be nice, but i can be patient ^^ I cant wait to see what could be done with this :)
-
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.
-
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?
-
Yeah, I'll probably do that, even if I have to sacrifice screen area.
2x1 looks sooooo much better than 2x2.
-
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
-
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)?
-
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!
-
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.
-
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.
-
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.
-
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).
-
I'm not an ASM programmer, so I'm not sure whether the Nspire has an FPU.
-
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?
-
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.)
-
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.
-
Here's a small video of it in action on hardware, since I've given up trying to get screenshots to work.
-
Cool! Now for other textures besides a checkerboard ;D
Keep up the good work! :)
-
Excellent! You should be very pleased with the results! If only wish TI had put in a better LCD.
-
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 :(
-
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 :/
-
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.
-
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....
-
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.
-
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.
-
bwang, this looks great! It works very nicely on calc! :)
-
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.
-
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.
-
Yep, ray-tracing has its advantages :)
-
Tilemaps and a fps increase? You've got to be kidding. :)
Are you going to release the source code for this version?
-
Here you go.
-
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!
-
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 :)
-
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.
-
The bigger the better, I guess. :P
-
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.
-
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!
-
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.
-
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?
-
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.
-
Aaah I see. And yeah I would reduce the framerate if I was you, since high framerate will be barely enjoyable x.x
-
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 :)
-
I know, I wasn't saying it was hard :/
/me sighs
-
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
-
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.
-
Yeah I know. Plus if it's incredibly fast you can add much more stuff without needing to decrease it artificially too much.
-
If you combine a wallcaster, ceiling caster and floor caster all in one, is that going to be slow?
-
It all depends if the cosmic rays manage to mutate the blue lobsters.
-
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.
-
It all depends if the cosmic rays manage to mutate the blue lobsters.
wut?
-
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?
-
Even better: cosmic rays mutating ordinary code into machine-level optimized code :P
-
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.
-
Now you guys are gonna make Bwang create a racing game where the map is a pic of rick astley D:
-
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.
-
yeah true :P.
-
Code updated for the new Ndless and properly packaged.
I may start working on this again in the near future.
-
Code updated for the new Ndless and properly packaged.
Thanks!
-
This looks really cool from the still screenies. Can all of us non-Nspire users have a moving screenie please? Thanks! ;D
-
I think there was a video several pages back, but it may have not been the current version.
-
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
-
I believe there is a video of this in the Omnimaga Ninth Anniversary Video.
-
I'll post one in a bit, then.
-
I'll post one in a bit, then.
Thanks! I can't wait to see this in action. :)
-
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)
-
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" ? ;)
-
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...