Position of object in camera's coordinates in Unity3d.

Netvr
Explorer

Position of object in camera's coordinates in Unity3d.

Request: Would you please change a privacy settings for OnChangeEyeCallback listeners to public in WaveVR_CanvasEye class. Otherwise I couldn't see any normal way to get left and right eye's cameras.

A goal is to get a position of object in camera's coordinates and to put there a canvas with text.

Vive Staff

Re: Position of object in camera's coordinates in Unity3d.

Are you trying to get the instances of eyes’ camera?

You can try below:

WaveVR_Render.Instance.lefteye.transform.position & WaveVR_Render.Instance.righteye.transform.position should be able to get the eyes’ positions.

Netvr
Explorer

Re: Position of object in camera's coordinates in Unity3d.

Anyway this instances is should be getting when the camera is changing from left to right (method WaveVR_CanvasEye.changeEye() is runing)

 

I try to get position of object on screen by this part of script, and result is not correct.

void LateUpdate()
{

 Camera lefteyeCamera = WaveVR_Render.Instance.lefteye.transform.GetComponent<Camera>();

Vector3 pos = lefteyeCamera.WorldToScreenPoint(targetPosition)  

}

 

Vive Staff

Re: Position of object in camera's coordinates in Unity3d.

Since the camera position changes over time, you could listen WaveVR_Utils.Event.AFTER_NEW_POSES to correct the position.

 

void Start () {

        WaveVR_Utils.Event.Listen(WaveVR_Utils.Event.AFTER_NEW_POSES, OnAfterNewPoses);

    }

 

    void OnAfterNewPoses(params object[] args)

    {

        Camera lefteyeCamera = WaveVR_Render.Instance.lefteye.transform.GetComponent<Camera>();

        Vector3 pos = lefteyeCamera.WorldToScreenPoint(transform.position);

    }

Netvr
Explorer

Re: Position of object in camera's coordinates in Unity3d.

No, unfortunately it's not getting correct result.