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?
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!
Most helpful comment
If you just want the orientation of the camera (say, to make items move with it), we provide a utility called
VrHeadModelwhich receives updates from a Native Module.It uses our internal MatrixMath module to produce these results, creating basic JS arrays containing the data from these vectors / matrices.