The tracked-controls component is A-Frame’s base controller component that provides the foundation for all of A-Frame’s controller components. The tracked-controls component:
Grabs a Gamepad object from the Gamepad API given an ID or prefix.
Applies pose (position and orientation) from the Gamepad API to read controller motion.
Looks for changes in the Gamepad object’s button values to provide events when buttons are pressed or touched and when axis and touchpads are changed (i.e. axischanged
, buttonchanged
, buttondown
, buttonup
, touchstart
, touchend
).
All of A-Frame’s controller components build on top of the tracked-controls
component by:
Setting the tracked-controls component on the entity with the appropriate Gamepad ID (e.g., Oculus Touch (Right)). For example, the vive-controls component does
el.setAttribute('tracked-controls', {idPrefix: 'OpenVR'})
tracked-controls
will then connect to the appropriate Gamepad object to provide pose and events for the entity.
Abstracting the events provided by tracked-controls. tracked-controls events are low-level; it’d difficult for us to tell which buttons were pressed based off of those events alone because we’d have to know the button mappings beforehand. Controller components can know the mappings beforehand for their respective controllers and provide more semantic events such as triggerdown
or xbuttonup
.
Providing a model. tracked-controls
alone does not provide any appearance. Controller components can provide a model that shows visual feedback, gestures, and animations when buttons are pressed or touched.
The controller components following are only activated if they detect the controller is found and seen as connected in the Gamepad API.
The tracked-controls
component interfaces with tracked controllers. tracked-controls uses the Gamepad API to handle tracked controllers, and is abstracted by the hand-controls component as well as the vive-controls and oculus-touch-controls components. This component elects the appropriate controller, applies pose to the entity, observes buttons state and emits appropriate events.
Note that due to recent browser-specific changes, Vive controllers may be returned by the Gamepad API with id values of either "OpenVR Gamepad" or "OpenVR Controller", so using idPrefix
for Vive / OpenVR controllers is recommended.
<a-entity tracked-controls="controller: 0; idPrefix: OpenVR"></a-entity>