« 5 Reasons why to switch to Git | Main | Augmented Reality Toolkit for the iPhone on GitHub »
Saturday
Jan162010

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 (50)

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

I see a memory leak everytime a tempCoordinate is allocated

e.g on the line

tempCoordinate = [ARGeoCoordinate coordinateWithLocation:tempLocation locationTitle:@"Denver"];

Is anybody else seing this? Is there a fix?

October 21, 2010 | Unregistered CommenterJohn Callaghan

Hi Niels, I am very happy to see product. I am also new in AR word but learning in fast pace. I have downloaded the ARKitDemo and tested it. I was wondering why it displays only particular map points every time? Are they hard coded somewhere? Also is it possible to add functionality like search for nearest railway station(around 1-2 miles) which displays the railway station name, station image etc. Same thing is possible for other things like bus station, bar, hospitals etc. If it is not supported then can you give me your thoughts how can we add it. What could be the best way to learn the ARKit code? I would be happy to contribute to ARKit and make these changes.

Thanks.

February 3, 2011 | Unregistered CommenterRaj

Hello! Love this, I'm using it in my new app which is going to be up in the app store in about 1 month or so.

I was just wondering, I want to add click/touch-events on the pointView/titleLabel.

Is this something that's coming up in the next version of this wonderful toolkit?

August 22, 2011 | Unregistered CommenterPeter

You can add gesture recognizer to the CoordinateView and have a method to push required controller view on top of ARViewController. I did similar stuff in one of my past project!

Cheers!

August 22, 2011 | Unregistered CommenterRaj

Thanks Raj!

But if I want to know which object in the array that shows in the ARViewController the user clicked on, how can I do that? I can't receive a sender from the gesture recognizer?

The callback looks like this:

- (void)handleSingleTap:(UITapGestureRecognizer *)recognizer;

August 22, 2011 | Unregistered CommenterPeter

The code I'm using to register the tap in the initForCoordinate-method in CoordinateView is:

[self setUserInteractionEnabled: YES];

UITapGestureRecognizer *tap =
[[UITapGestureRecognizer alloc] initWithTarget: self
action: @selector(handleSingleTap:)];
[tap setNumberOfTapsRequired:1];
[self addGestureRecognizer: tap];
[tap release];

But this doesn't seem to work. The tap never reaches the callback-method... How did you solve this Raj?

August 22, 2011 | Unregistered CommenterPeter

To answer your formar question, you can have unique property(may be viewcontroller name?) set in new variable in coordinateview and use it to recognize what to do?

For later question, I had the similar issue. You will need to transfer gesture event from your ARViewController to ARKit AugmentedRealityController! You can do it using:

- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
[self.agController touchesBegan:touches withEvent:event]; // agcontroller is the instance of ARKit AugmentedRealityController
}

- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
[self.agController touchesMoved:touches withEvent:event];
}


- (void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
[self.agController touchesEnded:touches withEvent:event];
}

in AugmentedRealityController.m,


- (void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
// do your stuff
}

For you events will be different, I have given examples for what I have used!

August 22, 2011 | Unregistered CommenterRaj

Thank you for your kind response, Raj.

The problem now is that you can tap all over the screen and the touch-event will execute. I want the touch event to execute when you click on a certain CoordinateView on the screen. For example if you see five of the McDonalds restaurants on the AR screen, and you click on one of them, the touch should react, but not if you click in the other area. Only on the CoordinateViews so to speak.

Sorry if i'm unclear here, but Swedish is my first language ;)

August 22, 2011 | Unregistered CommenterPeter

it will happen if you use my code dito! I had such requirements of moving points up and down so user can drag view points up and down by scrolling screen anywhere! For your requirements, you will need to add gasture recognizer for coordinateview object not augmented reality controller. Sorry but I can't spend more time on this writting code!

August 22, 2011 | Unregistered CommenterRaj

I'm basically wondering the same thing as Peter. In my CoordinateView init method I've changed the UILabel to a UIButton:


UIButton *btn = [[UIButton alloc] initWithFrame:CGRectMake(0, 0, BOX_WIDTH, 20)];
[btn setBackgroundColor: [UIColor orangeColor]];
[btn setTitle:@"Click Me!" forState:UIControlStateNormal];
[btn addTarget: self action:@selector(hej) forControlEvents:UIControlEventTouchDown];

[btn setFrame: CGRectMake(BOX_WIDTH / 2.0 - [btn bounds].size.width / 2.0 - 4.0, 0, [btn bounds].size.width + 8.0, [btn bounds].size.height + 8.0)];

But the button doesn't respond when I click on it. I don't know why. My CoordinateView has setUserInteractionEnabled: YES.

Could it be the view hierarchy? And in that case, how can I make my button respond?


Thanks for a great library by the way! I absolutely love it!

September 9, 2011 | Unregistered CommenterPeter

HI everyone,

I'd like to thank Raj for answering all the questions hear on the post. I would love to get back into working on the AR Kit. I've been super busy with other projects the last 6 months that I've not had enough free time to work on it. However it's something I want to start doing again.

If there are changes that everyone has made and would like to merge it into the main branch, let me know and we can see what we can do to get that in.

September 9, 2011 | Registered CommenterNiels Hansen

Hi Niels!

You don't know the answer on my question I posted before your answer? Because you've worked on the library before?

It would be so much appreciated!

Have a great weekend!

September 10, 2011 | Unregistered CommenterPeter

Hi Neils, I have created this issue - https://github.com/nielswh/iPhone-AR-Toolkit/issues/5#issuecomment-2058613 also made the changes. Let me know how can I merge it? I would love to contribute!

Raj

September 10, 2011 | Unregistered CommenterRaj

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>