2 * Copyright © 2014 Keith Packard <keithp@keithp.com>
4 * This program is free software; you can redistribute it and/or modify
5 * it under the terms of the GNU General Public License as published by
6 * the Free Software Foundation; version 2 of the License.
8 * This program is distributed in the hope that it will be useful, but
9 * WITHOUT ANY WARRANTY; without even the implied warranty of
10 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
11 * General Public License for more details.
13 * You should have received a copy of the GNU General Public License along
14 * with this program; if not, write to the Free Software Foundation, Inc.,
15 * 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 package org.altusmetrum.altoslib_8;
20 public class AltosRotation {
21 private AltosQuaternion rotation;
23 public double tilt() {
24 double rotz = rotation.z * rotation.z - rotation.y * rotation.y - rotation.x * rotation.x + rotation.r * rotation.r;
26 double tilt = Math.acos(rotz) * 180.0 / Math.PI;
30 public void rotate(double dt, double x, double y, double z) {
31 AltosQuaternion rot = AltosQuaternion.half_euler(x * dt / 2.0, y * dt / 2.0, z * dt / 2.0);
32 rotation = rot.multiply(rotation).normalize();
35 /* Clone an existing rotation value */
36 public AltosRotation (AltosRotation old) {
37 this.rotation = new AltosQuaternion(old.rotation);
40 /* Create a new rotation value given an acceleration vector pointing down */
41 public AltosRotation(double x,
44 int pad_orientation) {
45 AltosQuaternion orient = AltosQuaternion.vector(x, y, z).normalize();
46 double sky = pad_orientation == 0 ? 1 : -1;
47 AltosQuaternion up = new AltosQuaternion(0, 0, 0, sky);
48 rotation = up.vectors_to_rotation(orient);