Marker to Markerless iOS

From Kudan AR Engine
Jump to: navigation, search

This tutorial will lead on from our previous tutorial which described how to add content to a marker. If you have not already set up a project where you place content onto a marker, we suggest you check it out first before heading any further. This tutorial will show you transfer a model that has been added to an image trackable to ArbiTrack.

For this sample we have used:

  • Marker : spaceMarker.jpg
  • Model : ben.armodel / ben.jet
  • Model Texture : bigBenTexture.png

Which can all be downloaded here.

Initial Setup

Before you start you will need to first create an image trackable using the spaceMarker image, then create a model and add it to the image trackable using the Big Ben armodel and texture.

ArbiTrack Setup

You will need to set your view controller/activity to be a ArbiTrack delegate/listener. This will later call a delegate function when ArbiTrack has been started and has collected its initial values.

// Initialise ArbiTrack
ARArbiTrackerManager *arbiTrack = [ARArbiTrackerManager getInstance];
[arbiTrack initialise];
 
//Add view controller as an ArbiTrack delegate
[arbiTrack addDelegate:self];

Create Target Node

When using ArbiTrack the model will be placed on top of the target node. As we are using a marker for placement instead of using the gyro we will be using an empty node, as a visual representation is unnecessary.

// Create empty target node
ARNode *targetNode = [[ARNode alloc] init];
 
// Add target node to image trackable world
[self.imageTrackable.world addChild: targetNode];
 
// Set blank node as target node for ArbiTrack
arbiTrack.targetNode = targetNode;

Switching to ArbiTrack

We used a button to handle switching from image tracking to ArbiTrack. However you’re free to use whichever event you’d like to trigger ArbiTrack.

// Get ArbiTrack instance
ARArbiTrackerManager *arbiTrack = [ARArbiTrackerManager getInstance];
 
// If image trackable is detected
if ([self.imageTrackable isDetected]) {
 
    // Start ArbiTrack
    [arbiTrack start];
}

Setting your model's position

The engine needs the initial frame to receive the ArbiTrack world’s correct position. We therefore use the ArbiTrack Delegate/Listener this will notify us when ArbiTrack has been started and contains values. From here we want to transform the model from its position in the image trackable world into the same position but in the ArbiTrack's world. We also want to use the same steps for the model’s orientation.

// Get ArbiTrack instance
ARArbiTrackerManager *arbiTrack = [ARArbiTrackerManager getInstance];
 
// Get target nodes position relative to camera
ARVector3 *fullPos = [[arbiTrack targetNode].fullTransform multiplyByVector:[ARVector3 vectorWithZero]];
 
// Get target position relative to ArbiTracks world.
ARVector3 *posInArbiTrack = [arbiTrack.world.fullTransform.inverse multiplyByVector:fullPos];
 
//Get the orientation of the model relative to the ArbiTrack world
ARQuaternion *orInArbiTrack = [arbiTrack.world.fullOrientation.inverse multiplyByQuaternion:self.modelNode.fullOrientation];
 
// Add the model node as a child of ArbiTrack
[arbiTrack.world addChild:self.modelNode];
 
// Change model nodes position to be relative to the marker nodes world
[self.modelNode setPosition:posInArbiTrack];
 
// Change model nodes orientation to be relative to the marker nodes world
[self.modelNode setOrientation:orInArbiTrack];