Viro: How to show +z object (User's Back) when user rotates camera

Created on 25 Oct 2018  路  4Comments  路  Source: viromedia/viro

I have successfully integrated Viro in my project.

Followed below code and able to put object
https://github.com/viromedia/viro/issues/131

As in front of camera it's -Z and i am getting X and Z

var objFinalPosZ = objPoint.y - devicePoint.y;
// var objFinalPosZ = objPoint.z - devicePoint.z;
var objFinalPosX = objPoint.x - devicePoint.x;
//flip the z, as negative z(is in front of us which is north, pos z is behind(south).
return ({ x: objFinalPosX, z: -objFinalPosZ });

But the issue is i am not able to show the object those are behind my camera view

screenshot_20181025-143147

See in image i am in mid of two object i am able to view the -Z object but not able to view +z objects.
Is there any way i can rerender view if my camera rotates 180 degree.

Most helpful comment

HI @krishanjangir,
I see what the issue is. To fix the object not appearing when you turn around, you'll need to billboard it. Billboarding tells the object to always face the camera, this way in doesn't matter where the camera is, as the object will rotate to face it. In your case, the object is facing away from you when you turn around and therefore is not being drawn.

It seems like you are you are using a flexview, so for your top most flexview set the transformBehaviors property like below:

<ViroFlexView transformBehaviors={["billboard"]} .... />

That should fix the object not showing up when you turn around.

Regarding compass logic, if your device has no accelerometer or orientation sensor I'm not sure currently what can be done regarding orientation.

All 4 comments

Hi @krishanjangir, when you rotate the phone around(which implicitly changes the camera), the you should be facing +z and the object should show automatically. Perhaps I'm misunderstanding your question. Are you looking to have both of them display at once? Did you put in logic to handle compass calibration? Let me know, thanks.

To view both at once i have changed your logic

    if (objFinalPosZ > 0){ 
      objFinalPosZ = -objFinalPosZ   // putting +z back object in front
    }
   return ({ x: objFinalPosX, z: objFinalPosZ });

But i am using your code->

    //flip the z, as negative z(is in front of us which is north, pos z is behind(south).
    return ({ x: objFinalPosX, z: -objFinalPosZ });

on camera rotation +z and the object should show automatically. -> But this is not happening in my case.

see video
https://drive.google.com/file/d/1IjeDXn4rKQd56UIFTkRdVoEcHmP5-ZG-/view?usp=sharing

No i haven't implemented logic to handle compass calibration ,and what if my device has no Orientation sensor and Accelerometer.

HI @krishanjangir,
I see what the issue is. To fix the object not appearing when you turn around, you'll need to billboard it. Billboarding tells the object to always face the camera, this way in doesn't matter where the camera is, as the object will rotate to face it. In your case, the object is facing away from you when you turn around and therefore is not being drawn.

It seems like you are you are using a flexview, so for your top most flexview set the transformBehaviors property like below:

<ViroFlexView transformBehaviors={["billboard"]} .... />

That should fix the object not showing up when you turn around.

Regarding compass logic, if your device has no accelerometer or orientation sensor I'm not sure currently what can be done regarding orientation.

Thanks a lot @VikAdvani

Was this page helpful?
0 / 5 - 0 ratings