istereo

annotate libs/vmath/matrix.h @ 43:73813c1176de

better hgignore
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 14 Aug 2015 04:33:42 +0300
parents c0ae8e668447
children
rev   line source
nuclear@39 1 /*
nuclear@39 2 libvmath - a vector math library
nuclear@39 3 Copyright (C) 2004-2011 John Tsiombikas <nuclear@member.fsf.org>
nuclear@39 4
nuclear@39 5 This program is free software: you can redistribute it and/or modify
nuclear@39 6 it under the terms of the GNU Lesser General Public License as published
nuclear@39 7 by the Free Software Foundation, either version 3 of the License, or
nuclear@39 8 (at your option) any later version.
nuclear@39 9
nuclear@39 10 This program is distributed in the hope that it will be useful,
nuclear@39 11 but WITHOUT ANY WARRANTY; without even the implied warranty of
nuclear@39 12 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
nuclear@39 13 GNU Lesser General Public License for more details.
nuclear@39 14
nuclear@39 15 You should have received a copy of the GNU Lesser General Public License
nuclear@39 16 along with this program. If not, see <http://www.gnu.org/licenses/>.
nuclear@39 17 */
nuclear@39 18
nuclear@28 19 #ifndef VMATH_MATRIX_H_
nuclear@28 20 #define VMATH_MATRIX_H_
nuclear@28 21
nuclear@28 22 #include <stdio.h>
nuclear@28 23 #include "vmath_types.h"
nuclear@28 24
nuclear@28 25 #ifdef __cplusplus
nuclear@28 26 extern "C" {
nuclear@28 27 #endif /* __cplusplus */
nuclear@28 28
nuclear@28 29 /* C matrix 3x3 functions */
nuclear@28 30 static inline void m3_identity(mat3_t m);
nuclear@28 31 static inline void m3_cons(mat3_t m,
nuclear@28 32 scalar_t m11, scalar_t m12, scalar_t m13,
nuclear@28 33 scalar_t m21, scalar_t m22, scalar_t m23,
nuclear@28 34 scalar_t m31, scalar_t m32, scalar_t m33);
nuclear@28 35 static inline void m3_copy(mat3_t dest, mat3_t src);
nuclear@28 36 void m3_to_m4(mat4_t dest, mat3_t src);
nuclear@28 37
nuclear@28 38 void m3_print(FILE *fp, mat3_t m);
nuclear@28 39
nuclear@28 40 /* C matrix 4x4 functions */
nuclear@28 41 static inline void m4_identity(mat4_t m);
nuclear@28 42 static inline void m4_cons(mat4_t m,
nuclear@28 43 scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
nuclear@28 44 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
nuclear@28 45 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
nuclear@28 46 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
nuclear@28 47 static inline void m4_copy(mat4_t dest, mat4_t src);
nuclear@28 48 void m4_to_m3(mat3_t dest, mat4_t src);
nuclear@28 49
nuclear@28 50 static inline void m4_mult(mat4_t res, mat4_t m1, mat4_t m2);
nuclear@28 51
nuclear@28 52 void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 53 void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 54 void m4_rotate_x(mat4_t m, scalar_t angle);
nuclear@28 55 void m4_rotate_y(mat4_t m, scalar_t angle);
nuclear@28 56 void m4_rotate_z(mat4_t m, scalar_t angle);
nuclear@28 57 void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 58 void m4_rotate_quat(mat4_t m, quat_t q);
nuclear@28 59 void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 60 static inline void m4_set_column(mat4_t m, vec4_t v, int idx);
nuclear@28 61 static inline void m4_set_row(mat4_t m, vec4_t v, int idx);
nuclear@28 62
nuclear@28 63 void m4_transpose(mat4_t res, mat4_t m);
nuclear@28 64 scalar_t m4_determinant(mat4_t m);
nuclear@28 65 void m4_adjoint(mat4_t res, mat4_t m);
nuclear@28 66 void m4_inverse(mat4_t res, mat4_t m);
nuclear@28 67
nuclear@28 68 void m4_print(FILE *fp, mat4_t m);
nuclear@28 69
nuclear@28 70 #ifdef __cplusplus
nuclear@28 71 }
nuclear@28 72
nuclear@28 73 /* when included from C++ source files, also define the matrix classes */
nuclear@28 74 #include <iostream>
nuclear@28 75
nuclear@28 76 /** 3x3 matrix */
nuclear@28 77 class Matrix3x3 {
nuclear@28 78 private:
nuclear@28 79 scalar_t m[3][3];
nuclear@28 80
nuclear@28 81 public:
nuclear@28 82
nuclear@28 83 static Matrix3x3 identity;
nuclear@28 84
nuclear@28 85 Matrix3x3();
nuclear@28 86 Matrix3x3( scalar_t m11, scalar_t m12, scalar_t m13,
nuclear@28 87 scalar_t m21, scalar_t m22, scalar_t m23,
nuclear@28 88 scalar_t m31, scalar_t m32, scalar_t m33);
nuclear@28 89 Matrix3x3(const mat3_t cmat);
nuclear@28 90
nuclear@28 91 Matrix3x3(const Matrix4x4 &mat4x4);
nuclear@28 92
nuclear@28 93 /* binary operations matrix (op) matrix */
nuclear@28 94 friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 95 friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 96 friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 97
nuclear@28 98 friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 99 friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 100 friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 101
nuclear@28 102 /* binary operations matrix (op) scalar and scalar (op) matrix */
nuclear@28 103 friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
nuclear@28 104 friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
nuclear@28 105
nuclear@28 106 friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
nuclear@28 107
nuclear@28 108 inline scalar_t *operator [](int index);
nuclear@28 109 inline const scalar_t *operator [](int index) const;
nuclear@28 110
nuclear@28 111 inline void reset_identity();
nuclear@28 112
nuclear@28 113 void translate(const Vector2 &trans);
nuclear@28 114 void set_translation(const Vector2 &trans);
nuclear@28 115
nuclear@28 116 void rotate(scalar_t angle); /* 2d rotation */
nuclear@28 117 void rotate(const Vector3 &euler_angles); /* 3d rotation with euler angles */
nuclear@28 118 void rotate(const Vector3 &axis, scalar_t angle); /* 3d axis/angle rotation */
nuclear@28 119 void set_rotation(scalar_t angle);
nuclear@28 120 void set_rotation(const Vector3 &euler_angles);
nuclear@28 121 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@28 122
nuclear@28 123 void scale(const Vector3 &scale_vec);
nuclear@28 124 void set_scaling(const Vector3 &scale_vec);
nuclear@28 125
nuclear@28 126 void set_column_vector(const Vector3 &vec, unsigned int col_index);
nuclear@28 127 void set_row_vector(const Vector3 &vec, unsigned int row_index);
nuclear@28 128 Vector3 get_column_vector(unsigned int col_index) const;
nuclear@28 129 Vector3 get_row_vector(unsigned int row_index) const;
nuclear@28 130
nuclear@28 131 void transpose();
nuclear@28 132 Matrix3x3 transposed() const;
nuclear@28 133 scalar_t determinant() const;
nuclear@28 134 Matrix3x3 inverse() const;
nuclear@28 135
nuclear@28 136 friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
nuclear@28 137 };
nuclear@28 138
nuclear@28 139 /** 4x4 matrix */
nuclear@28 140 class Matrix4x4 {
nuclear@28 141 private:
nuclear@28 142 scalar_t m[4][4];
nuclear@28 143
nuclear@28 144 public:
nuclear@28 145
nuclear@28 146 static Matrix4x4 identity;
nuclear@28 147
nuclear@28 148 Matrix4x4();
nuclear@28 149 Matrix4x4( scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
nuclear@28 150 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
nuclear@28 151 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
nuclear@28 152 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
nuclear@28 153 Matrix4x4(const mat4_t cmat);
nuclear@28 154
nuclear@28 155 Matrix4x4(const Matrix3x3 &mat3x3);
nuclear@28 156
nuclear@28 157 /* binary operations matrix (op) matrix */
nuclear@28 158 friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 159 friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 160 friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 161
nuclear@28 162 friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 163 friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 164 friend inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 165
nuclear@28 166 /* binary operations matrix (op) scalar and scalar (op) matrix */
nuclear@28 167 friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
nuclear@28 168 friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
nuclear@28 169
nuclear@28 170 friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
nuclear@28 171
nuclear@28 172 inline scalar_t *operator [](int index);
nuclear@28 173 inline const scalar_t *operator [](int index) const;
nuclear@28 174
nuclear@28 175 inline void reset_identity();
nuclear@28 176
nuclear@28 177 void translate(const Vector3 &trans);
nuclear@28 178 void set_translation(const Vector3 &trans);
nuclear@28 179
nuclear@28 180 void rotate(const Vector3 &euler_angles); /* 3d rotation with euler angles */
nuclear@28 181 void rotate(const Vector3 &axis, scalar_t angle); /* 3d axis/angle rotation */
nuclear@28 182 void set_rotation(const Vector3 &euler_angles);
nuclear@28 183 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@28 184
nuclear@28 185 void scale(const Vector4 &scale_vec);
nuclear@28 186 void set_scaling(const Vector4 &scale_vec);
nuclear@28 187
nuclear@28 188 void set_column_vector(const Vector4 &vec, unsigned int col_index);
nuclear@28 189 void set_row_vector(const Vector4 &vec, unsigned int row_index);
nuclear@28 190 Vector4 get_column_vector(unsigned int col_index) const;
nuclear@28 191 Vector4 get_row_vector(unsigned int row_index) const;
nuclear@28 192
nuclear@28 193 void transpose();
nuclear@28 194 Matrix4x4 transposed() const;
nuclear@28 195 scalar_t determinant() const;
nuclear@28 196 Matrix4x4 adjoint() const;
nuclear@28 197 Matrix4x4 inverse() const;
nuclear@28 198
nuclear@28 199 friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
nuclear@28 200 };
nuclear@28 201 #endif /* __cplusplus */
nuclear@28 202
nuclear@28 203 #include "matrix.inl"
nuclear@28 204
nuclear@28 205 #endif /* VMATH_MATRIX_H_ */