File indexing completed on 2024-04-21 04:05:09

0001 /*
0002     SPDX-FileCopyrightText: 2008 Ian Wadham <iandw.au@gmail.com>
0003 
0004     SPDX-License-Identifier: GPL-2.0-or-later
0005 */
0006 
0007 #ifndef QUATERNION_H
0008 #define QUATERNION_H
0009 
0010 /*
0011   A little library to do quaternion arithmetic.  Adapted from C to C++.
0012   Acknowledgements and thanks to John Darrington and the Gnubik package.
0013 */
0014 
0015 #define DIMENSIONS 4
0016 
0017 typedef float Matrix [DIMENSIONS * DIMENSIONS];
0018 
0019 class Quaternion
0020 {
0021 public:
0022     Quaternion ();
0023     Quaternion (double realPart, double iPart, double jPart, double kPart);
0024 
0025     void quaternionSetIdentity();
0026     void quaternionAddRotation (const double axis[3], const double degrees);
0027     void quaternionPreMultiply (Quaternion * q1, const Quaternion * q2) const;
0028     void quaternionToMatrix (Matrix M) const;
0029     void quaternionInvert();
0030     void quaternionRotateVector (double axis[3]) const;
0031     void quaternionPrint() const;
0032 
0033 private:
0034     double w;           // The "real" part.
0035     double x;           // The "i" part.
0036     double y;           // The "j" part.
0037     double z;           // The "k" part.
0038 };
0039 
0040 #endif  // QUATERNION_H