Skip to content

Commit

Permalink
Fixed the text orientation in gyroscope mode.
Browse files Browse the repository at this point in the history
  • Loading branch information
jaydeetay committed Jul 12, 2016
1 parent 345d440 commit 0ab0be1
Show file tree
Hide file tree
Showing 4 changed files with 11 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,10 +28,6 @@
* @author John Taylor
*/
public interface AstronomerModel {


void setUseRotationVector(boolean useRotationVector);

/**
* A POJO to hold the user's view direction.
*
Expand Down Expand Up @@ -156,7 +152,7 @@ void updateLineOfSight(Vector3 newLineOfSight) {
*
* <p>The returned object should not be modified.
*/
Vector3 getPhoneAcceleration();
Vector3 getPhoneUpDirection();

/**
* Sets the acceleration and magnetic field in the phone frame.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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();

Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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];
Expand All @@ -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.
Expand Down Expand Up @@ -367,9 +367,4 @@ public void setClock(Clock clock) {
public long getTimeMillis() {
return clock.getTimeInMillisSinceEpoch();
}

@Override
public void setUseRotationVector(boolean useRotationVector) {
this.useRotationVector = useRotationVector;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 0ab0be1

Please sign in to comment.