ofDocsdocumentation addons ofxAccelerometer ofxAccelerometerHandler

ofxAccelerometerHandler

This addon allows you access to the acceleromete on devices that support one. At the moment both Android and iOS are supported.

To get values from the accelerometer in polling mode, request them:


void testApp::setup(){
	ofxAccelerometer.setup(); // this initializes the accelerometer
}

void testApp::update()
{
  ofVec3f accel = ofxAccelerometer.getForce();
  ofVec2f orientation = ofxAccelerometer.getOrientation();
}

To register an event handler for the accelerometer values changing, do something like the following:

ofAddListener(ofxAccelerometer.accelChanged,this,&ofApp::accelerationChanged);


exit( )

void exit()

Stops ofxAccelerometer from receiving updates from the underlying system.


getForce( )

ofPoint & getForce()

Gets the current smoothed accelerometer data (value in number of g's (1g = gravity, 9.8m/s^2). The smoothing prevents sudden spikes but can potentially make detecting gestures or other sudden moments difficult.


getMatrix( )

GLfloat * getMatrix()

This returns a 3x3 matrix with the following values set:

First column is gravity vector. Second column as an arbitrary vector in the plane perpendicular to the gravity vector {Gx, Gy, Gz} defined by by the equation "Gx * x + Gy * y + Gz * z = 0" in which we arbitrarily set x=0 and y=1. Third column as the cross product of the first two.


getOrientation( )

ofPoint & getOrientation()

Gets current orientation in degrees as an ofPoint (x: pitch, y: roll, z: not used).

yaw-pitch


getRawAcceleration( )

ofPoint & getRawAcceleration()

Gets current real accelerometer data (value in number of g's (1g = gravity, 9.8m/s^2)


ofxAccelerometerHandler( )

ofxAccelerometerHandler()

setCallback( ... )

void setCallback(ofxAccelCB new_callback)

This allows you to set a callback that can be called whenever motion is detected.


setForceSmoothing( ... )

void setForceSmoothing(float forceSmoothing)

This sets amount of smoothing on force data (0: no smooth, 1:very smooth)


setOrientationSmoothing( ... )

void setOrientationSmoothing(float orientationSmoothing)

This sets amount of smoothing on orientation data (0: no smooth, 1:very smooth)


setup( )

void setup()

You must call setup() before polling ofxAccelerometer for force or orientation values.


update( ... )

void update(float x, float y, float z)

This is called by your underlying OS to update all the orientation matrices.


updateMatrix( )

void updateMatrix()

updateOrientation( )

void updateOrientation()

Variables

ofPoint accelForce
ofPoint accelOrientation
ofPoint accelReal
ofxAccelCB callback
float forceSmoothing
GLfloat matrix
bool matrixDirty
bool orientDirty
ofPoint orientation
float orientationSmoothing