Not able to translate device co-ordinate system to world co-ordinate system on android

我怕爱的太早我们不能终老 提交于 2019-12-22 17:59:02

问题


I have written a small code to convert the device co-ordinates into world co-ordinates by multiplying the Rotation matrix(using getRotationMatrix) and the vector (Ax,Ay,Az) which are the accelerometer values. When I run this, and the phone is static, I get a very fluctuating value for the Z axis(from 9.3 to 10.3) and the other two are 0. However when I give the phone some acceleration in any direction , it still doesn't show any change to those values and they remain zero. This is the part of the code where I get the values.

     if(ctp.getType()==Sensor.TYPE_ACCELEROMETER){
            Ca[0]=event.values[0];  
            Ca[1]=event.values[1];
            Ca[2]=event.values[2];
            SensorManager.getRotationMatrix(R, I, Ca , Cm);
            for(i=0;i<16;i++)
                rotmat[i/4][i%4]=R[i];
            fAx=0;
            fAy=0;
            fAz=0;
            Ca[3]=0;
            for(i=0;i<4;i++){
                fAx+=rotmat[0][i]*Ca[i];
                fAy+=rotmat[1][i]*Ca[i];
                fAz+=rotmat[2][i]*Ca[i];                    
            }
            buff1.append(fAx);              
            x.setText(buff1.toString());
            buff2.append(fAy);
            y.setText(buff2.toString());
            buff3.append(fAz);
            z.setText(buff3.toString());  
        }
        else if(ctp.getType()==Sensor.TYPE_MAGNETIC_FIELD){
            Cm[0]=event.values[0];  
            Cm[1]=event.values[1];
            Cm[2]=event.values[2];
        }

Also I would like to know if it would be better to get the rotation matrix based on the orientation sensor on my own or use the inbuilt getRotationMatrix?

来源:https://stackoverflow.com/questions/7708987/not-able-to-translate-device-co-ordinate-system-to-world-co-ordinate-system-on-a

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!