iPhone 3D Renderer

Friday, June 13, 2008
send this post to a friend
iPhone SimulatorProgress on porting Phit to the iPhone has moved quickly this week.

On Wednesday I set out to port my 3D renderer from Windows to the iPhone. This is a renderer I've maintained for several years and which I use in teaching 3D rendering for games at the Guildhall. (A renderer is a piece of software that displays 3D objects on the screen.)

Porting the renderer proved much easier than I expected. Now I can load and display 3D models—like this one from Unreal Tournament 2004—on the iPhone simulator.

I was surprised that the renderer ported over so well. It was written for the PC. On the PC it supports both Direct3D and OpenGL—I stripped out the Direct3D portion. It is quite a large piece of code, with about 40 files or so and maybe 15,000 lines of code. I've only ever compiled it with Visual Studio, and the gcc compiler used for iPhone is substantially different.

I thought the biggest hurdle would come from the fact that the iPhone framework is written in Objective-C, whereas my renderer is all C++. As it turns out, Objective-C files that have the extension .mm happily coexist in both worlds: they can call C++ object member functions as well as Objective-C object methods. So I wrote one or two Objective-C classes to interact with the iPhone OS and framework. I have my two dozen or so C++ classes that make up the engine. And then I have three or four "adapter" classes in .mm files that help my C++ classes talk to the iPhone OS.

I tried to get an iPhone this week to test the code on. (The iPhone Simulator on the Mac tells you nothing about how your code will actually perform on the iPhone. Presumably the iPhone will run quite a bit slower for complex 3D scenes.) Unfortunately, with the June 9th announcement of the new iPhone, nobody is selling iPhones anymore. So I got an iPod Touch instead. But I'm still having to wait because Apple hasn't gotten us our Developer certificate yet. You need that to make your iPhone/iPod Touch into a development device.

So on the one hand I'm learning the iPhone SDK. On the other hand I'm working on Phit, upgrading it for life on the iPhone.

Specifically, I wanted to improve the way the pieces move in Phit, making them smoother and more natural. The iPhone sets a high standard for user interface "feel", and I want iPhit to meet or exceed that standard.

So I'm creating a new physics system for iPhit. It uses Verlet integration to move and constrain pieces, and features a sophisticated collision detection system so that pieces can "stack" and won't pass through each other. The implementation I have now seems to work very reliably, but is slower than I'd like. Still, it begins to give an idea of iPhit might feel on the iPhone. Feel free to try out the new physics and let me know what you think.



Labels: , , , ,


Comments

Something else the iPhone can do: http://blog.wired.com/defense/2008/06/video-iphone-co.html
 
Wow. I can just see the headlines: "iPhone Oversees Destruction of Sadr City."
 




<< Home
©Copyright 2002–2007 Jeff Wofford