Skip to content

Sensors

Joan edited this page Apr 6, 2014 · 8 revisions

BeyondAR uses the following sensors to provide the AR experience:

  • Accelerometer
  • Magnetic field

The values provided by this sensors is filtered in order to get a better user experience. If you need to access this data you could use the BeyondarSensorManager.

To get notified when the sensors are updated just register your BeyondarSensorListener implementation:

// Register the sensor listener
BeyondarSensorManager.registerSensorListener(mySensorListener);

// When we don't need to listen the sensors we need to unregister our listener
BeyondarSensorManager.unregisterSensorListener(mySensorListener);

Then when the sensor data is changes the onSensorChanged will be called. Use the SensorEvent object to check which kind of sensor is generating the data:

@Override
public void onSensorChanged(float[] filteredValues, SensorEvent event) {
    switch (event.sensor.getType()) {
	case Sensor.TYPE_ACCELEROMETER:
		mLastAccelerometer = filteredValues;
		break;
	case Sensor.TYPE_MAGNETIC_FIELD:
		mLastMagnetometer = filteredValues;
		break;
	}
	if (mLastAccelerometer == null || mLastMagnetometer == null)
		return;

	boolean success = SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
	SensorManager.getOrientation(mR, mOrientation);
	if (success)
		rotateView((float) Math.toDegrees(mOrientation[0]));
}

Example code

You can find the source code of a complete example here.

Clone this wiki locally