pushplay

interactive · design · studio


< Back to Main

Locating an iPhone in 3D space

September 2, 2009
|

A world of augmented reality possibilities were opened up once the capability to superimpose graphics over the camera display was made available by Apple. One of my initial game ideas required this functionality, but it's been a case of "wait for a tutorial to show how to do this and miss the boat" versus "spend a lot of time working on inventing new functionality instead of doing other things that you really should be working on". Obviously, I would prefer to do the latter over the former...

One caveat: right now, I do not have a working solution. The following is a description of what I'm working through to solve this problem - and any advice would be greatly appreciated!

Game concept

My game idea didn't involve technology as much as a concept of what I wanted the players to "feel" when they played it - the sort of fully immersive game where you feel like you are "in" the game world, and you have physical reactions (heart pounding, adrenaline spiking) like you would if it was real life. This meant that the game would have to involve the use of the space around you, in order to psychologically simulate the idea of fear and accomplishment. The example I came up with was a simple "ghost hunter" game - very similar in concept to the way Ghostbusters trapped ghosts - crossed with the real-life apprehension you have playing Laser tag or paintball.

One player would start a game (similar to starting a game in a multiplayer shooter like Quake or Unreal Tournament). This would create a series of enemies located somewhere in 3D space around them, which they'd have to avoid, as well as capture and trap. Other players would then be able to "join" their game (via peer-to-peer networking), in which case they'd see the enemies in the same exact physical 3D locations, but adjusted relative to the 3D location of their phones.

The following image shows how two iPhones (or iPod Touches) would view an object (the green cube).

multiple iphones in 3D space

Each iPhone has its own viewing angle and would see the object as located in the same physical space, but they would display it relative to their own position. For example, the iPhones listed above would show the following screens:

view from perspective of first iPhone view from perspective of second iPhone

The gameplay would involve locating and then choosing to "capture" a ghost - but two or more players would be required to lock on in order to capture a ghost. However, if a ghost intersects with the 3D space located by a device, it would "kill" the device - basically booting them out of the game. In my mind, that would create a situation with people ducking and bobbing around trying to get away from a "ghost" that seems to be following them in real life...and it would give the feeling of a real ephemeral entity that you can't see - but is right in front of you. The blurring of what is real and what is virtual (making it seem that the iPhone is acting like an infrared camera for ghosts) would have a really creepy effect, and would be perfect for a horror-style game (especially when you add intense graphics, things moving and tracking you, objects given 20% alpha blends so they merge with the background, etc.)

Augmented Reality Implementation in 3D Space

In order to implement this game, I need to be able to locate a device in 3D space, and display an object relative to the device itself.

cube view of iPhone in 3D space with annotations for use in augmented reality

Let's start with the easy part. Latitude and longitude are given through the CLLocationManager (for the device's location), and CLLocation:getDistanceFrom: to measure the distance between the current location and the location of any other objects.

We also need to know where the device is pointed (there is a different view when you're facing forward versus facing backward). The magnetometer will give us the compass direction, which we can use to adjust where other objects are in 3D space.

We still have two more things we need to know where we are in 3D space. One is the vertical viewing angle (the viewing area will be different if we're pointed at the ceiling, versus pointed at the floor). I was planning on using the accelerometer to help me figure out this angle based on default values (either perfectly horizontal (parallel to the floor) or perpendicular to the floor).

diagram showing three iPhone viewing angles

The one final variable that I need (and the one I don't think I can get) is the height of the iPhone from the floor. From what I've seen, other iPhone augmented reality applications ignore this, and assume a fixed distance from the floor (for argument's sake, let's arbitrarily call it 1 meter). The problem with this is that I wouldn't be able to have ghosts hide up by the ceiling or down on the floor - everything would effectively be in the same plane view, which means simple rotating 360 degrees would show the full game area (and would greatly decrease the difficulty, challenge, and intensity of the game).

As much as I don't like posting problems without solutions, this is a problem that I've been playing with for the past few months and I didn't want to sit on it any longer. If you have any suggestions for what I should do, please post them in the comments!

4 Comments

04 Sep
2009
Alex
I think you might not need to worry about the iPhone height. Most players are going to be standing, holding the iPhone in front of them, pointing it towards either the horizon, ceiling or floor (all of which you can determine). Your "ghosts" don't have to be in one plane, but you can assume your users are (most will be within a 1-2 foot range, about 5ft off the ground). Your users are unlikely to be at ceiling or floor level, so you can safely draw objects as if they were without worrying too much about how "high" your user is.

The real problem I think you're going to run into is the latitude and longitude to determine location - I don't think it's accurate or fast enough to handle a bunch of people running around in a room, especially indoors where it is even less accurate. With current AR apps, you have to sit and wait for your location to be determined, and I don't think it updates in real time as you walk a few feet.
04 Sep
2009
Jeffrey Berthiaume
Hi, Alex:

The problem with height is related to gameplay -- I want people to be squatting and looking down at the ground (like with a magnifying glass) or holding the device over their head pointed at the ceiling. The problem with the Yelp AR application (that we looked at yesterday) is that no matter what angle the phone is facing, their overlays are always in the center of the screen...
04 Sep
2009
Adam
Nice, post. I been working with AR too recently. I agree with Alex that a big problem is still CLLocation. It only really works in certain locations outside, and works best when an object is over 5-10m away from you. Once you get closer then that to an objects location it starts to get ridiculously inaccurate about where that object is relative to you. Also it starts to get really inaccurate when you're moving faster then a slow walking pace.

What you describe is really the best practice i've found of going about this with the tools that are available however, until Apple gives us more to work with, applications like this are going to be really hard if not impossible to implement.

If you come up with a solution though, I'd love to see it.
27 Oct
2009
Mark
Jeffrey, very nice idea and post.

I too am struggling with the same problem as you so can't really offer you a solution as such.

I am attempting to use similar technology to the iPhone (accelerometer, magnetometer, GPS) in a sports watch to accurately track height. After 3 months I haven't been able to do it.

GPS as you mentioned in a post on another site is not accurate for height, I have a calibration button but that doesn't help, it's simply not accurate enough. I need < 50cm accuracy.

I tried using an air sensor - not accurate.

So then going back to the same base hardware as you are using in the iPhone I tried to see if maths could solve it by using constantly updating live data from the accelerometer for orientation, magnetometer for direction, angle sensor for angle and GPS for speed it is possible it is possible to work out the distance travelled on a certain angle at a certain speed and thus calculate height.

I know the above is doable, unfortunately I haven't the maths brain or knowledge to be able to program it correctly so at this point in time the project is on hold.

Not sure if that suggestion will help you or not. Let me know if it does.

Let me know if you've already succeeded as I would love to see it working and hear how you did it.

Submit a Comment:

Your Name:
Email Address:
Comments:
Enter what you see: Verification Image