public final class HeadTracker

  1. Object
  2. HeadTracker

Tracks the device orientation for VR by feeding the motion sensors (gyroscope, accelerometer and magnetometer through com.codename1.sensors.MotionSensorManager) into an OrientationFilter.

The gyroscope drives the orientation; without one the tracker falls back to accelerometer tilt (stable pitch and roll, no reliable yaw). Sensor hardware runs only between #start() and #stop() - the sensors API reference-counts listeners, so a stopped tracker costs no battery.

#getOrientation(float[]) is thread safe: sensor events arrive on the EDT while the render thread reads the latest snapshot.

Constructors

public HeadTracker()Creates a tracker over the platform motion sensors.

Methods

public static boolean isSupported()True when the device has the sensors head tracking needs: a gyroscope, or at least an accelerometer for tilt-only tracking.
public OrientationFilter getFilter()The fusion filter behind this tracker, exposed to tune the gyro/reference blend.
public void start()Starts the sensors and orientation updates.
public void stop()Stops the sensors.
public boolean isStarted()True between #start() and #stop().
public void recenter()Rotates the orientation so the current view direction becomes “straight ahead”, keeping pitch and roll.
public void getOrientation(float[] quatOut4)Copies the latest orientation quaternion into quatOut4 as {x, y, z, w}.

Inherited methods

Constructor details

HeadTracker

public HeadTracker()
Creates a tracker over the platform motion sensors.

Method details

isSupported

public static boolean isSupported()
True when the device has the sensors head tracking needs: a gyroscope, or at least an accelerometer for tilt-only tracking.

getFilter

public OrientationFilter getFilter()
The fusion filter behind this tracker, exposed to tune the gyro/reference blend. Configure before #start().

start

public void start()
Starts the sensors and orientation updates. Idempotent.

stop

public void stop()
Stops the sensors. Idempotent; the last orientation remains readable.

isStarted

public boolean isStarted()
True between #start() and #stop().

recenter

public void recenter()
Rotates the orientation so the current view direction becomes “straight ahead”, keeping pitch and roll.

getOrientation

public void getOrientation(float[] quatOut4)
Copies the latest orientation quaternion into quatOut4 as {x, y, z, w}. Thread safe; intended to be read from the render thread.