Skip to content
This repository has been archived by the owner on Jun 21, 2023. It is now read-only.

Commit

Permalink
clean up compass engine comments and duplication
Browse files Browse the repository at this point in the history
  • Loading branch information
LukasPaczos committed Apr 23, 2020
1 parent 6f6f146 commit 161abf8
Showing 1 changed file with 8 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -109,7 +109,6 @@ public void onSensorChanged(@NonNull SensorEvent event) {
// Update the heading, even if the sensor is unreliable.
// This makes it possible to use a different indicator for the unreliable case,
// instead of just changing the RenderMode to NORMAL.
//return;
}
if (event.sensor.getType() == Sensor.TYPE_ROTATION_VECTOR) {
rotationVectorValue = getRotationVectorFromSensorEvent(event);
Expand Down Expand Up @@ -183,8 +182,7 @@ private void updateOrientation() {

if (orientation[1] < -Math.PI / 4) {
// The pitch is less than -45 degrees.
// Remap the axes as if the device screen was the instrument panel,
// and adjust the rotation matrix for the device orientation.
// Remap the axes as if the device screen was the instrument panel.
switch (windowManager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
worldAxisForDeviceAxisX = SensorManager.AXIS_Z;
Expand All @@ -204,16 +202,9 @@ private void updateOrientation() {
worldAxisForDeviceAxisY = SensorManager.AXIS_Z;
break;
}

SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
worldAxisForDeviceAxisY, adjustedRotationMatrix);

// Transform rotation matrix into azimuth/pitch/roll
SensorManager.getOrientation(adjustedRotationMatrix, orientation);
} else if (orientation[1] > Math.PI / 4) {
// The pitch is larger than 45 degrees.
// Remap the axes as if the device screen was upside down and facing back,
// and adjust the rotation matrix for the device orientation.
// Remap the axes as if the device screen was upside down and facing back.
switch (windowManager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Z;
Expand All @@ -233,16 +224,9 @@ private void updateOrientation() {
worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Z;
break;
}

SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
worldAxisForDeviceAxisY, adjustedRotationMatrix);

// Transform rotation matrix into azimuth/pitch/roll
SensorManager.getOrientation(adjustedRotationMatrix, orientation);
} else if (Math.abs(orientation[2]) > Math.PI / 2) {
// The roll is less than -90 degrees, or is larger than 90 degrees.
// Remap the axes as if the device screen was face down,
// and adjust the rotation matrix for the device orientation.
// Remap the axes as if the device screen was face down.
switch (windowManager.getDefaultDisplay().getRotation()) {
case Surface.ROTATION_90:
worldAxisForDeviceAxisX = SensorManager.AXIS_MINUS_Y;
Expand All @@ -262,13 +246,13 @@ private void updateOrientation() {
worldAxisForDeviceAxisY = SensorManager.AXIS_MINUS_Y;
break;
}
}

SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
worldAxisForDeviceAxisY, adjustedRotationMatrix);
SensorManager.remapCoordinateSystem(rotationMatrix, worldAxisForDeviceAxisX,
worldAxisForDeviceAxisY, adjustedRotationMatrix);

// Transform rotation matrix into azimuth/pitch/roll
SensorManager.getOrientation(adjustedRotationMatrix, orientation);
}
// Transform rotation matrix into azimuth/pitch/roll
SensorManager.getOrientation(adjustedRotationMatrix, orientation);

// The x-axis is all we care about here.
notifyCompassChangeListeners((float) Math.toDegrees(orientation[0]));
Expand Down

0 comments on commit 161abf8

Please sign in to comment.