istereo

annotate libs/vmath/matrix.h @ 35:23e5d274b2a2

added options panel, also added the xib files to the repository as they're needed
author John Tsiombikas <nuclear@member.fsf.org>
date Fri, 09 Sep 2011 10:03:42 +0300
parents
children ff055bff6a15
rev   line source
nuclear@28 1 #ifndef VMATH_MATRIX_H_
nuclear@28 2 #define VMATH_MATRIX_H_
nuclear@28 3
nuclear@28 4 #include <stdio.h>
nuclear@28 5 #include "vmath_types.h"
nuclear@28 6
nuclear@28 7 #ifdef __cplusplus
nuclear@28 8 extern "C" {
nuclear@28 9 #endif /* __cplusplus */
nuclear@28 10
nuclear@28 11 /* C matrix 3x3 functions */
nuclear@28 12 static inline void m3_identity(mat3_t m);
nuclear@28 13 static inline void m3_cons(mat3_t m,
nuclear@28 14 scalar_t m11, scalar_t m12, scalar_t m13,
nuclear@28 15 scalar_t m21, scalar_t m22, scalar_t m23,
nuclear@28 16 scalar_t m31, scalar_t m32, scalar_t m33);
nuclear@28 17 static inline void m3_copy(mat3_t dest, mat3_t src);
nuclear@28 18 void m3_to_m4(mat4_t dest, mat3_t src);
nuclear@28 19
nuclear@28 20 void m3_print(FILE *fp, mat3_t m);
nuclear@28 21
nuclear@28 22 /* C matrix 4x4 functions */
nuclear@28 23 static inline void m4_identity(mat4_t m);
nuclear@28 24 static inline void m4_cons(mat4_t m,
nuclear@28 25 scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
nuclear@28 26 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
nuclear@28 27 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
nuclear@28 28 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
nuclear@28 29 static inline void m4_copy(mat4_t dest, mat4_t src);
nuclear@28 30 void m4_to_m3(mat3_t dest, mat4_t src);
nuclear@28 31
nuclear@28 32 static inline void m4_mult(mat4_t res, mat4_t m1, mat4_t m2);
nuclear@28 33
nuclear@28 34 void m4_translate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 35 void m4_rotate(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 36 void m4_rotate_x(mat4_t m, scalar_t angle);
nuclear@28 37 void m4_rotate_y(mat4_t m, scalar_t angle);
nuclear@28 38 void m4_rotate_z(mat4_t m, scalar_t angle);
nuclear@28 39 void m4_rotate_axis(mat4_t m, scalar_t angle, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 40 void m4_rotate_quat(mat4_t m, quat_t q);
nuclear@28 41 void m4_scale(mat4_t m, scalar_t x, scalar_t y, scalar_t z);
nuclear@28 42 static inline void m4_set_column(mat4_t m, vec4_t v, int idx);
nuclear@28 43 static inline void m4_set_row(mat4_t m, vec4_t v, int idx);
nuclear@28 44
nuclear@28 45 void m4_transpose(mat4_t res, mat4_t m);
nuclear@28 46 scalar_t m4_determinant(mat4_t m);
nuclear@28 47 void m4_adjoint(mat4_t res, mat4_t m);
nuclear@28 48 void m4_inverse(mat4_t res, mat4_t m);
nuclear@28 49
nuclear@28 50 void m4_print(FILE *fp, mat4_t m);
nuclear@28 51
nuclear@28 52 #ifdef __cplusplus
nuclear@28 53 }
nuclear@28 54
nuclear@28 55 /* when included from C++ source files, also define the matrix classes */
nuclear@28 56 #include <iostream>
nuclear@28 57
nuclear@28 58 /** 3x3 matrix */
nuclear@28 59 class Matrix3x3 {
nuclear@28 60 private:
nuclear@28 61 scalar_t m[3][3];
nuclear@28 62
nuclear@28 63 public:
nuclear@28 64
nuclear@28 65 static Matrix3x3 identity;
nuclear@28 66
nuclear@28 67 Matrix3x3();
nuclear@28 68 Matrix3x3( scalar_t m11, scalar_t m12, scalar_t m13,
nuclear@28 69 scalar_t m21, scalar_t m22, scalar_t m23,
nuclear@28 70 scalar_t m31, scalar_t m32, scalar_t m33);
nuclear@28 71 Matrix3x3(const mat3_t cmat);
nuclear@28 72
nuclear@28 73 Matrix3x3(const Matrix4x4 &mat4x4);
nuclear@28 74
nuclear@28 75 /* binary operations matrix (op) matrix */
nuclear@28 76 friend Matrix3x3 operator +(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 77 friend Matrix3x3 operator -(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 78 friend Matrix3x3 operator *(const Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 79
nuclear@28 80 friend void operator +=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 81 friend void operator -=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 82 friend void operator *=(Matrix3x3 &m1, const Matrix3x3 &m2);
nuclear@28 83
nuclear@28 84 /* binary operations matrix (op) scalar and scalar (op) matrix */
nuclear@28 85 friend Matrix3x3 operator *(const Matrix3x3 &mat, scalar_t scalar);
nuclear@28 86 friend Matrix3x3 operator *(scalar_t scalar, const Matrix3x3 &mat);
nuclear@28 87
nuclear@28 88 friend void operator *=(Matrix3x3 &mat, scalar_t scalar);
nuclear@28 89
nuclear@28 90 inline scalar_t *operator [](int index);
nuclear@28 91 inline const scalar_t *operator [](int index) const;
nuclear@28 92
nuclear@28 93 inline void reset_identity();
nuclear@28 94
nuclear@28 95 void translate(const Vector2 &trans);
nuclear@28 96 void set_translation(const Vector2 &trans);
nuclear@28 97
nuclear@28 98 void rotate(scalar_t angle); /* 2d rotation */
nuclear@28 99 void rotate(const Vector3 &euler_angles); /* 3d rotation with euler angles */
nuclear@28 100 void rotate(const Vector3 &axis, scalar_t angle); /* 3d axis/angle rotation */
nuclear@28 101 void set_rotation(scalar_t angle);
nuclear@28 102 void set_rotation(const Vector3 &euler_angles);
nuclear@28 103 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@28 104
nuclear@28 105 void scale(const Vector3 &scale_vec);
nuclear@28 106 void set_scaling(const Vector3 &scale_vec);
nuclear@28 107
nuclear@28 108 void set_column_vector(const Vector3 &vec, unsigned int col_index);
nuclear@28 109 void set_row_vector(const Vector3 &vec, unsigned int row_index);
nuclear@28 110 Vector3 get_column_vector(unsigned int col_index) const;
nuclear@28 111 Vector3 get_row_vector(unsigned int row_index) const;
nuclear@28 112
nuclear@28 113 void transpose();
nuclear@28 114 Matrix3x3 transposed() const;
nuclear@28 115 scalar_t determinant() const;
nuclear@28 116 Matrix3x3 inverse() const;
nuclear@28 117
nuclear@28 118 friend std::ostream &operator <<(std::ostream &out, const Matrix3x3 &mat);
nuclear@28 119 };
nuclear@28 120
nuclear@28 121 /** 4x4 matrix */
nuclear@28 122 class Matrix4x4 {
nuclear@28 123 private:
nuclear@28 124 scalar_t m[4][4];
nuclear@28 125
nuclear@28 126 public:
nuclear@28 127
nuclear@28 128 static Matrix4x4 identity;
nuclear@28 129
nuclear@28 130 Matrix4x4();
nuclear@28 131 Matrix4x4( scalar_t m11, scalar_t m12, scalar_t m13, scalar_t m14,
nuclear@28 132 scalar_t m21, scalar_t m22, scalar_t m23, scalar_t m24,
nuclear@28 133 scalar_t m31, scalar_t m32, scalar_t m33, scalar_t m34,
nuclear@28 134 scalar_t m41, scalar_t m42, scalar_t m43, scalar_t m44);
nuclear@28 135 Matrix4x4(const mat4_t cmat);
nuclear@28 136
nuclear@28 137 Matrix4x4(const Matrix3x3 &mat3x3);
nuclear@28 138
nuclear@28 139 /* binary operations matrix (op) matrix */
nuclear@28 140 friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 141 friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 142 friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 143
nuclear@28 144 friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 145 friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 146 friend inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
nuclear@28 147
nuclear@28 148 /* binary operations matrix (op) scalar and scalar (op) matrix */
nuclear@28 149 friend Matrix4x4 operator *(const Matrix4x4 &mat, scalar_t scalar);
nuclear@28 150 friend Matrix4x4 operator *(scalar_t scalar, const Matrix4x4 &mat);
nuclear@28 151
nuclear@28 152 friend void operator *=(Matrix4x4 &mat, scalar_t scalar);
nuclear@28 153
nuclear@28 154 inline scalar_t *operator [](int index);
nuclear@28 155 inline const scalar_t *operator [](int index) const;
nuclear@28 156
nuclear@28 157 inline void reset_identity();
nuclear@28 158
nuclear@28 159 void translate(const Vector3 &trans);
nuclear@28 160 void set_translation(const Vector3 &trans);
nuclear@28 161
nuclear@28 162 void rotate(const Vector3 &euler_angles); /* 3d rotation with euler angles */
nuclear@28 163 void rotate(const Vector3 &axis, scalar_t angle); /* 3d axis/angle rotation */
nuclear@28 164 void set_rotation(const Vector3 &euler_angles);
nuclear@28 165 void set_rotation(const Vector3 &axis, scalar_t angle);
nuclear@28 166
nuclear@28 167 void scale(const Vector4 &scale_vec);
nuclear@28 168 void set_scaling(const Vector4 &scale_vec);
nuclear@28 169
nuclear@28 170 void set_column_vector(const Vector4 &vec, unsigned int col_index);
nuclear@28 171 void set_row_vector(const Vector4 &vec, unsigned int row_index);
nuclear@28 172 Vector4 get_column_vector(unsigned int col_index) const;
nuclear@28 173 Vector4 get_row_vector(unsigned int row_index) const;
nuclear@28 174
nuclear@28 175 void transpose();
nuclear@28 176 Matrix4x4 transposed() const;
nuclear@28 177 scalar_t determinant() const;
nuclear@28 178 Matrix4x4 adjoint() const;
nuclear@28 179 Matrix4x4 inverse() const;
nuclear@28 180
nuclear@28 181 friend std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
nuclear@28 182 };
nuclear@28 183 #endif /* __cplusplus */
nuclear@28 184
nuclear@28 185 #include "matrix.inl"
nuclear@28 186
nuclear@28 187 #endif /* VMATH_MATRIX_H_ */