当前位置: 首页>>代码示例>>Java>>正文


Java SensorManager.getOrientation方法代码示例

本文整理汇总了Java中android.hardware.SensorManager.getOrientation方法的典型用法代码示例。如果您正苦于以下问题:Java SensorManager.getOrientation方法的具体用法?Java SensorManager.getOrientation怎么用?Java SensorManager.getOrientation使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在android.hardware.SensorManager的用法示例。


在下文中一共展示了SensorManager.getOrientation方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent event) {
    if (event.accuracy == SensorManager.SENSOR_STATUS_ACCURACY_LOW) return;

    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        arrayCopy(event.values, geomagnetic);
    }
    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        arrayCopy(event.values, gravity);
    }
    if (SensorManager.getRotationMatrix(R, I, gravity, geomagnetic)) {
        SensorManager.getOrientation(R, orientation);
        azimuth += easing * (orientation[0] - azimuth);
        pitch += easing * (orientation[1] - pitch);
        roll += easing * (orientation[2] - roll);
    }
}
 
开发者ID:InnoFang,项目名称:Android-Code-Demos,代码行数:17,代码来源:CompassSketch.java

示例2: update

import android.hardware.SensorManager; //导入方法依赖的package包/类
protected void update(float[] vectors) {
	int worldAxisX = SensorManager.AXIS_X;
	int worldAxisZ = SensorManager.AXIS_Z;

	float[] rotationMatrix = new float[9];
	float[] adjustedRotationMatrix = new float[9];
	float[] orientation = new float[3];

	SensorManager.getRotationMatrixFromVector(rotationMatrix, vectors);
	SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisX, worldAxisZ, adjustedRotationMatrix);
	SensorManager.getOrientation(adjustedRotationMatrix, orientation);

	float roll = orientation[2] * FROM_RADS_TO_DEGS;

	if (roll > -45 && roll < 45) {
		setRequestedOrientation(ActivityInfo.SCREEN_ORIENTATION_UNSPECIFIED);
		Log.d(LOG_TAG, "Requesting undefined");
	}
	Log.d(LOG_TAG, "Roll: " + roll);
}
 
开发者ID:SebastianRask,项目名称:Pocket-Plays-for-Twitch,代码行数:21,代码来源:StreamActivity.java

示例3: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * SensorEventListener method called when sensor values are updated. Reads gravitational and
 * magnetic field information, and when both are available computes the orientation values
 * and calls the delegate with them.
 */
@Override public void onSensorChanged(SensorEvent event) {
    switch(event.sensor.getType()) {
    case Sensor.TYPE_MAGNETIC_FIELD:
        mags = event.values.clone();
        break;
    case Sensor.TYPE_ACCELEROMETER:
        accels = event.values.clone();
        break;
    }

    if (mags!=null && accels!=null) {
        SensorManager.getRotationMatrix(R, I, accels, mags);
        SensorManager.getOrientation(R, orientationValues);
        delegate.receivedOrientationValues(
                orientationValues[0], orientationValues[1], orientationValues[2]);
    }
}
 
开发者ID:StringMon,项目名称:homescreenarcade,代码行数:23,代码来源:OrientationListener.java

示例4: getBaseOrientation

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * Calculates orientation angles from accelerometer and magnetometer output.
 */
protected float[] getBaseOrientation(float[] acceleration, float[] magnetic) {
    // To get the orientation vector from the acceleration and magnetic
    // sensors, we let Android do the heavy lifting. This call will
    // automatically compensate for the tilt of the compass and fail if the
    // magnitude of the acceleration is not close to 9.82m/sec^2. You could
    // perform these steps yourself, but in my opinion, this is the best way
    // to do it.
    float[] rotationMatrix = new float[9];
    if (SensorManager.getRotationMatrix(rotationMatrix, null, acceleration, magnetic)) {
        float[] baseOrientation = new float[3];
        SensorManager.getOrientation(rotationMatrix, baseOrientation);
        return baseOrientation;
    }

    return null;
}
 
开发者ID:KalebKE,项目名称:FSensor,代码行数:20,代码来源:OrientationFusion.java

示例5: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
    synchronized (this) {
        if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
            lowPass(event.values, mGravity);
        }
        if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
            lowPass(event.values, mGeomagnetic);
        }
        float R[] = new float[9];
        float I[] = new float[9];
        if (SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic)) {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            mOrientation[0] = (float)Math.toDegrees(orientation[0]);
            adjustArrow();
        }
    }
}
 
开发者ID:wade-fs,项目名称:Military-North-Compass,代码行数:20,代码来源:Compass.java

示例6: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor == compas){
        System.arraycopy(event.values,0,comp,0,event.values.length);
        c=true;
    }
    else if(event.sensor == accelerometer){
        System.arraycopy(event.values,0,acc,0,event.values.length);
        a=true;
    }
    if(c && a) {
        float []r = new float[9],orien=new float[3];
        SensorManager.getRotationMatrix(r, null, acc, comp);
        SensorManager.getOrientation(r, orien);
        float grad = (float)((Math.toDegrees(orien[0])+360)%360);
        MyLocation.getInstance().setCompas(grad);
    }
}
 
开发者ID:TudorRosca,项目名称:enklave,代码行数:19,代码来源:MyCompas.java

示例7: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent event) {
        int type = event.sensor.getType();
        float[] data;
        if (type == Sensor.TYPE_ACCELEROMETER) {
            data = mGData;
        } else if (type == Sensor.TYPE_MAGNETIC_FIELD) {
            data = mMData;
        } else {
            // we should not be here.
            return;
        }
        for (int i=0 ; i<3 ; i++)
            data[i] = event.values[i];

        SensorManager.getRotationMatrix(mR, mI, mGData, mMData);
// some test code which will be used/cleaned up before we ship this.
//        SensorManager.remapCoordinateSystem(mR,
//                SensorManager.AXIS_X, SensorManager.AXIS_Z, mR);
//        SensorManager.remapCoordinateSystem(mR,
//                SensorManager.AXIS_Y, SensorManager.AXIS_MINUS_X, mR);
        SensorManager.getOrientation(mR, mOrientation);
        float incl = SensorManager.getInclination(mI);

        if (mCount++ > 50) {
            final float rad2deg = (float)(180.0f/Math.PI);
            mCount = 0;
            Log.d("Compass", "yaw: " + (int)(mOrientation[0]*rad2deg) +
                    "  pitch: " + (int)(mOrientation[1]*rad2deg) +
                    "  roll: " + (int)(mOrientation[2]*rad2deg) +
                    "  incl: " + (int)(incl*rad2deg)
                    );
        }
    }
 
开发者ID:sdrausty,项目名称:buildAPKsSamples,代码行数:34,代码来源:CompassActivity.java

示例8: calculateOrientation

import android.hardware.SensorManager; //导入方法依赖的package包/类
private void calculateOrientation() {
    // If phone doesn't have Rotation Vector sensor, calculate orientation based on Accelerometer and Magnetometer
    if (SensorManager.getRotationMatrix(mAccMagMatrix, null, mAccel, mMagnet) && !hasRotationSensor) {
        SensorManager.getOrientation(mAccMagMatrix, mOrientation);
    } else {
        SensorManager.getRotationMatrixFromVector(mRotationMatrixFromVector, mRotation);
        SensorManager.getOrientation(mRotationMatrixFromVector, mOrientation);
    }

    // Calculate azimuth to detect direction
    currentAzimuth = Math.toDegrees(mOrientation[0]);

    // Only notify other receivers if there is a change in orientation greater than 2.0 degrees
    if(Math.abs(currentAzimuth - preAzimuth) >= 2.0) {
        announceChange(ANGLE_UPDATE);
        preAzimuth = currentAzimuth;
    }
}
 
开发者ID:tringuyen1121,项目名称:Khonsu,代码行数:19,代码来源:SensorService.java

示例9: calculateOrientation

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * 计算方向
 *
 * @return
 */
private void calculateOrientation(float[] accValues, float[] magValues) {
	float[] R = new float[9];
	float[] values = new float[3];
	SensorManager.getRotationMatrix(R, null, accValues, magValues);
	SensorManager.getOrientation(R, values);
	// 相反方向所以为负
	newRotationDegree = (float) Math.toDegrees(values[0]);
}
 
开发者ID:613-sysu,项目名称:Days,代码行数:14,代码来源:CalendarActivity.java

示例10: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {

    if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
        mGravity = event.values;
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD_UNCALIBRATED)
        mGeomagnetic = event.values;
    if ((mGravity == null) || (mGeomagnetic == null))
        return;

    float[] R = new float[9];
    float[] I = new float[9];
    if (!SensorManager.getRotationMatrix(R, I, mGravity, mGeomagnetic))
        return;

    float[] orientation = new float[3];
    SensorManager.getOrientation(R, orientation);

    if (orientation == null)
        return;

    double rollAngle = orientation[1] * 180 / Math.PI;
    double pitchAngle = orientation[2] * 180 / Math.PI;

    if(notWithinAngleTolerance((int)rollAngle, mLastRoll))
        this.mRollTextView.setText(String.format("%.0f", (rollAngle)));
    if(notWithinAngleTolerance((int)pitchAngle,mLastPitch))
        this.mPitchTextView.setText(String.format("%.0f", (pitchAngle)));

    mLastPitch = (int)pitchAngle;
    mLastRoll = (int) rollAngle;

    calculateAndSetSpeed(rollAngle,pitchAngle);
}
 
开发者ID:zugaldia,项目名称:android-robocar,代码行数:35,代码来源:TiltControllerActivity.java

示例11: getSensorsData

import android.hardware.SensorManager; //导入方法依赖的package包/类
private void getSensorsData(){
    SensorManager.getRotationMatrix(sensorInitializer.getRotationMatrix(), null,
            sensorInitializer.getAccelerationValues(), sensorInitializer.getMagneticValues());
    SensorManager.getOrientation(sensorInitializer.getRotationMatrix(), sensorInitializer.getOrientationValues());
    xSensorAxis = sensorInitializer.getOrientationValues()[1] * 57.3f * (-1);
    ySensorAxis = sensorInitializer.getOrientationValues()[2] * 57.3f + 90.0f;
}
 
开发者ID:PawelTypiak,项目名称:Checkerboard-IMU-Comparator,代码行数:8,代码来源:MainActivity.java

示例12: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event) {
    if(event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
    {
        mGravity = event.values;
    }
    if(event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
    {
        mGeomagnetic = event.values;
    }
    if(mGravity != null && mGeomagnetic != null)
    {
        float R[] = new float[9];
        float I[] = new float[9];
        boolean success = SensorManager.getRotationMatrix(R,I,mGravity,mGeomagnetic);
        if(success)
        {
            float orientation[] = new float[3];
            SensorManager.getOrientation(R, orientation);
            Log.e("NEW ORIENTATION---","---------------");
            Log.e("orientation azimut", String.valueOf(orientation[0]*60));
            Log.e("orientation pitch", String.valueOf(orientation[1]*60));
            Log.e("orientation roll", String.valueOf(orientation[2]*60));

            txt.setText("orientation azimut " + String.valueOf(orientation[0]*60) + "\n" + "orientation pitch" + String.valueOf(orientation[1]*60) + "\n" + "orientation roll"+ String.valueOf(orientation[2]*60));
        }
    }
}
 
开发者ID:ANFR-France,项目名称:proto-collecte,代码行数:29,代码来源:CameraActivity.java

示例13: updateOrientationAngles

import android.hardware.SensorManager; //导入方法依赖的package包/类
public void updateOrientationAngles() {
    // Update rotation matrix, which is needed to update orientation angles.
    SensorManager.getRotationMatrix(mRotationMatrix, null,
            mAccelerometerReading, mMagnetometerReading);

    // "mRotationMatrix" now has up-to-date information.

    SensorManager.getOrientation(mRotationMatrix, mOrientationAngles);

    // "mOrientationAngles" now has up-to-date information.
}
 
开发者ID:Twelvelines,项目名称:AndroidMuseumBleManager,代码行数:12,代码来源:ScanFragment.java

示例14: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
    public void onSensorChanged(SensorEvent event) {

    // get the angle around the z-axis rotated
        if (event.sensor == mMagneticSensor) {
            System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
            mLastMagnetometerSet = true;
        } else if (event.sensor == mAccelerometer) {
            System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
            mLastAccelerometerSet = true;
        }

        if (mLastAccelerometerSet && mLastMagnetometerSet) {
            SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
            SensorManager.getOrientation(mR, mOrientation);
            float azimuthInRadians = mOrientation[0];

            float azimuthInDegress = (float) (Math.toDegrees(azimuthInRadians) + 360) % 360;

            mTargetDirection = azimuthInDegress;
        }

        float azimuth = -mTargetDirection;
        GeomagneticField geoField = new GeomagneticField( Double
                .valueOf( mLastLocation.getLatitude() ).floatValue(), Double
                .valueOf( mLastLocation.getLongitude() ).floatValue(),
                Double.valueOf( mLastLocation.getAltitude() ).floatValue(),
                System.currentTimeMillis() );
        if(geoField.getDeclination()<0) {
            azimuth += geoField.getDeclination(); // converts magnetic north into true north
        }else{
            azimuth -= geoField.getDeclination();
        }
        //Correct the azimuth
        azimuth = (azimuth+360) % 360;
        //get the bearing
        float y = (float)Math.sin(Math.toRadians(target.getLongitude()-mLastLocation.getLongitude())) * (float)Math.cos(Math.toRadians(target.getLatitude()));
        float x = (float)Math.cos(Math.toRadians(mLastLocation.getLatitude()))*(float)Math.sin(Math.toRadians(target.getLatitude())) -
                (float)Math.sin(Math.toRadians(mLastLocation.getLatitude()))*(float)Math.cos(Math.toRadians(target.getLatitude()))*(float)Math.cos(Math.toRadians(target.getLongitude()-mLastLocation.getLongitude()));
        float bearing = (float)Math.toDegrees(Math.atan2(y, x));
    image.setRotation(azimuth+bearing);
}
 
开发者ID:karuiel,项目名称:GPSTracker,代码行数:43,代码来源:Route.java

示例15: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
/**
 * Responds to changes in the accelerometer or magnetic field sensors to
 * recompute orientation.  This only updates azimuth, pitch, and roll and
 * raises the OrientationChanged event if both sensors have reported in
 * at least once.
 *
 * @param sensorEvent an event from the accelerometer or magnetic field sensor
 */
@Override
public void onSensorChanged(SensorEvent sensorEvent) {
  if (enabled) {
    int eventType = sensorEvent.sensor.getType();

    // Save the new sensor information about acceleration or the magnetic field.
    switch (eventType) {
      case Sensor.TYPE_ACCELEROMETER:
        // Update acceleration array.
        System.arraycopy(sensorEvent.values, 0, accels, 0, DIMENSIONS);
        accelsFilled = true;
        // Only update the accuracy property for the accelerometer.
        accuracy = sensorEvent.accuracy;
        break;

      case Sensor.TYPE_MAGNETIC_FIELD:
        // Update magnetic field array.
        System.arraycopy(sensorEvent.values, 0, mags, 0, DIMENSIONS);
        magsFilled = true;
        break;

      default:
        Log.e(LOG_TAG, "Unexpected sensor type: " + eventType);
        return;
    }

    // If we have both acceleration and magnetic information, recompute values.
    if (accelsFilled && magsFilled) {
      SensorManager.getRotationMatrix(rotationMatrix,    // output
                                      inclinationMatrix, // output
                                      accels,
                                      mags);
      SensorManager.getOrientation(rotationMatrix, values);

      // Make sure values are in expected range.
      azimuth = OrientationSensorUtil.normalizeAzimuth(
          (float) Math.toDegrees(values[AZIMUTH]));
      pitch = OrientationSensorUtil.normalizePitch(
          (float) Math.toDegrees(values[PITCH]));
      // Sign change for roll is for compatibility with earlier versions
      // of App Inventor that got orientation sensor information differently.
      roll = OrientationSensorUtil.normalizeRoll(
          (float) -Math.toDegrees(values[ROLL]));

      // Adjust pitch and roll for phone rotation (e.g., landscape)
      int rotation = getScreenRotation();
      switch(rotation) {
        case Surface.ROTATION_0:  // normal rotation
          break;
        case Surface.ROTATION_90:  // phone is turned 90 degrees counter-clockwise
          float temp = -pitch;
          pitch = -roll;
          roll = temp;
          break;
        case Surface.ROTATION_180: // phone is rotated 180 degrees
          roll = -roll;
          break;
        case Surface.ROTATION_270:  // phone is turned 90 degrees clockwise
          temp = pitch;
          pitch = roll;
          roll = temp;
          break;
        default:
          Log.e(LOG_TAG, "Illegal value for getScreenRotation(): " +
                rotation);
          break;
      }

      // Raise event.
      OrientationChanged(azimuth, pitch, roll);
    }
  }
}
 
开发者ID:mit-cml,项目名称:appinventor-extensions,代码行数:82,代码来源:OrientationSensor.java


注:本文中的android.hardware.SensorManager.getOrientation方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。