Share Your Code

3D Tunnel

Posted by Matthew Pringle, Posted on May 8, 2011, Last updated May 9, 2011

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.


Replies

innominata
User offline. Last seen 1 year 35 weeks ago. Offline
Joined: 5 Feb 2011

if only we could get things pushed into a c script :P
howabout corona c modules :D
just add what you need, keep down bloat.
the things I could do with php's gd library...

gtatarkin
User offline. Last seen 4 weeks 10 hours ago. Offline
Joined: 16 Dec 2010

Hi Matt,
first of all - I'm at the end of a major project in my full time work so I haven't time to look at Your code. Sorry, will do it until end of week I hope.

secound of all - (by Wikipedia) Lua programs are not interpreted directly from the textual Lua file, but are compiled into bytecode which is then run on the Lua virtual machine. The compilation process is typically transparent to the user and is performed during run-time, but it can be done offline in order to increase loading performance or reduce the memory footprint of the host environment by leaving out the compiler.

Like most CPUs, and unlike most virtual machines (which are stack-based), the Lua VM is register-based, and therefore more closely resembles an actual hardware design. The register architecture both avoids excessive copying of values and reduces the total number of instructions per function. The virtual machine of Lua 5 is the first register-based VM to have a wide use.[4] Parrot (currently in development) is an another well-known register-based VM.

So, Lua sometimes is 40 times slower when C ( worst cases ) and sometimes only 3-4 times slower.

If You want to build kick ass 3D game in Corona You sholud think like the eighties/nineties game programmer -tricks, pre math, tricks, matrix, fastest algorithm and tricks again.

Some time ago I did an experiment with big Lime maps and If you display (object:isVisible = true) only really needed parts preformance is 1700 - 3000% better when without this simple trick.

Regards

Matthew Pringle
User offline. Last seen 30 weeks 5 days ago. Offline
Joined: 23 Feb 2010

The angle and distance tables are precalculated for speed.

The slowdown is updating the screen buffer, which in this case is a massive array of vector squares used to represent pixels.

So every 30th of a second im processing 6144 vector squares (1/5th screen res and scaled), this is where the cpu hit takes place, Corona just cant handle that many objects per frame.

gtatarkin
User offline. Last seen 4 weeks 10 hours ago. Offline
Joined: 16 Dec 2010

"So every 30th of a second im processing 6144 vector squares (1/5th screen res and scaled), this is where the cpu hit takes place, Corona just cant handle that many objects per frame."

and Corona shoudn't do this :) This is my point.
Regards

Matthew Pringle
User offline. Last seen 30 weeks 5 days ago. Offline
Joined: 23 Feb 2010

Your point was that Corona can do 3D.

Im saying that without a better way to update the real screen buffer this wont happen, if this was being programmed in obj c / c and I could interact with the screen buffer directly through the graphics chip.

gtatarkin
User offline. Last seen 4 weeks 10 hours ago. Offline
Joined: 16 Dec 2010

You have right if we both think about modern 3D graphics but what about Doom/Doom2 pseudo 3D tricks? You can translate and transform texture in Corona without bitwise operation. Just look at the Text Candy examples. It should works fine in my opinion.

After finish my work project will dive deeper in 3D tricks and see what can be done.
Regards
Greg

innominata
User offline. Last seen 1 year 35 weeks ago. Offline
Joined: 5 Feb 2011

Anyone seen doom in javascript?
http://canvex.lazyilluminati.com/83/play.xhtml

innominata
User offline. Last seen 1 year 35 weeks ago. Offline
Joined: 5 Feb 2011

Also, I'm assuming this loops at some stage, is there any logic in caching the frame buffer... does corona store tables purely in LUA or does it have some sort of C interaction. i.e. when you perform a transition.to, how does the backend handle the displaygroup you send it? :P

Matthew Pringle
User offline. Last seen 30 weeks 5 days ago. Offline
Joined: 23 Feb 2010

@gatarkin

I don have Text Candy, can you share your texture warping code so I can have a look.

A lot of the old school techniques still required hardware interaction at some level. SNES has mode 7 ( and other modes ), Amiga had a bunch of dedicated 2d chips and modes and Sega developed similar things.

For instance on the Amiga the blitter would be used for what I am attempting.

Mode 7, Mario Kart style required the screen buffer was constantly interrupted and reprocessed between frames which when rebuilt gave the 3D effect.

Im also talking about these effects being able to run real time, at 30fps and without slowdown. Nothing I have seen so far would lead me to believe that it is in anyway possible with the limited options that Corona offers.

@innominata
The frame buffer is cleared every frame, well each pixel has its values set to the colour the function returns. Corona passes your lua commands back to c / objc functions which interact directly with opengl. The native functions which Corona can access are very fast and accelerate by onboard hardware.

Lua is processed directly at runtime and this in turn instructs Corona to instruct opengl to do whatever is requested, or openal for sound etc...

gtatarkin
User offline. Last seen 4 weeks 10 hours ago. Offline
Joined: 16 Dec 2010

@johnson.miller100 ugly spam detected!