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


Java SensorManager.remapCoordinateSystem方法代码示例

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


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

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

示例2: interpretSensorEvent

import android.hardware.SensorManager; //导入方法依赖的package包/类
@SuppressWarnings("SuspiciousNameCombination")
public float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) {
    if (event == null) {
        return null;
    }

    float[] rotationVector = getRotationVectorFromSensorEvent(event);

    if (!mTargeted) {
        setTargetVector(rotationVector);
        return null;
    }

    SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector);

    final int rotation = ((WindowManager) context
            .getSystemService(Context.WINDOW_SERVICE))
            .getDefaultDisplay()
            .getRotation();

    if (rotation == Surface.ROTATION_0) {
        SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix);
    } else {
        switch (rotation) {
            case Surface.ROTATION_90:
                SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_Y, AXIS_MINUS_X, mOrientedRotationMatrix);
                break;

            case Surface.ROTATION_180:
                SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_X, AXIS_MINUS_Y, mOrientedRotationMatrix);
                break;

            case Surface.ROTATION_270:
                SensorManager.remapCoordinateSystem(mRotationMatrix, AXIS_MINUS_Y, AXIS_X, mOrientedRotationMatrix);
                break;
        }

        SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix);
    }

    for (int i = 0; i < mTiltVector.length; i++) {
        mTiltVector[i] /= Math.PI;

        mTiltVector[i] *= mTiltSensitivity;

        if (mTiltVector[i] > 1) {
            mTiltVector[i] = 1f;
        } else if (mTiltVector[i] < -1) {
            mTiltVector[i] = -1f;
        }
    }

    return mTiltVector;
}
 
开发者ID:alibaba,项目名称:LuaViewPlayground,代码行数:55,代码来源:SensorInterpreter.java

示例3: updateOrientation

import android.hardware.SensorManager; //导入方法依赖的package包/类
@SuppressWarnings("SuspiciousNameCombination")
private void updateOrientation(float[] rotationVector) {
  float[] rotationMatrix = new float[9];
  SensorManager.getRotationMatrixFromVector(rotationMatrix, rotationVector);

  final int worldAxisForDeviceAxisX;
  final int worldAxisForDeviceAxisY;

  // Remap the axes as if the device screen was the instrument panel,
  // and adjust the rotation matrix for the device orientation.
  switch (windowManager.getDefaultDisplay().getRotation()) {
    case Surface.ROTATION_90:
      worldAxisForDeviceAxisX = SensorManager.AXIS_Z;
      worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_X;
      break;
    case Surface.ROTATION_180:
      worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_X;
      worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Z;
      break;
    case Surface.ROTATION_270:
      worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Z;
      worldAxisForDeviceAxisY = SensorManager.AXIS_X;
      break;
    case Surface.ROTATION_0:
    default:
      worldAxisForDeviceAxisX = SensorManager.AXIS_X;
      worldAxisForDeviceAxisY = SensorManager.AXIS_Z;
      break;
  }

  float[] adjustedRotationMatrix = new float[9];
  SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
    worldAxisForDeviceAxisY, adjustedRotationMatrix);

  // Transform rotation matrix into azimuth/pitch/roll
  float[] orientation = new float[3];
  SensorManager.getOrientation(adjustedRotationMatrix, orientation);

  // The x-axis is all we care about here.
  internalCompassListener.onCompassChanged((float) Math.toDegrees(orientation[0]));
  for (CompassListener compassListener : compassListeners) {
    compassListener.onCompassChanged((float) Math.toDegrees(orientation[0]));
  }
}
 
开发者ID:mapbox,项目名称:mapbox-plugins-android,代码行数:45,代码来源:CompassManager.java

示例4: interpretSensorEvent

import android.hardware.SensorManager; //导入方法依赖的package包/类
@Nullable
@SuppressWarnings("SuspiciousNameCombination")
private float[] interpretSensorEvent(@NonNull Context context, @Nullable SensorEvent event) {
    if (event == null) {
        return null;
    }

    float[] rotationVector = getRotationVectorFromSensorEvent(event);

    if (!mTargeted) {
        setTargetVector(rotationVector);
        return null;
    }

    SensorManager.getRotationMatrixFromVector(mRotationMatrix, rotationVector);

    final int rotation =
            ((WindowManager) context.getSystemService(Context.WINDOW_SERVICE)).getDefaultDisplay()
                    .getRotation();

    if (rotation == Surface.ROTATION_0) {
        SensorManager.getAngleChange(mTiltVector, mRotationMatrix, mTargetMatrix);
    } else {
        switch (rotation) {
            case Surface.ROTATION_90:
                SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_Y,
                        SensorManager.AXIS_MINUS_X, mOrientedRotationMatrix);
                break;

            case Surface.ROTATION_180:
                SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_X,
                        SensorManager.AXIS_MINUS_Y, mOrientedRotationMatrix);
                break;

            case Surface.ROTATION_270:
                SensorManager.remapCoordinateSystem(mRotationMatrix, SensorManager.AXIS_MINUS_Y,
                        SensorManager.AXIS_X, mOrientedRotationMatrix);
                break;
            default:
                break;
        }

        SensorManager.getAngleChange(mTiltVector, mOrientedRotationMatrix, mTargetMatrix);
    }

    for (int i = 0; i < mTiltVector.length; i++) {
        mTiltVector[i] /= Math.PI;

        mTiltVector[i] *= mTiltSensitivity;

        if (mTiltVector[i] > 1) {
            mTiltVector[i] = 1f;
        } else if (mTiltVector[i] < -1) {
            mTiltVector[i] = -1f;
        }
    }

    return mTiltVector;
}
 
开发者ID:hidetag,项目名称:CheckIn,代码行数:60,代码来源:SensorTranslationUpdater.java

示例5: onSensorChanged

import android.hardware.SensorManager; //导入方法依赖的package包/类
@SuppressWarnings("deprecation")
@Override
public void onSensorChanged(SensorEvent event) 
{
	if(m_useDeprecatedOrientationMethod)
	{
		if (event.sensor.getType() == Sensor.TYPE_ORIENTATION)
		{
			float smoothing = 0.6f;
			float heading = event.values[0];
        	if (Float.isNaN(heading)) // Fix MPLY-4888
        	{
        		return;
        	}
			float newAzimuth = adjustHeadingForDeviceOrientation(heading);
			
			if(Math.abs(newAzimuth - m_azimuthDegrees) >= 180)
			{
				if(newAzimuth > m_azimuthDegrees)
				{
					m_azimuthDegrees += 360.0f;
				}
				else
				{
					newAzimuth += 360.0f;
				}
			}
			m_azimuthDegrees = (float) ((newAzimuth * smoothing) + (m_azimuthDegrees * (1.0 - smoothing)));     
			m_azimuthDegrees %= 360.0f;
			m_hasAzimuthAngle = true;
			return;
		}
	}
	else
	{	
		if (event.sensor.getType() == Sensor.TYPE_ACCELEROMETER)
		{
			m_gravity = event.values.clone();
		}
	
		if (event.sensor.getType() == Sensor.TYPE_MAGNETIC_FIELD)
		{
			m_geomagnetic = event.values.clone();
		}

		if (m_gravity != null && m_geomagnetic != null) 
		{
			float R[] = new float[9];
			float I[] = new float[9];
			boolean success = SensorManager.getRotationMatrix(R, I, m_gravity, m_geomagnetic);
			if(success)
			{ 
				float remap[] = new float[9];
				SensorManager.remapCoordinateSystem(R, SensorManager.AXIS_X, SensorManager.AXIS_Z, remap);
				
				float orientation[] = new float[3];
				SensorManager.getOrientation(remap, orientation);

				m_hasAzimuthAngle = true;
				addResultForFiltering(orientation[0]);                
			}
		}
	}
}
 
开发者ID:wrld3d,项目名称:android-api,代码行数:65,代码来源:HeadingService.java

示例6: parseRoatationMatrix

import android.hardware.SensorManager; //导入方法依赖的package包/类
@SuppressWarnings("SuspiciousNameCombination")
double[] parseRoatationMatrix(float[] rotationMatrix) {
    // Remap for pitch
    SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_X, SensorManager.AXIS_Y, rotationMatrix);

    // Grab pitch
    double pitch = toDegrees(Math.asin(rotationMatrix[7]));

    // Roll can be extracted without problems when pitch is smaller than 70 degrees
    float[] orientationValues = new float[3];
    double roll;
    if (pitch < 70) {
        roll = toDegrees(Math.atan2(-rotationMatrix[6], abs(rotationMatrix[8])));
    } else {
        // Remap axis to extract roll
        SensorManager.remapCoordinateSystem(rotationMatrix, SensorManager.AXIS_Y, SensorManager.AXIS_Z, rotationMatrix);
        SensorManager.getOrientation(rotationMatrix, orientationValues);
        roll = -toDegrees(orientationValues[0]);
    }

    // Normalize roll (0, 90, 0, -90)
    /*if (roll > 90) {
        roll = 180 - roll;
    } else if (roll < -90) {
        roll = -180 - roll;
    }*/
    // TODO Move elsewhere
    if (oldAngle > 150 && roll < -150) {
        baseRoll += 360;
    } else if (oldAngle < -150 && roll > 150) {
        baseRoll -= 360;
    }
    oldAngle = roll;
    roll += baseRoll;

    // Fix cross panic
    if ((oldPitch < 70 && pitch >= 70) || (pitch < 70 && oldPitch >= 70)) {
        deltaCross = roll - oldRoll;
    }
    roll = roll - deltaCross;

    // Update old values
    oldRoll = roll;
    oldPitch = pitch;

    return new double[]{pitch, roll};
}
 
开发者ID:lucasax,项目名称:Zero,代码行数:48,代码来源:RotationParser.java


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