X-Git-Url: https://git.gag.com/?a=blobdiff_plain;f=altoslib%2FAltosRotation.java;h=4b7ab407514331e6b3bb62ee117a0a78f62d62c7;hb=1b5ea911049a8afae6af475a4a2bf62a6e3aa57b;hp=49225f77db80d34cf82199027944faebddc5fff4;hpb=4231d68bae69d9a7d1f52205002db452cd5f986d;p=fw%2Faltos diff --git a/altoslib/AltosRotation.java b/altoslib/AltosRotation.java index 49225f77..4b7ab407 100644 --- a/altoslib/AltosRotation.java +++ b/altoslib/AltosRotation.java @@ -15,9 +15,9 @@ * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA. */ -package org.altusmetrum.altoslib_6; +package org.altusmetrum.altoslib_11; -public class AltosRotation { +public class AltosRotation implements AltosHashable, 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,37 @@ public class AltosRotation { AltosQuaternion up = new AltosQuaternion(0, 0, 0, sky); rotation = up.vectors_to_rotation(orient); } + + public AltosHashSet hashSet() { + AltosHashSet h = new AltosHashSet(); + + h.putHashable("rotation", rotation); + return h; + } + + public AltosJson json() { + return rotation.json(); + } + + public AltosRotation(AltosHashSet h) { + rotation = new AltosQuaternion(h.getHash("rotation")); + } + + public static AltosRotation fromHashSet(AltosHashSet h, AltosRotation def) { + if (h == null) + return def; + + return new AltosRotation(h); + } + + public AltosRotation(AltosJson j) { + rotation = new AltosQuaternion(j); + } + + public static AltosRotation fromJson(AltosJson j, AltosRotation def) { + if (j == null) + return def; + + return new AltosRotation(j); + } }