Marker to Markerless Android

From Kudan AR Engine
Jump to: navigation, search

This tutorial will lead on from our previous tutorials, in which we described how to project and track content using marker and markerless tracking. If you have not already set up a project, we suggest you check it out the previous tutorials 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
ARArbiTrack arArbiTrack = ARArbiTrack.getInstance();
arArbiTrack.initialise();
 
// Add Activity to ARArbiTrack listeners
arArbiTrack.addListener(this);

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 = new ARNode();
targetNode.setName("targetNode");
 
// Add target node to image trackable world
trackable.getWorld().addChild(targetNode);
 
// Set blank node as target node for ArbiTrack
arArbiTrack.setTargetNode(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
ARArbiTrack arArbiTrack = ARArbiTrack.getInstance();
 
// If image trackable is detected
if (trackable.getDetected()) {
 
    // Start ArbiTrack
    arArbiTrack.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
ARArbiTrack arArbiTrack = ARArbiTrack.getInstance();
 
// Get model nodes position relative to camera
Vector3f fullPos = arArbiTrack.getTargetNode().getFullTransform().mult(Vector3f.ZERO);
 
// Get models position relative to ArbiTracks world.
Vector3f posInArbiTrack = arArbiTrack.getWorld().getFullTransform().invert().mult(fullPos);
 
// Get models orientation relative to ArbiTracks world.
Quaternion orInArbiTrack = arArbiTrack.getWorld().getWorldOrientation().inverse().mult((modelNode.getWorld().getWorldOrientation()));
 
// Add the model node as a child of ArbiTrack
arArbiTrack.getWorld().addChild(modelNode);
 
// Change model nodes position to be relative to the marker nodes world
modelNode.setPosition(posInArbiTrack);
 
// Change model nodes orientation to be relative to the marker nodes world
modelNode.setOrientation(orInArbiTrack);