Skip to content

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

Notifications You must be signed in to change notification settings

lucaregini/CocosAccelerometerFilter

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

5 Commits
 
 
 
 
 
 

Repository files navigation

#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);

About

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

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages