當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。