Saturday, March 28, 2009

Review of 3D Engines for the iPhone

I need a 3D engine for my iPhone project. I've hacked together my own 2D engines for rendering and physics in the past, but I have done very little OpenGL, and all the time I spent hacking around in the Quake, Quake2, Quake3 engines was focused on game logic and AI. This means that it is hard for me to define suitable requirements upon which to discriminate between available iPhone 3D engine middleware.

Requirements
Generally, I think my needs are modest (although still too rough to prepare a feature matrix comparison):

  • 3D rendering and rigid body 3D physics
  • Demonstrated iPhone integration and deployment (technically possible and apple has permitted deployment)
  • Low polygon counts regarding world entities, robust physics simulation (one creature as a dozen or so cuboids connected by simulated muscles)
  • Facility to execute physics simulations in a/the world without rendering (at the same time as rendering would be really nice but implausible given the hardware)
  • Programmatic management of 3D world entities (definition, instantiation, post-simulation manipulation)
  • No cost (I don't mind open sourcing my project if it is permitted by the conditions of the Apple AppStore)
Candidates
Two clear candidates have emerged that may satisfy my needs, as follows:
  • SIO2 Interactive, SIO2: An opensource (LGPL) game engine for the iPhone. It uses the Bullet physics library and 3D objects and scenes are prepared using the opensource tool Blender. The project offers many tutorials (16) some of which are screencasts. The project also boasts a healthy number (15) of deployed iPhone applications available in the AppStore. The engine has a free version that imposes a flash screen (advertisement for the engine), an indie version is available without this restriction for $50USD. The volume of developer documentation in the form of tutorials is great, although the seeming dependence on Blender to prepare the 3D models and scenes used by the engine may be a deal breaker if there is no programmatic workaround.
  • Oolong Game Engine (on google code): An opensource (MIT License) game engine for the iPhone with some credibility given that it was developed in large part by Wolfgang Engel, Rockstar Games' lead graphics programmer. It uses the Bullet Physics Library for 3D physics and fluid studios for memory management. It has seemingly been used in a small number of titles (3?) currently available in the AppStore and proposes that it was used as the basis for the iTorque Game Builder. The source code comes with a number of demonstrations, although developer support documentation and tutorials are really lacking, and the mailing list is quite empty. This might be an engine for hard core developers.
Missed the cut
I came across four engines that missed the cut only because of an associated cost or maturity. I may reconsider selecting one of these engines if (and only if) it can be demonstrated that their adoption will save me time (or money - yes I'm keeping timesheets) on this project.
  • Unity 3D Engine (Unity Technologies): A cross platform engine that offers iPhone integration features and support. A large number of titles use the engine and presumably some of which are available in the AppStore. The core engine costs $199.00USD (Indie) plus there is a cost of $399USD (Basic) for iPhone integration totalling at least $600USD to get up and running. The cost buys support both in terms of documentation and a company that will return your support emails and calls. The engine looks slick and it seems a lot of people are using it.
  • tTGB - the iTorque Game Builder (Garage Games): The Torque engine has been ported to the iPhone and is offered as two products: iTGB for 2D games which is available now for $500USD (presumably built on the old TGEA platform), and a planned but as yet un-released T3D that presumably will have iPhone support. The software is both a builder software for making the game (WYSIWYG 2D editor) as well as an engine and packing tools for deploying your game. As with Unity 3D, the cost of iTGB is for the documentation and human support, and also like that engine it looks really slick. It was unclear to me how may titles have been built using this product and are available in the AppStore.
  • Ston3D Engine (ShiVa): The Ston3D engine offers iPhone integration support as a free add-on after purchasing the core product called ShiVa for $169.00GBP (about $244USD). ShiVa is a Windows-based game development product (like the Torque product) and offers a crippled free version that prevents publishing created games. A number (at least 8) of iPhone titles have been released based on the engine and are available in the AppStore.
  • CubicVR Engine (on sourceforge): An opensource (LGPL) game engine with no clear stable builds (only SVN access). There are some iPhone demonstration projects provided with the source code. It uses the Bullet physics library and supports other mobile and console platforms. The code base is seemingly the basis for the Pocket Hoops game in the AppStore. The project does not seem very mature and there are no clear tutorials or support documentation for starting a game project. As such, it did not make the cut.
Out of Scope
I came across a number of related projects that partially addressed some of my needs, but ultimately were out of scope. They are listed here for completeness, or in case I miss-interpreted the projects.
Alternatives
Some alternatives popped into my head while 'deep googling' this problem and I thought I'd list them in the event I do decide to re-scope the project.
  • Write my own: One option that I briefly considered and dismissed given the time it would consume is to write a 3D rendering engine myself. I might be able to piece together the things I need from tutorial sites like Nehe and OpenGL ES. For the physics I could use an off-the-shelf solution like Box2D (used for Rolando) or Bullet.
  • Port an engine: There are many great 3D engines out there just ready and waiting to be ported to the iPhone. May of the communities of those engines have manifest demand, are discussing, or have already started the porting process like Irrlicht, OGRE, and Allegro. Frankly, I do not have the current chops or inclination to get into a port.
  • Use a Quake: Both the opensource (GPL) Quake and Quake III Arena game engines have been ported to the iPhone and are available on jailbroken phones via Cydia. Both engines are 3D, have long histories of community involvement (mods and engine ports), and the source code of their ports are available (quake4iphone and quake3-iphone). Also, id Software might be releasing these titles officially soon enough. I've had experience with these engines before, but not regarding the simulation and rendering of arbitrary programmatic generated world entities. As such I may have more trouble than a conventional 3D engine in trying to shoehorn non-quake techniques into the engine (maybe a good fallback position).
The Plan
As a warm up I was thinking of writing some tutorials on how to compile and deploy wolf3d, doom, quake, and quake3 for the iPhone. I suspect they will not be too hard to write given the sources are out there, and I expect it'll provide a good opportunity for getting up-to-speed on the environment.

Regarding my choice of 3D engine, I want to go with Oolong for as long as possible and fallback to SIO2 if progress proves too slow. I have booted the sample programs from both projects in the iPhone simulator, and have started to get a feeling for how one might map the algorithms and data structures from morphology evolution research into a 3D world. This brief research into available engines gives me some alternatives if the scope of the project changes or if I get fed up and decide I require developer documentation and support. I'm looking forward to starting the build early next month, after I finalize some GUI and algorithm designs.

Check out a similar round-up by Matthias Gall from September 2008 entitled "3D Engines on iPhone / iPod".

Please drop me a comment or email if you know of any further 3D engines or related resources.

Wednesday, March 25, 2009

Not Reading Passively: iPhone Links

In the spirit of not reading passively, I've been trying hard to write summaries of all the iPhone related links I've been reading. Here are a recent mix from the last week of high-level iPhone propaganda and low level technical details:

  • iPhone SDK 3.0: A New Beginning: The new 3.0 iPhone OS as the new desktop. iPhone apps are more like simple desktop apps than conventional mobile apps. Android is a long way behind re developer base/app maturity. Constraints on the iPhone are liberating. iPhone is secure, no viruses like windows mobile and blackberry. Lots of fanboy spam in this post as well.
  • Should An iPhone App Developer Charge Or Run Ads? (Galaxy Impact Case Study): TechCrunch post on paid apps versus free app with advertising. Example app tanked after releasing for free then charging a dollar then free again. Lesson is to pick the right model at the start and stick with it.
  • Pinch Media Data Shows The Average Shelf Life Of An iPhone App Is Less Than 30 Days: Only 20% of users return to app after initial download. After 30 days, 5% of users still use app. Return is about 70c per user, equiv with free app is an $8 CPM (most are 0.50 to 2.00).
  • Coder's Half-Million-Dollar Baby Proves iPhone Gold Rush Is Still On: Wired article on the iShoot case study (lucky bastard). >600K in a month, 37K a day as number one in app store.
  • Good iPhone Practices: Discussion of managing buttons in UITableViewCells. Only use a XIB file only for a complicated interface. Discussion of instantiating UIViewController subclasses.
  • Intro to the Objective-C Runtime: How objective c works at the run time level. A class is a struct. An object is a pointer to a struct, the first variable of which is a pointer to its class. Struct contains compatibility info for older operating systems, built on top of C, can go rooting around to see how it works/hangs together.
  • Using Multiple OpenGL Views And UIKit: Discussion on how to mix openGL views with UIKit controls/views. Apple suggest to avoid doing transformations with opengl views, avoid putting transparent buttons on them. Stop doing frame updates when opengl view is not visible. Discussion of opengl view, mixed with uiview, mixed with multiple opengl views.
  • Cocos2D: Open Source 2D Game Engine for iPhone Developers: Engine for easy development of 2d games for the iphone. Open source, built in physics engine (chipmunk).
  • iPhone - Interface Builder Tutorial: Excellent interface builder tutorial that was recommended by someone/where. Step-by-step, very clear.
  • Tutorial: JSON Over HTTP On The iPhone: Tutorial that demonstrates how to consume, parse, and display a JSON feed from the web in an iPhone app.
  • Apple iPhone Makes Up Half Of U.S. Smart Phone Web Traffic: Study that suggests that 50% of smart phone traffic on the web is coming from iPhones. Up from 10% in August 2008. Android is at 5% in the same market.
  • Engineers show off "no jailbreak" iPhone keyboard hack: What I liked about this article was the clever workaround for interfacing with the phone, specifically by using the headphone port (WTF?). It "allows two-way transmission of data using frequency shift keying, the same method used in early modems". Awesome.
  • Apple Putting The Squeeze On iPhone Developers: A rumour site. Describes an amendment to the iPhone developer contract that forces developers to submit to a 90 day refund policy for apps in the app store. Developers would have to cover apples 30% cut as well, leaving them out of pocket (how could that be?). Although the clause may have always been in the contract.
  • PhoneGap: A very interesting project focused on automatically generating native (!) iPhone (and other) apps from javascript. Way Cool! You can access device features. Oh yeah, it's open source. Check the video.

Monday, March 23, 2009

Running a Genetic Algorithm on the iPhone

I saw a post the other morning on the Genetic Argonaut blog entitled "Running Genetic Algorithms On A Cellphone". The post described the work by Christian Perone running a genetic algorithm in python on a mobile phone, specifically a Nokia N73 with Symbian and PyS60.

"Cool" I thought. "I can do something like that!"


I uploaded an old genetic algorithm script I wrote in Ruby for my Intelligent Algorithms project and it ran first time under iPhone Ruby (installed by Cydia), no problems at all. The above image is a screen shot I took in my jailbroken iPhone console running my GA script on a simple two-dimensional ("sphere") function optimization problem.

Not a big deal really. Wait until you can play with evolved 3D creatures on the iPhone, that will turn some heads!

If anyone wants the ruby script, shoot me an email.

3D Virtual Creature Evolution Part 1: Videos

Inspiration is an important concern for Natural Selection, my current iPhone application under development. In communicating the inspiration for the app over recent weeks, I have reverted to accompanying any description I write with a link to a YouTube clip of Karl Sim's early 1990's research. I thought I would take some time to elaborate on this inspiration and dig up a bunch of related motivational resources.

I'm breaking this down into two posts, the first (this one) provides a collection of YouTube links to the results of 3D creature evolution, and the second longer more academic most summarises the state of research with lots of links to people and papers (I'll publish it in about a week).

An important element of broader success of the field of virtual creature evolution (and ALife) is the visual results it provides. Karl Sims is commonly referred to as the godfather of the of the study of evolved virtual creatures not because he released the first papers on the topic (he didn't), but because he (or someone close) ensured that digital videos of the work were released and popularised. Importantly, these videos are still around on the web and are held aloft as the seminal examples of this and the broader field can produce.

The two great video's of Sims' work I often share around are the following (they both have narration):

Sims' creatures are adapted to address very specific and narrow goals in simulated 3D environments including: swimming speed, walking (distance from origin, total distance traveled), jumping, light following, and block possession.

Any searching of this topic on YouTube will very quickly turn up results related to Lee Graham's 3D Virtual Creature Evolution (3DVCE) project. The project offers software to design and run experiments for creature evolution as well as a distributed environment for more elaborate experiments. A very clever marketing strategy adopted by Graham (intentionally or otherwise) was to exploit YouTube to both publicise the fruits of his efforts, and as a database for the favourites and the 'zoo' of user submitted creatures. The effect is a near dominance of video-based searching on the topic.

There are far too many videos to list (and I have watched a large number of those that are out there). I've listed a broad pseudo-popular and interesting collection, as follows:
Graham also links to an impressive number of related projects, providing an excellent summary of the state of web-available projects in the field.

Nicolas Lassabe has some interesting challenges involving walking, stair climbing, block pushing, walking across blocks, and even skateboarding:
Evo Runners (I can't access their blog either) provides some good videos, some with some excellent production quality, including:
The AnimatLab have a very interesting video involving the evolution of different flapping strategies in a simulated bird:
I really love the videos by Tyler Streeter of his evolved humanoid jumping behaviour. It makes me laugh out loud every time!
Finally, here are some additional random clips I came across and thought worthy of a look:
An excellent aggregation of videos and links in this field (inspiring this post) was compiled and published by Alex Champandard of AIGameDev last February entitled: Evolving Virtual Creatures: The Definitive Guide.

Please, if you know of some more/better videos of three dimensional creature evolution leave a comment or get into contact with me.

Sunday, March 22, 2009

iPhone Resurrection and New iPhone App Project

After my iPhone fall from grace, I bit the bullet and bought a new iPhone. It sucks, I'm out of pocket. I'm trying to get over it and I'm optimistically looking to the future. I've jailbroken again, and I'm very aggressively developing a new iPhone application (out side work hours) with an estimated launch mid year.

I have been noodling around the idea for a while and even mentioned it before on this blog. I started development it on Wednesday 18th March, and since that time I've bashed out: 1) a project plan, 2) a functional requirements specification, and 3) draft technical designs for four major technical risks in my project (should one do business plan for a self-managed iPhone game?).

I have been debating with myself over the last few days how much information to publicly release on my ramp up to build. I've tendered comment on functional spec from mayhem and some developer friends, with excellent results so far. Frankly, I'm afraid that some kid with 6 months more ObjectiveC/OpenGL experience than me will see my idea and scoop me. I want to make some cash out of this (cover the cost of the phone/s), but more than the money (I have a good job in the real world) I want this app to exist in the world so that I can burn phone cycles (and my phone battery) playing with it. This latter need supersedes my concerns, so I'm going to release general descriptions of what I'm working on and release more (like the docs) to those who show an interest.

The code name for my project is 'Natural Selection', although iPity or iPhone Resurrection may be more appropriate project code names. The app is based on my obsession with simulated morphology evolution over the last 10 years, way before I dropped out of the world to do my Masters and PhD in Computational Intelligence.

The description from the head of my functional requirements specification is as follows:

The 'natural selection' iPhone application is an evolution simulator for the iPhone and iTouch platforms, providing light entertainment in a game like environment.

Natural Selection provides a selection of 3D environments and challenges for a virtual creature to adapt to and solve using an evolutionary process. Example environments include walking, swimming, flying, jumping, following, carrying an object, and fighting. The environment defines a virtual 3D space including a plane, obstacles, gravity, friction, and weather. Creatures are defined by a base body plan (head, body, arms, legs) in terms of 3D geometrical shapes that are connected via simulated muscles. The evolutionary process operates upon a genetic code that defines a given creatures body plan and muscle sensor-to-actuator configuration.

The user selects an environment and a base body plan from their respective libraries and watches as the creature adapts, specialising to the constraints of an environment under an evolutionary process. The user interacts with the process passively by moving the camera around the environment as the creatures evolve, and directly by manipulating the parameters of the evolutionary process. The parameters for the environment can be modified in real-time, changing the objective and constraints imposed on the creature under the evolutionary process.

Creatures and environments can be saved with screenshot and a symbolic name that can be used to load the creatures and/or environments in a later simulation. Creatures can be shared with friends via electronic communication such as email.
Naturally, there is more to it, especially along the lines of making it a 'game' (thanks Dave) and interactivity toward reinforcing behaviour (thanks Nigel). If you're at all interested, I hope that the description wets your appetite. Contact me if you want to know more, or get involved in some way! In the medium term I'm starting to evaluate 3D and physics engines for the iPhone platform (to give me a leg up), and I'm desperately going to need a source for sweet iPhone-esk graphics and music in coming weeks and months.

I think an iPhone or OpenGL hacker could whip something up in a few weeks to scoop me. Right now as I type this I think I would be pissed off (emotional brain). Nevertheless my rational brain keeps kicking in reminding me of the 10 years of my life I have dedicated to studding to this domain and the 5 years of that I spent designing building these kind of systems. I've got the heuristic and algorithmic savvy as well as the passion to pull this app off well, maybe better than potential scooping competitors. And if this suspension of disbelief fails me, at least there will be some incarnations of the idea out there in the wild (hopefully) for me to play with.

Wednesday, March 11, 2009

So I bricked my iPhone...

My brand new iPhone is basically a write off, and I'm sad.

The story begins a little over a month ago. It was my birthday, there was a BBQ in the park, there were water balloons, and I had my iPhone in my pocket (super dumb in retrospect). When I got home I noticed that my clothes were quite damp, although the phone was relatively dry, so I thought little of it. Later that evening I played around with it and noticed the home button was not responding. Thinking that a little bit of moisture must have found its way inside the button, I switched it off for the night and left it alone (what I should have done is put it in a container of rice).

The home button was stuffed. No matter what I did, the home button would not work. I tried restoring. I tried pressing hard and pressing soft. I tried fiddling around with the button in case it was stuck. I started to get that sinking feeling in my stomach that a birthday afternoon of horsing around had fatally damaged my pride and joy.

I waited a week for the break of following weekend and took it to the geneses at the Chadstone apple store. I had recently jailbroken the phone, so I restored the device using iTunes back to a virgin state for the trip - this step also retrospectively was a poor move. The dude listened to my 'it doesn't work' story, inspected the water exposure indicators on the top and bottom of the device and said 'you have exposed it to water, we can't touch it'. Now, I concede that the home button must have got some moisture in there, although the damn phone was far from immersed! At most it would have been as much as few drops of rain if I were to use it briefly during bad weather. I pushed the point and the dude said that officially the water indicators were not completely triggered, the top was clear and the bottom indicator was partially indicating water exposure. I could have scraped the indicator and gone back on another day to try again - this retrospectively would have been worth a shot.

A new iPhone. Almost 2 months of use. Next to useless given fragile electronics, and apple tells me I'm on my own. I was a little sad at this point. I accepted the situation, more specifically my causal role, and optimistically began researching the next step: third party repair.

I researched the general class of problem from two perspectives: water damaged iPhone and broken home button. I read lots of similar problems and questions on iPhone related forums including a most impressive successful iPhone resurrection saga that involved (among other things) baking the phone in the oven!

I researched the components that I may need to replace and their prices: home button, flex cable assembly, etc. I also collected a long list of local third party iPhone repair stores and got quotes for fixing the general problem (in the order of $60 to $80 AUD for a home button replacement).

I picked a guy and dropped off the phone. Unfortunately, replacing the home button did not fix the problem. My guy deduced that it must be the flex cable assembly that the home button interfaces. He ordered an assembly from China, and I waited a number of weeks. The part finally arrived, although swapping out the flex cable assembly and the home button did not fix the problem. My guy deduced that the problem is likely the main board, and the cost would be close to half the value of a new phone. At this point I put a halt to the experiment, and took the device back. Fortunately, my guys policy is 'no fix, no pay', although unfortunately upon receiving the handset back the speaker no longer works and the screen no longer sits snug in the case. I plan on re-visiting my guy soon to resolve these issues, hoping that the speaker issue is simply a matter of a loose connection, and the screen can be reset in the case better than it was.

My fall back position was to use the device without a working home button, and use a software solution to close apps. I mean, the only thing the button is for is to close apps. That is what I thought until I went to re-jailbreak the phone so that I could install said software. The finally nail in the coffin is that I cannot re-install a jailbroken firmware on the device because I cannot enter DFU mode, a step needed in the quickpwn jailbreaking process. There was a way to get into DFU mode without a home button using software and hints of alternative jailbreaking software (ZiPhone or iLIBERTY) that may operate this way, but thus far these have not offered a viable path. Therefore: No home button, no DFU mode, no jailbreaking, and thus a bricked iPhone.

Options have eroded and my thoughts have settled on the following for my iPhone finale:

  1. Continuing to use the iPhone as is. Maybe a software based DFU mode will come along allowing me to jailbreak and install a software based home button solution (Bossprefs or something). I might be able to install an older firmware and then use a software DFU mode solution. The phone would be a constant reminder of the penalty of not being careful enough with edge technology. The down side is that until a home button solution is found, I have to turn the phone off and on any time I want to change applications, which is VERY ANNOYING!
  2. Selling the iPhone. I am seriously considering selling the lot for parts on eBay and forking out the cash for either a brand new/secondhand iPhone or more likely a G1 (or equivalent) Android based phone.
  3. Rebuild from Parts. A third and final option may be to buy another broken phone from eBay - one with a broken screen (my screen is fine) and give them both to an iPhone repair guy to construct a viable phone. Slim chance of a payoff, although cheaper than a new phone.
My iPhone situation is dire, and I've had it locked in a draw for the last few weeks so that I didn't have to address it directly (also I was out of the country on business). It is time for me to move on I think, to bury my fallen comrade. Moving to a new (albeit less aesthetic) phone platform seems attractive at this glum point in time.