Commit cb560fb1 authored by Arnaud Aliès's avatar Arnaud Aliès Committed by John David Taylor

Added advanced setting to rotate horizon by 90 degrees (for devices with...

Added advanced setting to rotate horizon by 90 degrees (for devices with locked orientation, such as (#161)

smartglasses, or android pc)
parent a18f2a19
......@@ -52,6 +52,7 @@ public class ApplicationConstants {
public static final String SENSOR_DAMPING_STANDARD = "STANDARD";
public static final String SENSOR_DAMPING_PREF_KEY = "sensor_damping";
public static final String REVERSE_MAGNETIC_Z_PREFKEY = "reverse_magnetic_z";
public static final String ROTATE_HORIZON_PREFKEY = "rotate_horizon";
// End Preference Keys
......
......@@ -107,11 +107,14 @@ public class DynamicStarMapActivity extends InjectableActivity
private static final class RendererModelUpdateClosure extends AbstractUpdateClosure {
private RendererController rendererController;
private AstronomerModel model;
private boolean horizontalRotation;
public RendererModelUpdateClosure(AstronomerModel model,
RendererController rendererController) {
RendererController rendererController, SharedPreferences sharedPreferences) {
this.model = model;
this.rendererController = rendererController;
this.horizontalRotation = sharedPreferences.getBoolean(ApplicationConstants.ROTATE_HORIZON_PREFKEY, false);
model.setHorizontalRotation(this.horizontalRotation);
}
@Override
......@@ -562,6 +565,8 @@ public class DynamicStarMapActivity extends InjectableActivity
}
setAutoMode(autoMode);
break;
case ApplicationConstants.ROTATE_HORIZON_PREFKEY:
model.setHorizontalRotation(sharedPreferences.getBoolean(key, false));
default:
return;
}
......@@ -636,7 +641,7 @@ public class DynamicStarMapActivity extends InjectableActivity
rendererController = new RendererController(renderer, skyView);
// The renderer will now call back every frame to get model updates.
rendererController.addUpdateClosure(
new RendererModelUpdateClosure(model, rendererController));
new RendererModelUpdateClosure(model, rendererController, sharedPreferences));
Log.i(TAG, "Setting layers @ " + System.currentTimeMillis());
layerManager.registerWithRenderer(rendererController);
......
......@@ -115,6 +115,8 @@ public interface AstronomerModel {
void setFieldOfView(float degrees);
void setHorizontalRotation(boolean value);
float getMagneticCorrection();
/**
......
......@@ -75,6 +75,8 @@ public class AstronomerModelImpl implements AstronomerModel {
private static final String TAG = MiscUtil.getTag(AstronomerModelImpl.class);
private static final Vector3 POINTING_DIR_IN_PHONE_COORDS = new Vector3(0, 0, -1);
private static final Vector3 SCREEN_UP_IN_PHONE_COORDS = new Vector3(0, 1, 0);
private static final Vector3 SCREEN_DOWN_IN_PHONE_COORDS = new Vector3(1, 0, 0);
private Vector3 screenInPhoneCoords = SCREEN_UP_IN_PHONE_COORDS;
private static final Vector3 AXIS_OF_EARTHS_ROTATION = new Vector3(0, 0, 1);
private static final long MINIMUM_TIME_BETWEEN_CELESTIAL_COORD_UPDATES_MILLIS = 60000L;
......@@ -127,6 +129,16 @@ public class AstronomerModelImpl implements AstronomerModel {
setMagneticDeclinationCalculator(magneticDeclinationCalculator);
}
@Override
public void setHorizontalRotation(boolean value) {
if (value) {
screenInPhoneCoords = SCREEN_DOWN_IN_PHONE_COORDS;
}
else {
screenInPhoneCoords = SCREEN_UP_IN_PHONE_COORDS;
}
}
@Override
public void setAutoUpdatePointing(boolean autoUpdatePointing) {
this.autoUpdatePointing = autoUpdatePointing;
......@@ -255,7 +267,7 @@ public class AstronomerModelImpl implements AstronomerModel {
Matrix33 transform = matrixMultiply(axesMagneticCelestialMatrix, axesPhoneInverseMatrix);
Vector3 viewInSpaceSpace = matrixVectorMultiply(transform, POINTING_DIR_IN_PHONE_COORDS);
Vector3 screenUpInSpaceSpace = matrixVectorMultiply(transform, SCREEN_UP_IN_PHONE_COORDS);
Vector3 screenUpInSpaceSpace = matrixVectorMultiply(transform, screenInPhoneCoords);
pointing.updateLineOfSight(viewInSpaceSpace);
pointing.updatePerpendicular(screenUpInSpaceSpace);
......
......@@ -475,4 +475,6 @@
<string name="whats_new_dialog_title">What\'s new</string>
<string name="disable_gyro_preference_title">Disable gyroscope</string>
<string name="disable_gyro_preference_summary">Not all devices have a gyro - if yours does then you\'ll get better results with it enabled and this box unchecked. On the other hand if your device does not have a gyro then Sky Map will probably not work if you uncheck this box.</string>
<string name="rotate_horizon_preference_title">Rotate horizon</string>
<string name="rotate_horizon_preference_summary">Rotate by 90 degree horizon (for screens with forced landscape, such as smartglasses)</string>
</resources>
......@@ -79,6 +79,11 @@
android:title="@string/sensor_reverse_preference_title"
android:summary="@string/sensor_reverse_preference_summary"
android:key="reverse_magnetic_z"/>
<CheckBoxPreference
android:defaultValue="false"
android:title="@string/rotate_horizon_preference_title"
android:summary="@string/rotate_horizon_preference_summary"
android:key="rotate_horizon"/>
</PreferenceCategory>
</PreferenceScreen>
</PreferenceScreen>
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment