viromedia / viro

ViroReact: AR and VR using React Native
MIT License
2.31k stars 483 forks source link

Lock the start position of the video, regardless of the position of the phone #625

Closed abaddonGIT closed 5 years ago

abaddonGIT commented 5 years ago

Environment

Please provide the following information about your environment:

  1. Development OS: Mac
  2. Version: ViroReact version and React Native version - 2.13, 0.57.8
  3. Device(s): iPhone 6s and iPhone x

Description

I need to set a certain angle for 360 videos and it shouldn't depend on the position of the phone. I have not found a way to fix the start position of the playback.

<ViroScene>
        {show && (
          <Viro360Video
            source={{ uri: `file://${docDir}/${viroAppProps.filename}` }}
            onFinish={this._onFinish}
            onError={this._videoError}
            loop
            paused={false}
            rotation={[0,130,0]}
            volume={0}
          />)
        }
      </ViroScene>
dthian commented 5 years ago

Hey @abaddonGIT, are you building an AR or VR experience?

360 videos and it shouldn't depend on the position of the phone

I'm not sure what you mean by the above. As with most VR experiences (Oculus / GearVR / Cardboard / Daydream), there is always a starting direction where the user then rotates / moves from. Thus all the positions and rotations are determined in reference to that that starting reference point. The above is thus by design.

Else, if you have a better idea on what the rotation of 3D objects should instead be dependent on, please do us let us know as well.

abaddonGIT commented 5 years ago

Thanks for answer. I use ViroVRSceneNavigator

<ViroVRSceneNavigator
          apiKey="***************"
          vrModeEnabled={false}
          ref={(node) => {
            this._vrNavigator = node;
          }}
          viroAppProps={effect}
          initialScene={{
            scene: effect.type === 'video' ? VideoVRScene : ImageVRScene,
          }}
        />

The problem is that I need to start showing the video from a certain position. For example: IMG_3670 But now if the phone for example is on the table, the user sees "the ground". Maybe there's a way to lock in the starting position?

dthian commented 5 years ago

Maybe there's a way to lock in the starting position?

Sorry what do you mean by this? How would you determine the starting position?

igor-slotin commented 5 years ago

We have a problem that we need to show user exact video/image position in 360 an image (video) when they open an image (video). And it shouldn't depend on the exact user phone position at the beginning, but all further calculations inside the scene should be done from the start position of the phone. We have needed position in the video, and have gyroscope info about exact phone position. And we need to say to the Viro360Video element that current phone position is the needed position of the image.

For example, on the image, we have some element (cloud, for example) in the heavens and we want to show it when the user opens the image. but user when open that image handle his phone in standard reading position when phone looks to the floor by some angle. How can we say Viro element that current gyroscope position (by y-axis) is the position in heavens?

Otherwords, how to say Viro lib the diff from the exact phone position to needed video position?

dthian commented 5 years ago

but all further calculations inside the scene should be done from the start position of the phone

As asked previously above, what do you mean by the starting position? How would you determine this starting position? Is this starting position (or rotation) provided by your application, where it is rotation of the gyroscope?

we have some element (cloud, for example) in the heavens and we want to show it when the user opens the image. but user when open that image handle his phone in standard reading position when phone looks to the floor by some angle

This is by design in VR. For example, for a given "forest image" 360 background, if the user looks down, he sees the ground of the forest. This spatial awareness makes sense in VR, where the "World forest background" has no rotation - when the user looks straight down, he sees the ground.

However, from the above, it sounds like you want to re-set the background rotation to the "start position of the phone" - as you have previously mentioned. Thus, if the "Start position of the phone" is provided by your application, can't you simply rotate the Viro360Image to the start rotation provided by your application (in this case, it sounds like the start rotation is whatever the gyroscope's rotation is oriented to).

For example, if the start rotation you want is [0,0,0] degrees. One thing you can do is to determine how the camera has rotated thus far due to Google's VR head rotation (or the head rotation the VR headset is giving. This ideally would be the rotation as a result of the gyroscope.), and then apply the same camera rotation to the 360 background.

abaddonGIT commented 5 years ago

And as can be to transform the output from the gyroscope in the settings to rotate parameter?

dthian commented 5 years ago

Hey @abaddonGIT, well if the gyroscope readings represents x,y,z rotation in radians - then yes, since the ViroCamera takes a rotation of x,y,z in radians, you can simply just apply them.

But again, note that the x,y,z gyroscope output values you have provided will will have to align to the starting rotation of the Google's VR experience (we don't control the default rotation that Google provides).

That transformation from gyroscope space ->GoogleVR space is something you will have to calculate.

Note: if you don't need any VR head-gear related features, you could try using a normal Viro3DSceneNav instead, and control the rotation directly. That way you could just try to see if you can go from: "Gyroscope space -> Viro3DSceneNav rotation space".