Advanced Usage

For greater control, you can also initialize a Target Image in a script. The snippet below demonstrates how to initialize an Image Tracking Target Image and load the relevant tracking file:

private IntPtr imageTracker;
private string targetFilename = "myImage.png.zpt";

public void OnZapparInitialised(IntPtr pipeline)
{
    imageTracker = Z.ImageTrackerCreate(pipeline);
    StartCoroutine(Z.LoadZPTTarget(targetFilename,
    TargetDataAvailableCallback));
}

private void TargetDataAvailableCallback(byte[] data)
{
    Z.ImageTrackerTargetLoadFromMemory(imageTracker, data);
}

Image Anchors

Each image tracker exposes anchors for images detected and tracked in the camera view. Currently, only one anchor is tracked by the camera.

The pose of an image anchor is exposed by passing in a zero based index to the Z.ImageTrackerAnchorPose(...) function, e.g.:

void Update() {
    if (Z.ImageTrackerAnchorCount(imageTracker) > 0)
    {
        Matrix4x4 cameraPose = ZapparCamera.Instance.Pose();
        Matrix4x4 imagePose = Z.ImageTrackerAnchorPose(imageTracker,
        0, cameraPose, m_isMirrored);
        Matrix4x4 targetPose = Z.ConvertToUnityPose(imagePose);
    }
}

Anchor Pose

In your application you can set whether the pose of the camera is at the Unity origin, or whether the target is at the origin and the camera moves around. To drive the pose of the camera from an image target you should override the AnchorPoseCameraRelative function (and ensure your class is derived from ZapparTrackingTarget), like so:

public override Matrix4x4 AnchorPoseCameraRelative()
{
    if (Z.ImageTrackerAnchorCount(imageTracker) > 0)
    {
        return Z.ImageTrackerAnchorPoseCameraRelative(imageTracker,
                0, /* anchor index */
                m_isMirrored);
    }
    return Matrix4x4.identity;
}
zapcode branded_zapcode i