zoukankan      html  css  js  c++  java
  • 重力感应

    呵呵,难得能遇到我可以解决的问题.我刚刚做好的程序用到这个.我来说明下吧
    XXXAppDelegate.m 中

    - (void)applicationDidFinishLaunching:(UIApplication *)application {
        
        glView.animationInterval = 1.0 / 60.0;
        [glView startAnimation];
        
        //Configure and start accelerometer
            //这里是启动重力感应,不加就没反映
        [[UIAccelerometer sharedAccelerometer] setUpdateInterval:(1.0 / kAccelerometerFrequency)];
        [[UIAccelerometer sharedAccelerometer] setDelegate:self];
    }

    #define kFilteringFactor 0.1
    // Implement this method to get the lastest data from the accelerometer 
    - (void)accelerometer:(UIAccelerometer*)accelerometer didAccelerate:(UIAcceleration*)acceleration {
        //Use a basic low-pass filter to only keep the gravity in the accelerometer values
        _accelerometer[0] = acceleration.x * kFilteringFactor + _accelerometer[0] * (1.0 - kFilteringFactor);
        _accelerometer[1] = acceleration.y * kFilteringFactor + _accelerometer[1] * (1.0 - kFilteringFactor);
        _accelerometer[2] = acceleration.z * kFilteringFactor + _accelerometer[2] * (1.0 - kFilteringFactor);
    }

    把_accelerometer数组传出来到程序中使用,[0]是X方向,[1]是Y方向,[2]是Z方向(没试过)

  • 相关阅读:
    sql查询原理和Select执行顺序(sql优化)
    SQL Server如何清除连接过的服务器名称历史?
    SQL Server DATEDIFF()
    oracle 创建用户、表空间
    IDEA 快捷键
    (Reflection)反射
    ClassLoader
    简单代码// 求质数
    简单代码 //输入三个数求最大值.
    简单代码 //输入两个数加减乘除。
  • 原文地址:https://www.cnblogs.com/zzxap/p/2175616.html
Copyright © 2011-2022 走看看