dungeon_crawler

annotate prototype/vmath/quat.h @ 79:110b2af4b9d8

fixed the shader non-conformity by explicitly converting 2.2 to vec3 before passing it to pow for the texel inverse-gamma thing
author John Tsiombikas <nuclear@member.fsf.org>
date Sat, 27 Oct 2012 01:54:39 +0300
parents
children
rev   line source
nuclear@1 1 /*
nuclear@1 2 libvmath - a vector math library
nuclear@1 3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
nuclear@1 4
nuclear@1 5 This program is free software: you can redistribute it and/or modify
nuclear@1 6 it under the terms of the GNU Lesser General Public License as published
nuclear@1 7 by the Free Software Foundation, either version 3 of the License, or
nuclear@1 8 (at your option) any later version.
nuclear@1 9
nuclear@1 10 This program is distributed in the hope that it will be useful,
nuclear@1 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@1 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@1 13 GNU Lesser General Public License for more details.
nuclear@1 14
nuclear@1 15 You should have received a copy of the GNU Lesser General Public License
nuclear@1 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@1 17 */
nuclear@1 18
nuclear@1 19 #ifndef VMATH_QUATERNION_H_
nuclear@1 20 #define VMATH_QUATERNION_H_
nuclear@1 21
nuclear@1 22 #include <stdio.h>
nuclear@1 23 #include "vmath_types.h"
nuclear@1 24 #include "vector.h"
nuclear@1 25
nuclear@1 26 #ifdef __cplusplus
nuclear@1 27 extern "C" {
nuclear@1 28 #endif /* __cplusplus */
nuclear@1 29
nuclear@1 30 #define quat_cons(s, x, y, z) v4_cons(x, y, z, s)
nuclear@1 31 #define quat_vec(q) v3_cons((q).x, (q).y, (q).z)
nuclear@1 32 #define quat_s(q) ((q).w)
nuclear@1 33 #define quat_identity() quat_cons(1.0, 0.0, 0.0, 0.0)
nuclear@1 34 void quat_print(FILE *fp, quat_t q);
nuclear@1 35
nuclear@1 36 #define quat_add v4_add
nuclear@1 37 #define quat_sub v4_sub
nuclear@1 38 #define quat_neg v4_neg
nuclear@1 39
nuclear@1 40 static inline quat_t quat_mul(quat_t q1, quat_t q2);
nuclear@1 41
nuclear@1 42 static inline quat_t quat_conjugate(quat_t q);
nuclear@1 43
nuclear@1 44 #define quat_length v4_length
nuclear@1 45 #define quat_length_sq v4_length_sq
nuclear@1 46
nuclear@1 47 #define quat_normalize v4_normalize
nuclear@1 48 static inline quat_t quat_inverse(quat_t q);
nuclear@1 49
nuclear@1 50 quat_t quat_rotate(quat_t q, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
nuclear@1 51 quat_t quat_rotate_quat(quat_t q, quat_t rotq);
nuclear@1 52
nuclear@1 53 static inline void quat_to_mat3(mat3_t res, quat_t q);
nuclear@1 54 static inline void quat_to_mat4(mat4_t res, quat_t q);
nuclear@1 55
nuclear@1 56 #define quat_lerp quat_slerp
nuclear@1 57 quat_t quat_slerp(quat_t q1, quat_t q2, scalar_t t);
nuclear@1 58
nuclear@1 59
nuclear@1 60 #ifdef __cplusplus
nuclear@1 61 } /* extern "C" */
nuclear@1 62
nuclear@1 63 #include <iostream>
nuclear@1 64
nuclear@1 65 /* Quaternion */
nuclear@1 66 class Quaternion {
nuclear@1 67 public:
nuclear@1 68 scalar_t s;
nuclear@1 69 Vector3 v;
nuclear@1 70
nuclear@1 71 Quaternion();
nuclear@1 72 Quaternion(scalar_t s, const Vector3 &v);
nuclear@1 73 Quaternion(scalar_t s, scalar_t x, scalar_t y, scalar_t z);
nuclear@1 74 Quaternion(const Vector3 &axis, scalar_t angle);
nuclear@1 75 Quaternion(const quat_t &quat);
nuclear@1 76
nuclear@1 77 Quaternion operator +(const Quaternion &quat) const;
nuclear@1 78 Quaternion operator -(const Quaternion &quat) const;
nuclear@1 79 Quaternion operator -() const;
nuclear@1 80 Quaternion operator *(const Quaternion &quat) const;
nuclear@1 81
nuclear@1 82 void operator +=(const Quaternion &quat);
nuclear@1 83 void operator -=(const Quaternion &quat);
nuclear@1 84 void operator *=(const Quaternion &quat);
nuclear@1 85
nuclear@1 86 void reset_identity();
nuclear@1 87
nuclear@1 88 Quaternion conjugate() const;
nuclear@1 89
nuclear@1 90 scalar_t length() const;
nuclear@1 91 scalar_t length_sq() const;
nuclear@1 92
nuclear@1 93 void normalize();
nuclear@1 94 Quaternion normalized() const;
nuclear@1 95
nuclear@1 96 Quaternion inverse() const;
nuclear@1 97
nuclear@1 98 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@1 99 void rotate(const Vector3 &axis, scalar_t angle);
nuclear@1 100 /* note: this is a totally different operation from the above
nuclear@1 101 * this treats the quaternion as signifying direction and rotates
nuclear@1 102 * it by a rotation quaternion by rot * q * rot'
nuclear@1 103 */
nuclear@1 104 void rotate(const Quaternion &q);
nuclear@1 105
nuclear@1 106 Matrix3x3 get_rotation_matrix() const;
nuclear@1 107
nuclear@1 108 friend Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
nuclear@1 109
nuclear@1 110 friend std::ostream &operator <<(std::ostream &out, const Quaternion &q);
nuclear@1 111 };
nuclear@1 112
nuclear@1 113 Quaternion slerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
nuclear@1 114 inline Quaternion lerp(const Quaternion &q1, const Quaternion &q2, scalar_t t);
nuclear@1 115 #endif /* __cplusplus */
nuclear@1 116
nuclear@1 117 #include "quat.inl"
nuclear@1 118
nuclear@1 119 #endif /* VMATH_QUATERNION_H_ */