iPhone加速度计校准

iPhone加速度计校准,iphone,accelerometer,calibration,Iphone,Accelerometer,Calibration,如何正确校准iPhone游戏的加速计?目前,当手机位于平面上时,拨片会向左漂移。高通或低通滤波器不是一个可接受的解决方案,因为我需要完全控制桨,即使在低和高值。我知道苹果有BubbleLevel样本,但我发现很难跟上。。。有人能简化这个过程吗 //calibrate code from StackOverflow float calibration = -acceleration.x * accelerationFraction; float x = (-acceleration.y * acc

如何正确校准iPhone游戏的加速计?目前,当手机位于平面上时,拨片会向左漂移。高通或低通滤波器不是一个可接受的解决方案,因为我需要完全控制桨,即使在低和高值。我知道苹果有BubbleLevel样本,但我发现很难跟上。。。有人能简化这个过程吗

//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}
我的加速计代码如下所示:

-(void)accelerometer:(UIAccelerometer *)accelerometer didAccelerate:(UIAcceleration *)acceleration {

float acelx = -acceleration.y;
float x = acelx*40;

Board *board = [Board sharedBoard];
AtlasSprite *paddle = (AtlasSprite *)[board.spriteManager getChildByTag:10];

if ( paddle.position.x > 0 && paddle.position.x < 480) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}

if ( paddle.position.x < 55 ) {
    paddle.position = ccp(56, paddle.position.y);
}

if ( paddle.position.x > 435 ) {
    paddle.position = ccp(434, paddle.position.y);
}

if ( paddle.position.x < 55 && x > 1 ) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}

if ( paddle.position.x > 435 && x < 0) {
    paddle.position = ccp(paddle.position.x+x, paddle.position.y);
}
}
//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}
-(无效)加速计:(UIAccelerator*)加速计DID加速度:(UIAcceleration*)加速度{
float acelx=-加速度.y;
浮点数x=acelx*40;
董事会*董事会=[董事会共享董事会];
AtlasSprite*桨=(AtlasSprite*)[board.spriteManager getChildByTag:10];
如果(拨杆位置x>0和拨杆位置x<480){
桨叶位置=ccp(桨叶位置x+x,桨叶位置y);
}
如果(桨叶位置x<55){
桨叶位置=ccp(56,桨叶位置y);
}
如果(拨杆位置x>435){
桨叶位置=ccp(434,桨叶位置y);
}
如果(拨杆位置x<55&&x>1){
桨叶位置=ccp(桨叶位置x+x,桨叶位置y);
}
如果(拨杆位置x>435&&x<0){
桨叶位置=ccp(桨叶位置x+x,桨叶位置y);
}
}

谢谢大家!

好吧,问题解决了,而且解决办法很简单,我真的很尴尬,我没有早点想出办法。就这么简单:

//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}
在“校准按钮”中:

//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}
在游戏时间加速计功能中:

//add the offset to the accel value
float x = (-acceleration.y * accelerationFactor) + calibration;
//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}

只需添加偏移量即可。*隐藏他的头*

这是我目前掌握的代码:

//calibrate code from StackOverflow
float calibration = -acceleration.x * accelerationFraction;
float x = (-acceleration.y * accelerationFraction) + calibration;

//My original code
accelerationFraction = acceleration.y*2;
if (accelerationFraction < -1) {
    accelerationFraction = -1;
} else if (accelerationFraction > 1) {
    accelerationFraction = 1;
}
//API CHANGE set delegate to self
if (orientation == UIDeviceOrientationLandscapeLeft){
    accelerationFraction *= -1;
}
//从StackOverflow校准代码
浮动校准=-加速度.x*加速度分数;
浮动x=(-加速度.y*加速度分数)+校准;
//我的原始代码
加速度分数=加速度y*2;
如果(加速度分数<-1){
加速度分数=-1;
}否则如果(加速度分数>1){
加速度分数=1;
}
//API更改集委托给self
if(方向==UIDeviceOrientationAndscapeLeft){
加速度分数*=-1;
}

这是对主题的全面解释这是一条古老的线索,但我很好奇currentAccelX是什么类型的对象以及accelerationFactor是什么。你能帮我吗?是的,你从哪里弄来的车;currentAccelX和accelerationFactor?这篇文章早在2011年就过时了…我知道现在它更老了,但也许有人能帮我?Thx这是我到目前为止的代码://calibrate code from StackOverflow float calibration=-acceleration.x*accelerationFraction;浮动x=(-加速度.y*加速度分数)+校准;加速度分数=加速度y*2;if(accelerationFraction<-1){accelerationFraction=-1;}else if(accelerationFraction>1){accelerationFraction=1;}//API将委托更改为self if(orientation==UIDeviceOrientationLandscapeLeft){accelerationFraction*=-1;}请阅读我的解释: