Welcome to the world of augmented reality and to the MobileSDK. This example application shows how a simple AR use case can be implemented. In this scenario we like to make the MetaioMan standing with his feet on a picture of himself.
public class HelloAugmentedWorldExample extends ARViewActivity {
/**
* The geometry to be displayed
*/
private IUnifeyeMobileGeometry mGeometry;
/**
* Tracking file you like to use. The file must be within the assets folder
* of this project.
*/
private final String mTrackingDataFileName = "TrackingData_MarkerlessFast.xml";
/**
* Gets called by the super-class after the GLSurface has been created.
* It runs on the OpenGL-thread.
*/
@Override
protected void loadUnifeyeContents() {
try {
// Load Tracking data
loadTrackingData(mTrackingDataFileName);
// Load all geometry
mGeometry = loadGeometry("metaioman.md2");
// Do something with it, like scaling
mGeometry.setMoveScale( new Vector3d(1,1,1) );
} catch (Exception e) {
Logger.logException(e);
}
}
}
mMobileSDK = AS_UnifeyeSDKMobile.CreateUnifeyeMobileAndroid(
this, Configuration.signature);
The object returned is a reference to the MobileSDK and has the type IUnifeyeMobileAndroid.
The next important step is to inflate the layout.
mGUIView = View.inflate(this, getGUILayout(), null);A reference of the View is saved to attach it later. Before it gets visible we need to create the AR-view first, so that it is the first element in the view.
mMobileSDK.activateCamera( Configuration.Camera.deviceId,
Configuration.Camera.resolutionX,
Configuration.Camera.resolutionY);
We store all nessecary data in the Configuration class here. The method activateCamera returns a vector with the actual dimension of the camera image. We recommend to use the following values: deviceId: Is 0 for the main camera of the device. Use 1 to use the front facing camera instead.
resolutionX, resolutionY: We recommend to use 480x320 as the best tradeoff between visual quality and performance.
onSurfaceCreated(), onSurfaceCachanged(), onSurfaceDestroyed(), onDrawFrame() and onScreenshot().
/* * Create a GLSurfaceView. The context 'this' is the current Activity. */ mUnifeyeSurfaceView = new UnifeyeGLSurfaceView(this); /* * Register the current Activity to receive callbacks. * With registerCallback onSurface...() events will be avaible. * setOnTouchListener lets us get touch-events. */ mUnifeyeSurfaceView.registerCallback(this); mUnifeyeSurfaceView.setOnTouchListener(this);
/**
* Loads trackingDataFileName from the assets folder
* @param trackingDataFileName The filename of the tracking data to be loaded.
* @return true on success, false otherwise
*/
protected boolean loadTrackingData(String trackingDataFileName) {
MobileSDKExampleApplication app = (MobileSDKExampleApplication) getApplication();
String filepathTracking = app.getAssetPath(trackingDataFileName);
boolean result = mMobileSDK.setTrackingData(filepathTracking);
Logger.log(Log.ASSERT, "Tracking data loaded: " + result);
return result;
}
In the HelloAugmentedWorldActivity class this method is used.
mUnifeyeMobile.registerAudioCallback( mUnifeyeSurfaceView.getUnifeyeAudioRenderer() ); mUnifeyeMobile.registerCallback( mCallbackHandler );