<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>musicalgeometry &#187; AR</title>
	<atom:link href="http://www.musicalgeometry.com/archives/category/ar/feed" rel="self" type="application/rss+xml" />
	<link>http://www.musicalgeometry.com</link>
	<description>sound, code, &#38; DIY tech</description>
	<lastBuildDate>Sat, 24 Jul 2010 16:32:17 +0000</lastBuildDate>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
	<generator>http://wordpress.org/?v=3.0</generator>
		<item>
		<title>iPhone Camera Overlay App With Custom Button Example</title>
		<link>http://www.musicalgeometry.com/archives/821</link>
		<comments>http://www.musicalgeometry.com/archives/821#comments</comments>
		<pubDate>Fri, 11 Dec 2009 05:26:37 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[XCode]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[code]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=821</guid>
		<description><![CDATA[There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or &#8230; <a href="http://www.musicalgeometry.com/archives/821">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p>There seems to be a lot of interest recently in making apps that use a camera view with an overlay for augmented reality or what some might call pseudo-augmented reality applications (because often these apps just layer an image or data on a camera view). I wasn&#8217;t satisfied with the few examples I found on the topic so I decided to try one myself. I will endeavour to make it as clear as I can and show you how to make a custom button while I am at it, but I do assume a basic knowledge of Objective-C and iPhone app development in Xcode.</p>
<div id="attachment_823" class="wp-caption alignnone" style="width: 210px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38.png"><img class="size-medium wp-image-823 " style="border: 1px solid black;" title="Screenshot 2009.12.10 18.46.38" src="http://www.musicalgeometry.com/wp-content/uploads/2009/12/Screenshot-2009.12.10-18.46.38-200x300.png" alt="OverlayViewTester screenshot" width="200" height="300" /></a><p class="wp-caption-text">OverlayViewTester screenshot</p></div>
<p>So first I will describe the OverlayViewTester app. Basically it just overlays some cool looking red selection braces on a camera view and has a button that when pressed performs a &#8216;scan&#8217; for two seconds and lets you know by adding a &#8220;Scanning&#8230;&#8221; label at the top of the screen during that time. So really it does nothing, but it looks good and is a good first step to making a more fun and interesting interactive camera overlay app.</p>
<p>To get started download the source code from <a href="http://github.com/jj0b/OverlayViewTester">GitHub</a>. Next I will go through the files in the project and present the juicy bits. Consult the source code you downloaded for the full meal deal.</p>
<p><strong>OverlayViewTesterApDelegate</strong></p>
<p>Taking a look at the project we start with a typical app delegate, OverlayViewTesterAppDelegate which loads the OverlayViewController. Nothing monumental there so I won&#8217;t bother reproducing it here.</p>
<p><strong>OverlayViewController</strong></p>
<p>Now on to the OverlayViewController where we create the camera view.</p>
<p>In the interface, <em>OverlayViewController.h</em>: we define some constants:</p>
<pre><code>// Transform values for full screen support:
#define CAMERA_TRANSFORM_X 1
#define CAMERA_TRANSFORM_Y 1.12412

// iPhone screen dimensions:
#define SCREEN_WIDTH  320
#define SCREEN_HEIGTH 480</code></pre>
<p>In the implementation, <em>OverlayViewController.m</em> there is a bit of a GOTCHA. The line</p>
<pre><code>[self presentModalViewController:picker animated:YES];</code></pre>
<p>must be called in  <em>viewDidAppear:</em> not in a <em>viewDidLoad:</em> method. Here it is:</p>
<pre><code>- (void) viewDidAppear:(BOOL)animated {
    OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];

    // Create a new image picker instance:
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];

    // Set the image picker source:
    picker.sourceType = UIImagePickerControllerSourceTypeCamera;

    // Hide the controls:
    picker.showsCameraControls = NO;
    picker.navigationBarHidden = YES;

    // Make camera view full screen:
    picker.wantsFullScreenLayout = YES;
    picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);

    // Insert the overlay:
    picker.cameraOverlayView = overlay;

    // Show the picker:
    [self presentModalViewController:picker animated:YES];
    [picker release];

    [super viewDidAppear:YES];
}</code></pre>
<p>I think the comments make it clear what is going on there.</p>
<p><strong>OverlayView</strong></p>
<p>Next lets look at the custom subclass of UIView called OverlayView. This is where we actually create our overlay.</p>
<p>In the interface, <em>OverlayView.h</em> we declare two new methods:</p>
<pre><code>- (void)scanButtonTouchUpInside;
- (void)clearLabel:(UILabel *)label;</code></pre>
<p>Here are the important parts of the implementation, <em>OverlayView.m</em>:</p>
<pre><code>- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
        // Clear the background of the overlay:
	self.opaque = NO;
	self.backgroundColor = [UIColor clearColor];

	// Load the image to show in the overlay:
	UIImage *overlayGraphic = [UIImage imageNamed:@"overlaygraphic.png"];
	UIImageView *overlayGraphicView = [[UIImageView alloc] initWithImage:overlayGraphic];
	overlayGraphicView.frame = CGRectMake(30, 100, 260, 200);
	[self addSubview:overlayGraphicView];
	[overlayGraphicView release];

	ScanButton *scanButton = [[ScanButton alloc] initWithFrame:CGRectMake(130, 320, 60, 30)];

	// Add a target action for the button:
	[scanButton addTarget:self action:@selector(scanButtonTouchUpInside) forControlEvents:UIControlEventTouchUpInside];
	[self addSubview:scanButton];
    }
    return self;
}

- (void) scanButtonTouchUpInside {
    UILabel *scanningLabel = [[UILabel alloc] initWithFrame:CGRectMake(100, 50, 120, 30)];
    scanningLabel.backgroundColor = [UIColor clearColor];
    scanningLabel.font = [UIFont fontWithName:@"Courier" size: 18.0];
    scanningLabel.textColor = [UIColor redColor];
    scanningLabel.text = @"Scanning...";

    [self addSubview:scanningLabel];

    [self performSelector:@selector(clearLabel:) withObject:scanningLabel afterDelay:2];

    [scanningLabel release];
}

- (void)clearLabel:(UILabel *)label {
    label.text = @"";
}</code></pre>
<p>Notice that we have used an instance of ScanButton which we will get to next. When the ScanButton detects a UIControlEventTouchUpInside it calls the scanButtonTouchUpInside method which places a label on the screen for 2 seconds.</p>
<p><strong>ScanButton</strong></p>
<p>So finally we are left with our ScanButton. You might think that for a custom button we would subclass UIButton, but unless you really want to use the UIBUtton method setTitle:ForState it is recommended that you subclass UIControl. It will save you a world of hurt.</p>
<p>Here is the interface, <em>ScanButton.h</em>:</p>
<pre><code>#import &lt;Foundation/Foundation.h&gt;

@interface ScanButton : UIControl {
}

- (void)buttonPressed;

@end</code></pre>
<p>I put the buttonPressed method in here for future use. It is meant to be used to change things related to the button itself and not the actions associated with the button in the OverlayViewController. You could for example use it to have the button&#8217;s image or state or both toggle.</p>
<p>Last but not least we have the implementation, <em>ScanButton.m</em>:</p>
<pre><code>#import "ScanButton.h"

@implementation ScanButton

- (id)initWithFrame:(CGRect)frame {
    if (self = [super initWithFrame:frame]) {
	// Set button image:
	UIImageView *buttonImage = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 60, 30)];
	buttonImage.image = [UIImage imageNamed:@"scanbutton.png"];

	[self addTarget:self action:@selector(buttonPressed) forControlEvents:UIControlEventTouchUpInside]; // for future use

        [self addSubview:buttonImage];
    }
    return self;
}

- (void)buttonPressed {
    // TODO: Could toggle a button state and/or image
}

@end</code></pre>
<p>So there you have it. A custom camera overlay and a custom button. I hope that with this code you will be well on your way to writing much more useful, interesting and creative apps than this example. Happy coding!</p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/821/feed</wfw:commentRss>
		<slash:comments>17</slash:comments>
		</item>
		<item>
		<title>iWasHere iPhone App Free For A Limited Time</title>
		<link>http://www.musicalgeometry.com/archives/638</link>
		<comments>http://www.musicalgeometry.com/archives/638#comments</comments>
		<pubDate>Wed, 26 Aug 2009 16:29:54 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=638</guid>
		<description><![CDATA[I have made my iPhone app iWasHere free for a limited time to encourage more users to start creating networks with their friends. Augment your reality with iWasHere! iWasHere is a geo-locational social networking message board. iWasHere allows you to &#8230; <a href="http://www.musicalgeometry.com/archives/638">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere.jpg"><img style="border: 0px initial initial;" title="iwashere" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere-50x50.jpg" alt="iwashere" width="50" height="50" /></a></p>
<p>I have made my iPhone app <a href="http://www.musicalgeometry.com/iwashere">iWasHere</a> free for a limited time to encourage more users to start creating networks with their friends.</p>
<div id="attachment_455" class="wp-caption alignnone" style="width: 218px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/addview1.jpg"><img class="size-medium wp-image-455" title="addview" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/addview1-208x300.jpg" alt="Creating a new network" width="208" height="300" /></a><p class="wp-caption-text">Creating a new network</p></div>
<p>Augment your reality with iWasHere!</p>
<p>iWasHere is a geo-locational social networking message board. iWasHere allows you to create an augmented reality by enabling you to leave a message at a specific location which can then only be read at that location. You can write to a Public network that is readable and writable by everyone, or you can create your own private networks for just you and your friends.</p>
<p>Use iWasHere to leave a note for a friend at a bus stop, outside their work or in a park. Read or write reviews of stores and restaurants right outside their doors. Make a virtual community message board in your neighborhood. Hide directions to a secret party or a surprise proposal. Create a treasure hunt that uses virtual clues or do virtual geocaching. iWasHere can be whatever you want it to be. The only limit is your imagination!</p>
<p>Get it while it is free!</p>
<p><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8"><img style="border: 0px initial initial;" title="marketing_badge" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/marketing_badge.png" alt="marketing_badge" width="121" height="41" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/638/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
		<item>
		<title>iWasHere Now Available On The App Store</title>
		<link>http://www.musicalgeometry.com/archives/582</link>
		<comments>http://www.musicalgeometry.com/archives/582#comments</comments>
		<pubDate>Thu, 13 Aug 2009 20:54:21 +0000</pubDate>
		<dc:creator>Jason Job</dc:creator>
				<category><![CDATA[AR]]></category>
		<category><![CDATA[app]]></category>
		<category><![CDATA[iPhone]]></category>

		<guid isPermaLink="false">http://www.musicalgeometry.com/?p=582</guid>
		<description><![CDATA[Augment your reality with iWasHere! After a long wait my geo-locational social networking message board iPhone app iWasHere is finally available for purchase on the App Store. iWasHere is a geo-locational social networking message board. iWasHere allows you to create &#8230; <a href="http://www.musicalgeometry.com/archives/582">Continue reading <span class="meta-nav">&#8594;</span></a>]]></description>
			<content:encoded><![CDATA[<p><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere.jpg"><img class="size-thumbnail wp-image-451 alignnone" title="iwashere" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/iwashere-50x50.jpg" alt="iwashere" width="50" height="50" /></a></p>
<p>Augment your reality with iWasHere!</p>
<p>After a long wait my geo-locational social networking message board iPhone app <a href="http://www.musicalgeometry.com/iwashere">iWasHere</a> is finally available for purchase on the <a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8">App Store</a>.</p>
<div id="attachment_461" class="wp-caption alignnone" style="width: 218px"><a href="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewview.jpg"><img class="size-medium wp-image-461 " style="border: 1px solid black;" title="viewview" src="http://www.musicalgeometry.com/wp-content/uploads/2009/07/viewview-208x300.jpg" alt="iWasHere view page" width="208" height="300" /></a><p class="wp-caption-text">iWasHere iPhone app</p></div>
<p>iWasHere is a geo-locational social networking message board. iWasHere allows you to create an augmented reality by enabling you to leave a message at a specific location which can then only be read at that location. You can write to a Public network that is readable and writable by everyone, or you can create your own private networks for just you and your friends.</p>
<p>Use iWasHere to leave a note for a friend at a bus stop,  outside their work or in a park. Read or write reviews of stores and restaurants right outside their doors. Make a virtual community message board in your neighborhood. Hide directions to a secret party or a surprise proposal. Create a treasure hunt that uses virtual clues or do virtual geocaching. iWasHere can be whatever you want it to be. The only limit is your imagination!</p>
<p><a href="http://itunes.apple.com/WebObjects/MZStore.woa/wa/viewSoftware?id=323502725&amp;mt=8"><img style="border: 0px initial initial;" title="marketing_badge" src="http://www.musicalgeometry.com/wp-content/uploads/2009/08/marketing_badge.png" alt="marketing_badge" width="121" height="41" /></a></p>
]]></content:encoded>
			<wfw:commentRss>http://www.musicalgeometry.com/archives/582/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
