Topic has a solution
Log in or register to post comments

How to get the target object direction for arbitrary ARCamera's position & rotation

Unity Editor
September 30, 2022 - 5:17am #1
Topic solved

Hello,
I'm working on an AR application using Vuforia engine.

For an arbitrary AR camera position and rotation, I want to determine whether a moving target is visible or off-camera.
And if the target is off-camera, I want to display an arrow on the UI canvas indicating the direction the target is in.

After the image marker is detected, the following values are available.
(1) ARCamera's position and rotation values (6 values)
(2) The target object's position values (3 values)

I noticed that all these values are based on the marker position.
In other words, the "world coordinate system" in this context is the "marker coordinate system".

Now how can I get the target object direction vector?

I think I need to first convert the target object's marker coordinate values to camera coordinate values.
Then, I need to do some calculations to determine if the target is visible or not for a given camera FOV (horizontal/vertical).

I'm not used to handling Unity classes and functions for this kind of matrix calculation.
Could you help me out?

I have attached two images showing my task.

Thank you in advance.

AttachmentSize
Image icon IMG_01.png71.85 KB
Image icon IMG_02.png49.62 KB
Platform: 

How to get the target object direction for arbitrary ARCamera's position & rotation

October 11, 2022 - 8:14pm #3

Hi Patrick,

Thank you for your reply. I'll check your link later.

In the meantime, I figured out the following solution myself.

public class Arrow : MonoBehaviour

{

    public GameObject arrowTarget;

    public GameObject arrow;

    private Vector3 targetWorldCoordinate, targetCameraCoordinate;

    private float horAngle, verAngle;



    void Update()

    {

        targetWorldCoordinate = arrowTarget.transform.position;

        targetCameraCoordinate = transform.worldToLocalMatrix * (targetWorldCoordinate - transform.position);

        horAngle = Mathf.Atan2(targetCameraCoordinate.x, targetCameraCoordinate.z) * Mathf.Rad2Deg;

        verAngle = Mathf.Atan2(targetCameraCoordinate.y, targetCameraCoordinate.z) * Mathf.Rad2Deg;

        float arrowAngle = Mathf.Atan2(verAngle, horAngle) * Mathf.Rad2Deg;

        arrow.transform.rotation = Quaternion.Euler(0, 0, arrowAngle);

    }

}

 

 

How to get the target object direction for arbitrary ARCamera's position & rotation

October 3, 2022 - 2:51am #2

Hey there,

 

I think you can circumvent this issue by changing the World Center Mode: https://developer.vuforia.com/forum/unity-extension-technical-discussion/what-world-center-mode#comment-47076

 

Kind regards,

Patrick Scheper

Vuforia Engine Product Manager

Log in or register to post comments