React-360: Is there a way to access the Camera rotation inside a component?

Created on 4 Mar 2017  ·  3Comments  ·  Source: facebookarchive/react-360

Description

I was trying to manipulate a flight in space based on where the person looks. Todo that I need camera.getWorldDirection(). Is there a way to get access to the camera within a component?

Most helpful comment

If you just want the orientation of the camera (say, to make items move with it), we provide a utility called VrHeadModel which receives updates from a Native Module.

import {VrHeadModel} from 'react-vr';

const position = VrHeadModel.positionOfHeadMatrix();
const rotation = VrHeadModel.rotationOfHeadMatrix();
const horizFov = VrHeadModel.horizontalFov();
const vertFov = VrHeadModel.verticalFov();

It uses our internal MatrixMath module to produce these results, creating basic JS arrays containing the data from these vectors / matrices.

All 3 comments

No you cannot access the camera directly within a React component, as the camera is on the runtime / three.js side of things. So you would need a Native Module or get a reference to the camera from the VRInstance in client.js (more on that in Issue https://github.com/facebookincubator/react-vr/issues/43)

If you just want the orientation of the camera (say, to make items move with it), we provide a utility called VrHeadModel which receives updates from a Native Module.

import {VrHeadModel} from 'react-vr';

const position = VrHeadModel.positionOfHeadMatrix();
const rotation = VrHeadModel.rotationOfHeadMatrix();
const horizFov = VrHeadModel.horizontalFov();
const vertFov = VrHeadModel.verticalFov();

It uses our internal MatrixMath module to produce these results, creating basic JS arrays containing the data from these vectors / matrices.

Holy cow 🐮 … this is amazing!

Was this page helpful?
0 / 5 - 0 ratings

Related issues

borisyankov picture borisyankov  ·  4Comments

nafiou picture nafiou  ·  3Comments

wuno picture wuno  ·  3Comments

devsatish picture devsatish  ·  3Comments

aziliak picture aziliak  ·  3Comments