altoslib: Improve AltosState save/restore debugging
[fw/altos] / altoslib / AltosRotation.java
index ad5aca8f7b7dd4e110368ff0d3ebff9094c22587..6db0b541595ce37f51acd0f78c413abd07b72c38 100644 (file)
@@ -15,9 +15,9 @@
  * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
  */
 
-package org.altusmetrum.altoslib_5;
+package org.altusmetrum.altoslib_11;
 
-public class AltosRotation {
+public class AltosRotation implements AltosJsonable {
        private AltosQuaternion         rotation;
 
        public double tilt() {
@@ -28,7 +28,7 @@ public class AltosRotation {
        }
 
        public void rotate(double dt, double x, double y, double z) {
-               AltosQuaternion rot = AltosQuaternion.half_euler(x * dt, y * dt, z * dt);
+               AltosQuaternion rot = AltosQuaternion.half_euler(x * dt / 2.0, y * dt / 2.0, z * dt / 2.0);
                rotation = rot.multiply(rotation).normalize();
        }
 
@@ -47,4 +47,23 @@ public class AltosRotation {
                AltosQuaternion up = new AltosQuaternion(0, 0, 0, sky);
                rotation = up.vectors_to_rotation(orient);
        }
+
+       public AltosRotation(AltosJson j) {
+               rotation = new AltosQuaternion(j);
+       }
+
+       public AltosRotation() {
+               rotation = new AltosQuaternion();
+       }
+
+       public AltosJson json() {
+               return rotation.json();
+       }
+
+       public static AltosRotation fromJson(AltosJson j, AltosRotation def) {
+               if (j == null)
+                       return def;
+
+               return new AltosRotation(j);
+       }
 }