ImageTarget Class
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.
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.
Item Index
Methods
destroy
()
Destroys the object.
getDistanceTo
-
destinationTarget
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
ImageTargetThe ImageTarget to which the distance should be calculated.
Returns:
The distance between this ImageTarget and the destinationTarget.
getRotationTo
-
destinationTarget
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
ImageTargetThe ImageTarget to which the rotation should be calculated.
Returns:
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
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
ImageTargetThe ImageTarget to which the translation should be calculated.
Returns:
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
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
ImageTargetThe 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
ImageTargetThe 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
ImageTargetThe second ImageTarget whose translation to was changed by more than the threshold.