cdmvision / arfoundation-densepointcloud

Visualizing a point cloud using scene depth in Unity similar to WWDC20 demo.
MIT License
64 stars 13 forks source link

Portrait orientation support #1

Open shaunsahdev opened 2 years ago

shaunsahdev commented 2 years ago

Hi, this looks great! do you know why it only works in landscape-left orientation? Thanks.

ibrahimpenekli commented 2 years ago

Hi @shaunsahdev thanks! As far as I remember, if the device rotates, depth and color image from device camera does not rotate. We should transform color and depth information of a point regarding to the device orientation. This is not a big deal to implement. If I had a spare time, I would have already implemented it :)

tizmon commented 2 years ago

You don't actually need to do those transformations. It is enough to just take the rotation into account when getting the world point. There might be something that I'm missing here, but it seems to work. E.g.:

switch (Screen.orientation) {
  case ScreenOrientation.Portrait:
    worldPoint = _mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * npy, Screen.height * (1-npx), depth));
    break;
  case ScreenOrientation.LandscapeRight:
    worldPoint =_mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * (1-npx), Screen.height * (1-npy), depth));
    break;
  default:
    // ScreenOrientation.LandscapeLeft
    worldPoint = _mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * npx, Screen.height * npy, depth));
    break;
}
ibrahimpenekli commented 2 years ago

You don't actually need to do those transformations. It is enough to just take the rotation into account when getting the world point. There might be something that I'm missing here, but it seems to work. E.g.:

switch (Screen.orientation) {
  case ScreenOrientation.Portrait:
    worldPoint = _mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * npy, Screen.height * (1-npx), depth));
    break;
  case ScreenOrientation.LandscapeRight:
    worldPoint =_mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * (1-npx), Screen.height * (1-npy), depth));
    break;
  default:
    // ScreenOrientation.LandscapeLeft
    worldPoint = _mainCamera.ScreenToWorldPoint(new Vector3(Screen.width * npx, Screen.height * npy, depth));
    break;
}

Thanks for code snippet. I meant this by saying 'transform color and depth information of a point regarding to the device orientation'.

tizmon commented 2 years ago

Thanks for code snippet. I meant this by saying 'transform color and depth information of a point regarding to the device orientation'.

Right 👍. I first thought it specifically meant rotating the XRCpuImages so they would match with the screen orientation. But of course it does not really matter if it is the screen coordinates that are rotated or the cpu images. Except that the latter would have been a lot more work.