Class HeadTracker

java.lang.Object
com.codename1.vr.HeadTracker

public final class HeadTracker extends Object

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.

  • Constructor Summary

    Constructors
    Constructor
    Description
    Creates a tracker over the platform motion sensors.
  • Method Summary

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

    Methods inherited from class Object

    clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • 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.