
Share Your Code
Browse Code
- All (914)
-
(95)
-
(87)
-
(45)
-
(4)
-
(42)
-
(136)
-
(22)
-
(40)
-
(13)
-
(66)
-
(153)
-
(211)
Texturemapped Raycasting Engine
As a follow up to my original code share of the Corona port I did of my 2D raycasting engine, texture mapped walls have been added.

This was achieved using sprite sheets. The downside of this is the frame rate takes quite a hit compared with the flat filled walls shown in the original sample. I know I can optimise how I use sprites in this demo, but I still think more needs to be done to get the frame rate up - that may mean using a different approach than sprites.
There is a mode button at the top left, which allows you to switch between textured and flat filled walls. The boxes on the left control your camera direction, and the two on the right control backwards/forwards movement.
Rather than relist all the code from before, I will just link it from my site. Most of the code remains untouched, outside of moving files into sub folders, and the changes to the render system. There is also a bug fix included in the raycasting engine to fix the texture offset returned for each wall slice to draw.
You can download the full source from here
Questions and comments always welcomed :)
- Type:
- Tags:
Replies
This is really incredible work. I think you are crossing the line which we all hoped could be crossed but couldn't see how to.
I assume the frame rate would be back up there if 2.5d image manipulation were to be worked on by Ansca? Though the 3D code would be significantly different....
Amazing work, very impressive.
Have you tried this on the latest daily build? The new automatic culling feature of offscreen objects may help tremendously with the framerate
Thanks for the positive comments guys :) The feedback i've been given on my previous demos/samples has actually kept me going to go 'one better' and try to improve them, or come out with something even better.
I have just updated the raycaster to v1.2, which has improved usage of sprites, giving the demo a frame rate boost. I also found 1 extra scan line was being calced every update, so that too offered something of a frame rate boost (although minimal).
You can get the updated version from the same link.
@Danny: I did see the new improvements released and spent some time in the blog reading up on them. It was funny timing actually since I had just been playing with sprite sheets, and now they are deprecated with something better. Although I was happy to see I can adapt easily.
I can't grab new build though since I'm not a subscriber. I'm holding off on that for now as I would like to see solid offline documentation available (I do most of my Corona coding without net access, so need offline docs to assist).
>> I'm not a subscriber
Ansca Team! Give that man a free subscription for being an awesomely nerdy contributor!
Very sweet GREAT Job!!!
Good Job!
thanks for sharing !
Marco
HOLY CRAP.
That means I like it. I feel like I am playing Wolfenstein 3d haha. It's amazing this can happen in Corona. Crazy Crazy Crazy!
Way cool. I don't understand the logic looking at it (I looked at the code and my brain went nuclear shutdown) but I can kind of see how it's done....barely.
You sir are highly skilled.
-ng
I just tested this on the iPad3.
It runs at an acceptable speed - I can absolutely imagine a 90s-style dungeon crawler using this ;)
Did you test it using latest daily build?
WOW! That's all I can say!
The only problem is understanding the logic behind!
Seriously, Hats off!
Hello Jesder,
What are the licensing terms for your ray-cast work?
I think some people are studying this and will happily make use/re-use commercially if allowed.
Thanks in advance for your answer and keep the good vibe going.
Giuseppe
@Satheesh: Here is a link to the same documentation I learnt from almost 15 years ago: http://www.permadi.com/tutorial/raycast/
The theory behind raycasting is actually quite simple when you get down in to it - especially when it's only dealing with 2 dimensions. Check out the link if you are interested!
@Giuseppe: Contact me at andrew.burch at newhighscore.net. If you are interested in using it for a project, I'd love to hear more!
Thanks everyone for the positive feedback - glad to see people have taken a strong interest in it :)
@Jesder Thanks!
Will do some reading.
@Jesder
Thanks a lot for your link at the tutorial, that's really what I was looking for!
I'm just planning to play a bit with ray-casting and make a small, fun game with 2D Corona by combining 3-4 environments to get a maze.
I understand I need to plan a bigger matrix and sketch a map, we will see what happens with performance.
Thanks again and keep going! Giuseppe
@Jesder awesome link! I can see clearly now the rain has gone :D
Ok, started putting my head into this great work from Jesder and the tutorial he put the link to.
The first remark I can do is that Jesder's solution it is very textMemUsage consuming at the moment.
In fact, by putting the well known Ansca memory checker at the end of his main.lua:
1 2 3 4 5 6 7 8 9 10 11 | local function garbagePrinting() collectgarbage("collect") local memUsage_str = string.format( "memUsage = %.3f KB", collectgarbage( "count" ) ) print( memUsage_str ) local texMemUsage_str = system.getInfo( "textureMemoryUsed" ) texMemUsage_str = texMemUsage_str/1000 texMemUsage_str = string.format( "texMemUsage = %.3f MB", texMemUsage_str ) print( texMemUsage_str ) end Runtime:addEventListener( "enterFrame", garbagePrinting ) |
and launching the app in the simulator, I can read:
memUsage = 719.371 KB
texMemUsage = 67.584 MB
The latest value is clearly too much for older mobile devices equipped with 128 MB Ram. I'm going to have a try with my 256 MB iPod Touch 4g as soon as possible. The latest CORONA SDK package only deploys to iOS 4.3 and following, so we are at the lower limit just now.
Considering that I want to populate this environment in order to make a game out of it, it appears that the critical value to look at is that texMemUsage value.
Well, going to have my tries and then reporting here. THanks again to Jesder.
Any people working on that?
Thanks for sharing. I hope to create something as fantastic as this. Thanks.
in a ipod touch 4 work so SLOW that I can say that don't work...
it is working on android or others devices?
Really awesome work Jesder.
Thanks for sharing.












impressive work !
thanks for sharing !!