camera

The camera component defines from which perspective the user views the scene.
The camera is commonly paired with controls components that allow input devices
to move and rotate the camera.

Examples

A camera should usually be positioned at the average height of human eye level
(1.6 meters). When used with controls that receive rotation or position (e.g.
from a VR device) this position will be overridden.

<a-entitycameralook-controlsposition="0 1.6 0"></a-entity>

When moving or rotating the camera relative to the scene, use a camera rig.
By doing so, the camera’s height offset can be updated by roomscale devices,
while still allowing the tracked area to be moved independently around the
scene.

Note that you should use HUDs sparingly as they cause irritation and eye strain
in VR. Consider integrating menus into the fabric of the world itself. If you
do create a HUD, make sure that the HUD is more in the center of the field of
view such that the user does not have to strain their eyes to read it.

Reading Position or Rotation of the Camera

To actively read the position or rotation of the camera, use a tick handler
of a component that reads the position or rotation, and does something with it.
Then attach the component to the camera.

Reading World Position or Rotation of the Camera

three.js has methods to attain position or rotation (or scale) in world space
versus object local space.

AFRAME.registerComponent('rotation-reader', {/** * We use IIFE (immediately-invoked function expression) to only allocate one * vector or euler and not re-create on every tick to save memory. */ tick: (function () {var position = new THREE.Vector3();var rotation = new THREE.Euler();returnfunction () {this.el.object3D.getWorldPosition(position);this.el.object3D.getWorldRotation(rotation);// position and rotation now contain vector and euler in world space. }; })});

The A-Frame project and content on this site are licensed under the MIT License.