This form does not yet contain any fields.
    « 5 Reasons why to switch to Git | Main | Augmented Reality Toolkit for the iPhone on GitHub »
    Saturday
    16Jan2010

    Progress made to the Augmented Reality Toolkit. Now a static library!

    Today we're please to announce that we've updated the source code on Github.  The latest set of changes made this week fixes  the orientation issue that's been driving me nuts.

    A Static Library - Finally!

    The project now has the core of the toolkit put into a static library.  Why is this important? In the future when this project has matured, it will allow anyone to add the library to their projects.

    We've still have a long way to go. One of the changes we want to have is the ability for any type of view to be added to augmented Reality layer.

    Orientation works in both landscape and portrait modes

    Woot! We finally got this one piece of code figured out.  It really came down to some simple math.  When the orientation of the phone changes, we need to adjust the azimuth.  We also fixed a stupid mistake where we were checking the same orientation direction instead of checking the left AND right.

    The final a-ha moment came in the determining the angle of the phone to know where to draw the y position of a view.

       1:  switch (currentOrientation) {
       2:    case UIDeviceOrientationLandscapeLeft:
       3:       viewAngle = atan2(acceleration.x, acceleration.z);
       4:       break;
       5:   
       6:    case UIDeviceOrientationLandscapeRight:
       7:       viewAngle = atan2(-acceleration.x, acceleration.z);
       8:       break;
       9:   
      10:    case UIDeviceOrientationPortrait:
      11:       viewAngle = atan2(acceleration.y, acceleration.z);
      12:       break;
      13:   
      14:    case UIDeviceOrientationPortraitUpsideDown:
      15:       viewAngle = atan2(-acceleration.y, acceleration.z);
      16:       break;
      17:   
      18:    default:
      19:       break;
      20:  }
    As you can see, determining the angle we need to use the y acceleration in portrait mode and the x acceleration in landscape mode.  However, there was one more thing we had to do to make sure the functionality behaved the same way, regardless of the orientation.  We needed to adjust the  x value as negative when the iPhone is in Landscape Right and the y value when the iPhone is upside down. (Not sure why one would do it upside down but we added the functionality anyways!)

    Scaling issue resolved!

    We finally go the scaling of the views working now too! The funny thing all we had to do was uncomment out the code we had commented out before and it started working.  The problem was solved by another bug we fixed a while back but forgot to uncomment the block code that was scaling the views down to nothing.

    What's next?

    Now that we have the bare minimum working now by simplifying the code and getting it to work for all orientations and adding it to a static library, we can now get to the fun part.  Making it into a real toolkit.  
    I don't recommend forking the project just yet because I still see a ton of refactoring that will go on from the project we forked from to get it to an acceptable toolkit.  My big projects are slowing down a bit right now so I feel I can spend a little more on this project than I had the first couple of weeks of the year.
    Stay tuned. The best is yet to come!

    PrintView Printer Friendly Version

    EmailEmail Article to Friend

    Reader Comments (7)

    Hello,

    I love this project. It works nice, please keep on going becuase it is great.

    I would like to ask you one thing.. it is possible to do not use the window object, instead use a View Controller. I woul like to use the static library on a Tab Bar app.. I'm very new on iphone development so I'm still learning, maybe I'm asking something very silly...

    thank you!

    January 22, 2010 | Unregistered Commenterdavid

    This was the first thing we changed. Make sure you grab the latest code base. We have a static library started but its not under the master branch. You need to switch over to the static library branch.

    I'm glad you like it so far. Let us know if there is anything you'd like to see us add to it.

    January 22, 2010 | Registered CommenterNiels Hansen

    yes, you're right, I've grab the latest code, and I have the static library started.. I know that is me (im a real beginner on this), I can't see the view on a tabBar app. I see how it works in the console but the view is not showing..

    Maybe I'm loosing something.. here is what I'm doing:

    I create a new UIViewController SubClass; then I import ARViewContrller.h and Geolocations.h, then on viewDidLoad. I alloc and init an ARViewController like this :


    - (void)viewDidLoad {

    ARViewController *viewController = [[ARViewController alloc] init];
    [viewController view];

    [super viewDidLoad];
    }

    Whe I run the app I change to view whitout any errors and on console I see :

    2010-01-25 14:18:02.647 pruebas2[2836:207] distance is 895289773, angle is 1094049360, azimuth is 0
    2010-01-25 14:18:02.648 pruebas2[2836:207] distance is -137817117, angle is 1093390979, azimuth is 0
    2010-01-25 14:18:02.648 pruebas2[2836:207] distance is 1014173419, angle is 1095148584, azimuth is 0
    2010-01-25 14:18:02.648 pruebas2[2836:207] distance is -2135402882, angle is 1094848403, azimuth is 0

    but the view is blank; I can't see the camera image or position targets.

    thank you anyway... I need to learn more... I know, and this is helping me a lot.

    January 25, 2010 | Unregistered Commenterdavid

    please discard my last comment, I saw that you have update the branch with new examples on how to work with the viewController.. so I will first to understand how, and then ask...

    thank you!

    January 25, 2010 | Unregistered Commenterdavid

    Ok, actually it works nice but I can't see the camera on the background:


    - (IBAction)pinchaAR
    {
    MapaAR *mapaAR = [[MapaAR alloc] init];
    [self.view addSubview: [mapaAR view]];
    }

    I see all the elements moving arround but the camera is not initializing.. this is an issue or is something that I'm doing wrong?
    If I try to init on the beginnig of the app and not on a viewDidLoad it works.

    January 26, 2010 | Unregistered Commenterdavid

    Have you tried it with the sample demo first without adding it to your own app to verify that it's running? I'm in the process of making additional changes to the library so that it can load in any size View controller. This should be released in the next couple of days. Please confirm that you're able to get the demo working.

    January 26, 2010 | Registered CommenterNiels Hansen

    yes demo is working perfect... I whant to see if a have a problem in my program so I try to create something from scratch so I create a new Tab Bar application, and if you init the library on root you have no problems, but this means that the camera is runnig from init and on all tabs (you need to hide the view if you want to see the camera on an specified tab)

    January 28, 2010 | Unregistered Commenterdavid

    PostPost a New Comment

    Enter your information below to add a new comment.

    My response is on my own website »
    Author Email (optional):
    Author URL (optional):
    Post:
     
    Some HTML allowed: <a href="" title=""> <abbr title=""> <acronym title=""> <b> <blockquote cite=""> <code> <em> <i> <strike> <strong>