Field of View / Shadow Casting Demo

In tile based games you might need to workout if an enemy can see you, if your player can see past an object etc...

Ive based the demo on this http://roguebasin.roguelikedevelopment.org/index.php?title=FOV_using_recursive_shadowcasting_-_improved which is itself based on an article by Björn Bergström on the subject.

Here is the demo http://www.alienhorde.com/files/field_of_view.zip It requires Lime so you need to add all the files for Lime yourself.

It should also be said this cannot run in realtime, the code is just too much for LUA but it is useful in turn based games. My implementation is also running slower as im rendering a separate shadow mask to make a torch light effect.

In fov.lua change "local maskTileSize = 16" to either 8 or 4 to up the resolution of the shadow mask.

Hi Res Very Slow Calculation

Low Res Fast Calculation

This is an early demo of the code, any ideas how to speed it up would be great, otherwise help yourself and alter as needed.

A better implementation would be to alter the map directly rather than building the separate shadowmask as that is only the size of the screen and if there were not walls at the edges it would try to access values in the array which didnt exist and cause a crash. By scanning the full Lime map that would probably be avoided.

The images are for the demo only as I found most of them online and are not mine.

Really really awesome!

Good work :) Made few real life test of iPod Touch 4G and performance is ok. What do You think about raycasting? Javascript Wolfenstein 3D 640x400 with this algorithm works very good in browser so Corona SDK version should be very fast and easy to build lua version

http://www.nihilogic.dk/labs/wolf/

http://dev.opera.com/articles/view/creating-pseudo-3d-games-with-html-5-can-1/

Visual result should be much better when png mask cheat which I use some time ago for dynamic light :)

Code like this needs to be pushed into C, lua is more for game logic than deep calculations like ray casting. On a turn based game its fine but for realtime 30fps it uses all the cpu and leaves nothing for the rest of the game logic.

As far as Wolf, again the routines would need to be in C for speed and Corona needs image manipulation, warping etc... to accomplish the texture effects. Hopefully some of this is coming soon.

Remember a browser on a PC runs many times faster than Corona on an iPhone / iPod Touch. Same as flash on a PC compared to Corona on iPhone.

M

Rendering pseudo 3D in browser using canvas and javascript (without hardware acceleration ofc) is slooooowwwww as drunk snail but as You see it's still playable :)

BTW. Have some fun with rewrite my old javascript project:
http://panzeronline.com/about.php
algorithm like advanced pathfinding, possible moves etc etc etc works well in Corona SDK.

It's even possible to build real 3D game in Corona SDK like this:

http://www.nihilogic.dk/labs/chess/

Regards

How would you suggest building any type of 3D in Corona. It can only render flat squares / circles / lines / texturemaps and cant warp images?

The only feasible way would be to render each pixel for every frame which would kill your computer never mind an actual iDevice.

I would think that bringing up a browser window inside corona would allow any CSS 3D effects that Safari supports but that wouldnt be doing it inside Corona and would limit what could be done I would think.

Pathfinding demo code for Corona is on here for those who want it

http://mobile.tutsplus.com/tag/path-finding/

Mine pathfinding algorithm is much better :) Matt - look at source of this demo. It's just some tricks in pure javascript and canvas easy to implement in Corona SDK like teapot demo.

Hey gtatarkin

do you have a link to that demo?

Matt

Ok Matt - let me deal with this problem and see what Corona can do without native 3D support :)
Regards

Ok man - no CSS tricks, just pure javascript with canvas elementh 3D demo:

http://www.concat.pl/canvas/

HTML5 Canvas ( https://developer.mozilla.org/en/canvas_tutorial ) can only draw primitives like flat squares / circles / lines / texturemaps (like Corona SDK).

It uses Three.js a javascript 3D engine. https://github.com/mrdoob/three.js/

Canvas still lets you draw complex shapes through paths and fills which Corona doesn't support. You also need to be able to warp images to produce a 3D effect which Corona doesn't yet support.

Ive requested such features as discussed here http://developer.anscamobile.com/forum/2010/08/09/simple-3d-transforms

and tried to simulate something like it using sprites http://developer.anscamobile.com/forum/2010/08/22/simple-3d-texture-background

I could take each pixel of an image, convert that into a 1px by 1px object, rearrange them all on screen to form the original image and then transform each sprite by size and position to reproduce a 3D transform of the plane but it would take so long in cpu time it would be useless.

OpenGL, which Corona uses, has these and more and is fully hardware accelerated. These transforms have not however been exposed to the programmer through the Corona API.

With just fills for paths you could achieve this http://en.wikipedia.org/wiki/File:Virus-amiga-screenshot.gif

but without you could only probably achieve this http://en.wikipedia.org/wiki/File:Virus-spectrum-screenshot.gif

Ok, Matt - just put simple 3d cube in code exchange:

http://developer.anscamobile.com/code/simple-3d-transform-corona-sdk

Texture and simple light comming soon :)

Regards

Hey gtatarkin

I would love to see how you will handle texturing. Im doing a 3D tunnel with real texturing but it will only run at a very low resolution.

M

Nice demo btw

I can show You how to do it but I'm little lazy right now :) Look at Text Candy code ( _DoDeform = function(Group) - line 1334 ) and this is how You can handle texturing in 3D mode:

http://www.youtube.com/watch?v=AjrWRWc0ivg

Regards

Hey gtatarkin

Sorry for the late reply, I was away over easter.

Here is the 3D tunnel with texture mapping code.

Original Texture

Download source

http://www.alienhorde.com/files/tunnel.zip

Its running at a very low resolution and scaled to fit the screen, even then on an iPhone 4 it gets about 4fps. The textures are processed with php to get the colour values which are then saved into a lua table which rebuilds the image in the fake screen buffer im using.

Its slow but it works and shows how easy it is to do something very complicated in Corona / Lua.

If these calculations were pushed into a C script, Corona could do this at full speed.

views:3551 update:2011/10/13 16:30:09
corona forums © 2003-2011