/CocosAccelerometerFilter

Implementation of a low pass filter for accellerometer singlas in cocos2d-x

Primary LanguageC++

#INTRODUCTION

This class provides a simple low-pass filter to deal with noisy accelerometer signals for cocosd-x version 3. It's a straight port of the analogous filter from the AccelerometerGraph example found in the iOS developer library.

#Usage Include the AccelerometerFilter.h and AccelerometerFilter.cpp in your project. Include and initialize an instance variable for each scene in your project that uses the accelerometer. The constructor takes a reference to the scene and the value of the desiderd cutoff Frequency. Higher values of the cutoff frequency result in a smoother but also more lagged signal.

The setMaxThreshold and setMinThreshold methods can be used to clamp the accelerometer output to given values. Use the getAcceleration method to get the actual filtered value.

#Example code

std::unique_ptr accelerometer;
accelerometer=make_unique(scene,cutoff Frequency);
accelerometer->setMinThreshold(0.1, 0.1, 0.1);
accelerometer->setMaxThreshold(0.4, 0.4, 0.4);

CCLOG("Acc x:%f",accelerometer->getAcceleration().x);
CCLOG("Acc y:%f",accelerometer->getAcceleration().y);