Class HeadTracker
java.lang.Object
com.codename1.vr.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.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionThe fusion filter behind this tracker, exposed to tune the gyro/reference blend.voidgetOrientation(float[] quatOut4) Copies the latest orientation quaternion intoquatOut4as{x, y, z, w}.booleanTrue between#start()and#stop().static booleanTrue when the device has the sensors head tracking needs: a gyroscope, or at least an accelerometer for tilt-only tracking.voidrecenter()Rotates the orientation so the current view direction becomes "straight ahead", keeping pitch and roll.voidstart()Starts the sensors and orientation updates.voidstop()Stops the sensors.
-
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
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 intoquatOut4as{x, y, z, w}. Thread safe; intended to be read from the render thread.
-