Saturday, January 16, 2010 at 5:35PM Progress made to the Augmented Reality Toolkit. Now a static library!
augmented reality,
github,
iPhone |
Niels Hansen 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: }

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!
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.
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.
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!
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.
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.
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)
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?
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.
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?
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!
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;
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?
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!
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 ;)
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!
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!
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.
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!
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