Wikitude SDK API Reference

API Docs for: 9.13.0
Show:

ImageTarget Class

Extends ARchitectObject
Module: AR

The ImageTarget is a representation of the tracked target image.

It can be used to:

  • Identify which target image was tracked.
  • Attach specific AR.Drawables to it.
  • Get the distance between this and another ImageTarget.
  • Get the translation between this and another ImageTarget.
  • Get the rotation between this and another ImageTarget.

An instance of an ImageTarget is created once a target image could be recognized, this instance is then available in AR.ImageTrackable.onImageRecognized. Once AR.ImageTrackable.onImageLost is called, the instance of the AR.ImageTarget is destroyed.

ImageTarget ExampleCode:
new AR.ImageTrackable(tracker, "*", { // The AR.ImageTrackable handles all targets available in the .wtc file
    onImageRecognized: function (target) {
        // Once an target image was recognized an ImageTarget is created in the SDK and passed in onImageRecognized.

        // Creates a 3d model drawable.
        var model = new AR.Model("assets/dino.wt3");

        // Assigns the model drawable to this specific ImageTarget.
        this.addImageTargetCamDrawables(target, model);
    }
    onImageLost: function (target) {
        // After onImageLost is called the ImageTarget(target) is destroyed.
        // This means that even if the same target image is recognized again, the ImageTarget is different.
    }
});

Note: The ImageTarget is created by the SDK and should not be created manually.

Methods

destroy

()

Inherited from ARchitectObject

Destroys the object.

getDistanceTo

(
  • destinationTarget
)
Number

Returns the distance to another ImageTarget. Note that both ImageTargets have to be created by the same AR.ImageTrackable to return the correct distance.

Parameters:

  • destinationTarget ImageTarget

    The ImageTarget to which the distance should be calculated.

Returns:

Number:

The distance between this ImageTarget and the destinationTarget.

getRotationTo

(
  • destinationTarget
)
Object

Returns the rotation to another ImageTarget. Note that both ImageTargets have to be created by the same AR.ImageTrackable to return the correct rotation.

Parameters:

  • destinationTarget ImageTarget

    The ImageTarget to which the rotation should be calculated.

Returns:

Object:

The rotation in X, Y and Z between this ImageTarget and the destinationTarget in degrees. Accessible through three separate fields called x, y, and z of the returned object.

getTranslationTo

(
  • destinationTarget
)
Object

Returns the translation to another ImageTarget. Note that both ImageTargets have to be created by the same AR.ImageTrackable to return the correct translation.

Parameters:

  • destinationTarget ImageTarget

    The ImageTarget to which the translation should be calculated.

Returns:

Object:

The translation in X, Y and Z between this ImageTarget and the destinationTarget in virtual units. Accessible through three separate fields called x, y, and z of the returned object.

Properties

destroyed

Boolean

Inherited from ARchitectObject

Indicates if the object has already been destroyed.

name

String

The name of the associated target image in the wikitude target collection (.wtc).

This property is immutable and may not be changed.

uniqueId

Number

The unique id of the ImageTarget. This unique id is incremented with every recognition of the same target.

This property is immutable and may not be changed.

Events

onDistanceChanged

The onDistanceChanged callback is triggered when the distance between this and any other image target was changed by more than the AR.ImageTracker.onDistanceChangedThreshold.
Note that this callback will only be triggered for ImageTargets that were created by the same AR.ImageTrackable.

The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onDistanceChanged.

Event Payload:

  • distance Number
  • destinationTarget ImageTarget

    The second ImageTarget whose distance to was changed by more than the threshold.

onRotationChanged

The onRotationChanged callback is triggered when the rotation between this and any other image target was changed by more than the AR.ImageTracker.onRotationChangedThreshold.
Note that this callback will only be triggered for ImageTargets that were created by the same AR.ImageTrackable.

The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onRotationChanged.

Event Payload:

  • rotation Number
  • destinationTarget ImageTarget

    The second ImageTarget whose rotation to was changed by more than the threshold.

onTranslationChanged

The onTranslationChanged callback is triggered when the translation between this and any other image target was changed by more than the AR.ImageTracker.onTranslationChangedThreshold.
Note that this callback will only be triggered for ImageTargets that were created by the same AR.ImageTrackable.

The trigger is null by default, and will thus result in no action executed when the trigger fires. A developer can add custom functionality by assigning a custom function to onTranslationChanged.

Event Payload:

  • translation Number
  • destinationTarget ImageTarget

    The second ImageTarget whose translation to was changed by more than the threshold.