summaryrefslogtreecommitdiffhomepage
path: root/facetracknoir
diff options
context:
space:
mode:
authorStanislaw Halik <sthalik@misaki.pl>2013-06-27 16:19:25 +0200
committerStanislaw Halik <sthalik@misaki.pl>2013-06-27 16:19:25 +0200
commitcb1fb94c79e44219ba15fafdbcad1cd0ef613726 (patch)
tree77e9285e22528e116293d0b076b481e76387ffe7 /facetracknoir
parent1535f956a73ea3be78bffa82a224ab7bcc6dd14d (diff)
parentd4e2f529a3e0c0c496eab4b7745fc320de8805c9 (diff)
Merge branch 'master' of github.com:opentrack/opentrack
Conflicts: ftnoir_tracker_rift/ftnoir_tracker_rift.cpp
Diffstat (limited to 'facetracknoir')
-rw-r--r--facetracknoir/facetracknoir.rc2
-rw-r--r--facetracknoir/rotation.cpp35
-rw-r--r--facetracknoir/rotation.h53
3 files changed, 49 insertions, 41 deletions
diff --git a/facetracknoir/facetracknoir.rc b/facetracknoir/facetracknoir.rc
index fcae12b3..655baa9d 100644
--- a/facetracknoir/facetracknoir.rc
+++ b/facetracknoir/facetracknoir.rc
@@ -1,2 +1,2 @@
-#include "resource.h"
+#include <windows.h>
IDI_ICON1 ICON "facetracknoir.ico"
diff --git a/facetracknoir/rotation.cpp b/facetracknoir/rotation.cpp
index f6d16d2d..1a6e1e8e 100644
--- a/facetracknoir/rotation.cpp
+++ b/facetracknoir/rotation.cpp
@@ -7,42 +7,9 @@
#include "rotation.h"
-#include <cmath>
-// ----------------------------------------------------------------------------
-Rotation Rotation::inv()
-{
- return Rotation(a,-b,-c,-d);
-}
-// conversions
-// see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
-void Rotation::fromEuler(double yaw, double pitch, double roll)
-{
- double sin_phi = sin(roll/2.0);
- double cos_phi = cos(roll/2.0);
- double sin_the = sin(pitch/2.0);
- double cos_the = cos(pitch/2.0);
- double sin_psi = sin(yaw/2.0);
- double cos_psi = cos(yaw/2.0);
+// ----------------------------------------------------------------------------
- a = cos_phi*cos_the*cos_psi + sin_phi*sin_the*sin_psi;
- b = sin_phi*cos_the*cos_psi - cos_phi*sin_the*sin_psi;
- c = cos_phi*sin_the*cos_psi + sin_phi*cos_the*sin_psi;
- d = cos_phi*cos_the*sin_psi - sin_phi*sin_the*cos_psi;
-}
-void Rotation::toEuler(volatile double& yaw, volatile double& pitch, volatile double& roll)
-{
- roll = atan2(2.0*(a*b + c*d), 1.0 - 2.0*(b*b + c*c));
- pitch = asin(2.0*(a*c - b*d));
- yaw = atan2(2.0*(a*d + b*c), 1.0 - 2.0*(c*c + d*d));
-}
-Rotation operator*(const Rotation& A, const Rotation& B)
-{
- return Rotation(A.a*B.a - A.b*B.b - A.c*B.c - A.d*B.d, // quaternion multiplication
- A.a*B.b + A.b*B.a + A.c*B.d - A.d*B.c,
- A.a*B.c - A.b*B.d + A.c*B.a + A.d*B.b,
- A.a*B.d + A.b*B.c - A.c*B.b + A.d*B.a);
-} \ No newline at end of file
diff --git a/facetracknoir/rotation.h b/facetracknoir/rotation.h
index 9dcea285..a1500969 100644
--- a/facetracknoir/rotation.h
+++ b/facetracknoir/rotation.h
@@ -7,25 +7,66 @@
#ifndef ROTATION_H
#define ROTATION_H
-
+#include <cmath>
// ----------------------------------------------------------------------------
class Rotation {
- friend Rotation operator*(const Rotation& A, const Rotation& B);
+
public:
Rotation() : a(1.0),b(0.0),c(0.0),d(0.0) {}
Rotation(double yaw, double pitch, double roll) { fromEuler(yaw, pitch, roll); }
Rotation(double a, double b, double c, double d) : a(a),b(b),c(c),d(d) {}
- Rotation inv(); // inverse
+ Rotation inv(){ // inverse
+ return Rotation(a,-b,-c,-d);
+ }
+
// conversions
- void fromEuler(double yaw, double pitch, double roll);
- void toEuler(volatile double& yaw, volatile double& pitch, volatile double& roll);
+ // see http://en.wikipedia.org/wiki/Conversion_between_quaternions_and_Euler_angles
+ void fromEuler(double yaw, double pitch, double roll)
+ {
+ double sin_phi = sin(roll/2.0);
+ double cos_phi = cos(roll/2.0);
+ double sin_the = sin(pitch/2.0);
+ double cos_the = cos(pitch/2.0);
+ double sin_psi = sin(yaw/2.0);
+ double cos_psi = cos(yaw/2.0);
+
+ a = cos_phi*cos_the*cos_psi + sin_phi*sin_the*sin_psi;
+ b = sin_phi*cos_the*cos_psi - cos_phi*sin_the*sin_psi;
+ c = cos_phi*sin_the*cos_psi + sin_phi*cos_the*sin_psi;
+ d = cos_phi*cos_the*sin_psi - sin_phi*sin_the*cos_psi;
+ }
+
+ void toEuler(double& yaw, double& pitch, double& roll)
+ {
+ roll = atan2(2.0*(a*b + c*d), 1.0 - 2.0*(b*b + c*c));
+ pitch = asin(2.0*(a*c - b*d));
+ yaw = atan2(2.0*(a*d + b*c), 1.0 - 2.0*(c*c + d*d));
+ }
+/* const Rotation operator*(const Rotation& A, const Rotation& B)
+ {
+ return Rotation(A.a*B.a - A.b*B.b - A.c*B.c - A.d*B.d, // quaternion multiplication
+ A.a*B.b + A.b*B.a + A.c*B.d - A.d*B.c,
+ A.a*B.c - A.b*B.d + A.c*B.a + A.d*B.b,
+ A.a*B.d + A.b*B.c - A.c*B.b + A.d*B.a);
+ }*/
+
+
+ const Rotation operator*(const Rotation& B)
+ {
+ const Rotation& A = *this;
+ return Rotation(A.a*B.a - A.b*B.b - A.c*B.c - A.d*B.d, // quaternion multiplication
+ A.a*B.b + A.b*B.a + A.c*B.d - A.d*B.c,
+ A.a*B.c - A.b*B.d + A.c*B.a + A.d*B.b,
+ A.a*B.d + A.b*B.c - A.c*B.b + A.d*B.a);
+ }
+
protected:
double a,b,c,d; // quaternion coefficients
};
-Rotation operator*(const Rotation& A, const Rotation& B); // composition of rotations
+
#endif //ROTATION_H