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


Java SensorManager.getRotationMatrix方法代码示例

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


在下文中一共展示了SensorManager.getRotationMatrix方法的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: 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

示例3: 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

示例4: 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

示例5: onSensorChanged

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

    // we received a sensor event. it is a good practice to check
    // that we received the proper event
    if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD) {
        System.arraycopy(event.values, 0, magnitudeValues, 0, magnitudeValues.length);
    } else if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER) {
        System.arraycopy(event.values, 0, accelerometerValues, 0, accelerometerValues.length);
    }

    if (magnitudeValues != null && accelerometerValues != null) {
        // Fuse accelerometer with compass
        SensorManager.getRotationMatrix(currentOrientationRotationMatrix.matrix, inclinationValues, accelerometerValues,
                magnitudeValues);
        // Transform rotation matrix to quaternion
        currentOrientationQuaternion.setRowMajor(currentOrientationRotationMatrix.matrix);
    }
}
 
开发者ID:peter10110,项目名称:Android-SteamVR-controller,代码行数:20,代码来源:AccelerometerCompassProvider.java

示例6: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
public void onSensorChanged(SensorEvent sensorEvent) {
    switch (sensorEvent.sensor.getType()) {
        case 1:
            this.g4 = sensorEvent.values;
            break;
        case 2:
            this.g8 = sensorEvent.values;
            break;
    }
    if (this.g4 != null && this.g8 != null) {
        float[] fArr = new float[9];
        if (SensorManager.getRotationMatrix(fArr, null, this.g4, this.g8)) {
            float[] fArr2 = new float[3];
            SensorManager.getOrientation(fArr, fArr2);
            g5 = (float) Math.toDegrees((double) fArr2[0]);
            g5 = (float) Math.floor(g5 >= 0.0f ? (double) g5 : (double) (g5 + 360.0f));
        }
    }
}
 
开发者ID:JackChan1999,项目名称:boohee_v5.6,代码行数:20,代码来源:af.java

示例7: calculateOrientationAccelMag

import android.hardware.SensorManager; //导入方法依赖的package包/类
protected void calculateOrientationAccelMag()
{
	// 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.
	if (SensorManager.getRotationMatrix(rmOrientationAccelMag, null,
			vAcceleration, vMagnetic))	//rmOrientationAccelMag涓烘棆杞煩闃点��
	{
		SensorManager.getOrientation(rmOrientationAccelMag,
				vOrientationAccelMag);	//vOrientationAccelMag涓鸿绠楁墍寰楃殑璁惧鏂瑰悜銆�

		isOrientationValidAccelMag = true;
	}
}
 
开发者ID:HyfUestc,项目名称:PDR,代码行数:18,代码来源:Orientation.java

示例8: 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

示例9: 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

示例10: 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,代码来源:MainActivity.java

示例11: 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

示例12: updateScreenOrientation

import android.hardware.SensorManager; //导入方法依赖的package包/类
private void updateScreenOrientation() {
    float[] R = new float[9];
    float[] I = new float[9];
    SensorManager.getRotationMatrix(R, I, gravity, geomagnetic);
    float[] orientation = new float[3];
    SensorManager.getOrientation(R, orientation);

    //device rotation angle = pitch (first value) [clockwise from horizontal]

    double pitch = orientation[1] / 2 / Math.PI * 360.0;
    double roll = orientation[2] / 2 / Math.PI * 360.0;
    double azimuth = orientation[0] / 2 / Math.PI * 360.0;

    //If the phone is too close to the ground, don't update
    if (Math.abs(roll) <= ROLL_MINIMUM)
        return;

    ScreenOrientation current = screenOrientation;

    if (Math.abs(pitch) <= PITCH_TOLERANCE)
        if (roll > 0.0f)
            current = ScreenOrientation.LANDSCAPE_REVERSE;
        else
            current = ScreenOrientation.LANDSCAPE;
    else if (Math.abs(pitch) >= PITCH_TOLERANCE_HIGH)
        if (pitch > 0.0f)
            current = ScreenOrientation.PORTRAIT_REVERSE;
        else
            current = ScreenOrientation.PORTRAIT;

    screenOrientation = current;
}
 
开发者ID:ykarim,项目名称:FTC2016,代码行数:33,代码来源:Sensors.java

示例13: 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

示例14: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Override
public void onSensorChanged(SensorEvent event)
{
	displayCleanValues();                                                                       // display clean value of x,y,z accelerometer

	if (event.sensor == mGyroscope)                                                             // Reading Gyroscope
	{
		gyro = event.values[1];                                                       			// Reading Gyroscope in Y -axies
	}
	else if (event.sensor == mAccelerometer)                                                    // Reading Accelerometer
	{
		System.arraycopy(event.values, 0, mLastAccelerometer, 0, event.values.length);
		mLastAccelerometerSet = true;
		Accel_X = Math.abs(event.values[0]);                                                    // Reading Acceleration in X-axis
		Accel_Y = Math.abs(event.values[1]);                                                    // Reading Acceleration in Y-axis
		Accel_Z = Math.abs(event.values[2]);                                                    // Reading Acceleration in Z-axis
	}
	else if (event.sensor == mMagnetometer)                                                     // Reading Magnetometer
	{
		System.arraycopy(event.values, 0, mLastMagnetometer, 0, event.values.length);
		mLastMagnetometerSet = true;
	}

	if (mLastAccelerometerSet && mLastMagnetometerSet)
	{
		SensorManager.getRotationMatrix(mR, null, mLastAccelerometer, mLastMagnetometer);
		SensorManager.getOrientation(mR, mOrientation);

		azimuthInRadians = mOrientation[0];                                                     // Reading Azimuth in radians
		float azimuthInDegress = (float)(Math.toDegrees(azimuthInRadians)+360)%360;             // Converting Azimuth to degrees
		azimuth = azimuthInDegress;
	}

	adjust_values();                                                                            // Adjusting the reading of accelerometer and produce average values
	calculate_pdr();               			                                                    // Calculating position by Pedestrian Dead Reckoning (PDR)
	displayCurrentValues();                                                                     // Display the current x,y,z accelerometer values

	zigbee_correction_total();

}
 
开发者ID:atarek92,项目名称:Intelligent_Indoor_Localization_System,代码行数:41,代码来源:J2xxHyperTerm.java

示例15: 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


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