diff --git a/app/src/main/java/com/google/android/stardroid/activities/DynamicStarMapActivity.java b/app/src/main/java/com/google/android/stardroid/activities/DynamicStarMapActivity.java index 1ec11e328..93b30134b 100644 --- a/app/src/main/java/com/google/android/stardroid/activities/DynamicStarMapActivity.java +++ b/app/src/main/java/com/google/android/stardroid/activities/DynamicStarMapActivity.java @@ -127,8 +127,8 @@ public void run() { rendererController.queueSetViewOrientation(directionX, directionY, directionZ, upX, upY, upZ); - Vector3 acceleration = model.getPhoneAcceleration(); - rendererController.queueTextAngle(MathUtil.atan2(-acceleration.x, -acceleration.y)); + Vector3 up = model.getPhoneUpDirection(); + rendererController.queueTextAngle(MathUtil.atan2(up.x, up.y)); rendererController.queueViewerUpDirection(model.getZenith().copy()); float fieldOfView = model.getFieldOfView(); @@ -563,8 +563,7 @@ public void onSharedPreferenceChanged(SharedPreferences sharedPreferences, Strin setAutoMode(autoMode); break; case ApplicationConstants.SHARED_PREFERENCE_EXPERIMENTAL_USE_GYRO: - boolean useGyro = sharedPreferences.getBoolean(key, false); - model.setUseRotationVector(useGyro); + // Do nothing - the sensor controller will take care of it. default: return; } diff --git a/app/src/main/java/com/google/android/stardroid/control/AstronomerModel.java b/app/src/main/java/com/google/android/stardroid/control/AstronomerModel.java index 4cf52023f..56ad630b6 100644 --- a/app/src/main/java/com/google/android/stardroid/control/AstronomerModel.java +++ b/app/src/main/java/com/google/android/stardroid/control/AstronomerModel.java @@ -28,10 +28,6 @@ * @author John Taylor */ public interface AstronomerModel { - - - void setUseRotationVector(boolean useRotationVector); - /** * A POJO to hold the user's view direction. * @@ -156,7 +152,7 @@ void updateLineOfSight(Vector3 newLineOfSight) { * *

The returned object should not be modified. */ - Vector3 getPhoneAcceleration(); + Vector3 getPhoneUpDirection(); /** * Sets the acceleration and magnetic field in the phone frame. diff --git a/app/src/main/java/com/google/android/stardroid/control/AstronomerModelImpl.java b/app/src/main/java/com/google/android/stardroid/control/AstronomerModelImpl.java index 4825a6ba3..500ac6737 100644 --- a/app/src/main/java/com/google/android/stardroid/control/AstronomerModelImpl.java +++ b/app/src/main/java/com/google/android/stardroid/control/AstronomerModelImpl.java @@ -96,6 +96,8 @@ public class AstronomerModelImpl implements AstronomerModel { /** The sensor acceleration in the phone's coordinate system. */ private Vector3 acceleration = ApplicationConstants.INITIAL_DOWN.copy(); + private Vector3 upPhone = Geometry.scaleVector(acceleration, -1); + /** The sensor magnetic field in the phone's coordinate system. */ private Vector3 magneticField = ApplicationConstants.INITIAL_SOUTH.copy(); @@ -163,8 +165,8 @@ public void setLocation(LatLong location) { } @Override - public Vector3 getPhoneAcceleration() { - return acceleration; + public Vector3 getPhoneUpDirection() { + return upPhone; } private static final float TOL = 0.01f; @@ -303,7 +305,6 @@ private void calculateLocalNorthAndUpInCelestialCoords(boolean forceUpdate) { */ private void calculateLocalNorthAndUpInPhoneCoordsFromSensors() { Vector3 magneticNorthPhone; - Vector3 upPhone; Vector3 magneticEastPhone; if (useRotationVector) { float[] rotationMatrix = new float[9]; @@ -327,7 +328,6 @@ private void calculateLocalNorthAndUpInPhoneCoordsFromSensors() { upPhone = scaleVector(down, -1); magneticEastPhone = vectorProduct(magneticNorthPhone, upPhone); } - // The matrix is orthogonal, so transpose it to find its inverse. // Easiest way to do that is to construct it from row vectors instead // of column vectors. @@ -367,9 +367,4 @@ public void setClock(Clock clock) { public long getTimeMillis() { return clock.getTimeInMillisSinceEpoch(); } - - @Override - public void setUseRotationVector(boolean useRotationVector) { - this.useRotationVector = useRotationVector; - } } diff --git a/app/src/main/java/com/google/android/stardroid/util/Geometry.java b/app/src/main/java/com/google/android/stardroid/util/Geometry.java index 923b7c655..28ac56c7a 100644 --- a/app/src/main/java/com/google/android/stardroid/util/Geometry.java +++ b/app/src/main/java/com/google/android/stardroid/util/Geometry.java @@ -14,14 +14,14 @@ package com.google.android.stardroid.util; -import java.util.Date; - import com.google.android.stardroid.units.GeocentricCoordinates; import com.google.android.stardroid.units.LatLong; import com.google.android.stardroid.units.Matrix33; import com.google.android.stardroid.units.RaDec; import com.google.android.stardroid.units.Vector3; +import java.util.Date; + /** * Utilities for working with angles, distances, matrices, and time. * @@ -77,7 +77,7 @@ public static Vector3 vectorProduct(Vector3 v1, Vector3 v2) { } /** - * Scales the vector by the given amount + * Scales the vector by the given amount and returns a new vector. */ public static Vector3 scaleVector(Vector3 v, float scale) { return new Vector3 (scale * v.x, scale * v.y, scale * v.z);