문제

I want to get device rotation and i have achieved somehow but the code is not working which device is not present with Magentic sensor,Orientation sensor and Gyroscope sensor. But i have seen some app those are working like XClinometer and iHandy level free on device .Having device htc Explorer not giving value as not present with these sensor.please tell me how i can achieve this task. I have use this code but as sensor not available so not getting any value so no rotation matrix as well.

  @Override
    public void onSensorChanged(SensorEvent event) {

        switch (event.sensor.getType()) {
        case Sensor.TYPE_ACCELEROMETER:
            // copy new accelerometer data into accel array and calculate
            // orientation
            System.arraycopy(event.values, 0, accel, 0, 3);
            calculateAccMagOrientation();
            break;

        case Sensor.TYPE_GYROSCOPE:
            // process gyro data
            gyroFunction(event);
            break;

        case Sensor.TYPE_MAGNETIC_FIELD:
            // copy new magnetometer data into magnet array
            System.arraycopy(event.values, 0, magnet, 0, 3);
            break;

        }

}

and the method is

public void calculateAccMagOrientation() {

         if (SensorManager.getRotationMatrix(rotationMatrix, null, accel,
                magnet)) {
            SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X,
                    SensorManager.AXIS_Y, mValuesOrientation);
            SensorManager.getOrientation(rotationMatrix, mValuesOrientation);

        }else{
            //float[] array = new float[9];
            if(magnet[0]<=0){
                System.out.println("herr.....");
                System.out.println();
            }else{
                System.out.println("null so herr.....");
            }
            /*on htc device it is coming here so i need code here to get angle as only received accelerometer sensor data.
           */
        }
    }
도움이 되었습니까?

해결책

The examples you link to only need the tilt angles, not the rotation matrix. It is enough to have accelerometers to get the tilt angles.

The rotation matrix contains more information than the tilt angles and it requires gyroscopes as well.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top