volmetrics

diff src/matrix.h @ 0:88d390af583f

Image loader
author Eleni Maria Stea <eleni@mutantstargoat.com>
date Sat, 11 Jan 2014 17:22:36 +0200
parents
children
line diff
     1.1 --- /dev/null	Thu Jan 01 00:00:00 1970 +0000
     1.2 +++ b/src/matrix.h	Sat Jan 11 17:22:36 2014 +0200
     1.3 @@ -0,0 +1,81 @@
     1.4 +#ifndef MATRIX_H_
     1.5 +#define MATRIX_H_
     1.6 +
     1.7 +#include <iostream>
     1.8 +#include "vector.h"
     1.9 +
    1.10 +class Matrix4x4 {
    1.11 +public:
    1.12 +	float m[4][4];
    1.13 +
    1.14 +	static Matrix4x4 identity;
    1.15 +
    1.16 +	Matrix4x4();
    1.17 +	Matrix4x4(	float m11, float m12, float m13, float m14,
    1.18 +				float m21, float m22, float m23, float m24,
    1.19 +				float m31, float m32, float m33, float m34,
    1.20 +				float m41, float m42, float m43, float m44);
    1.21 +
    1.22 +	/* binary operations matrix (op) matrix */
    1.23 +	friend Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.24 +	friend Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.25 +	friend Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.26 +
    1.27 +	friend void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.28 +	friend void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.29 +	friend inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.30 +
    1.31 +	/* binary operations matrix (op) scalar and scalar (op) matrix */
    1.32 +	friend Matrix4x4 operator *(const Matrix4x4 &mat, float scalar);
    1.33 +	friend Matrix4x4 operator *(float scalar, const Matrix4x4 &mat);
    1.34 +
    1.35 +	friend void operator *=(Matrix4x4 &mat, float scalar);
    1.36 +
    1.37 +	inline float *operator [](int index);
    1.38 +	inline const float *operator [](int index) const;
    1.39 +
    1.40 +	inline void reset_identity();
    1.41 +
    1.42 +	void translate(const Vector3 &trans);
    1.43 +	void set_translation(const Vector3 &trans);
    1.44 +
    1.45 +	void rotate(const Vector3 &euler);			/* 3d rotation with euler angles */
    1.46 +	void rotate(const Vector3 &axis, float angle);	/* 3d axis/angle rotation */
    1.47 +	void set_rotation(const Vector3 &euler_angles);
    1.48 +	void set_rotation(const Vector3 &axis, float angle);
    1.49 +
    1.50 +	void scale(const Vector3 &scale_vec);
    1.51 +	void set_scaling(const Vector3 &scale_vec);
    1.52 +
    1.53 +	void set_column_vector(const Vector3 &vec, unsigned int col_index);
    1.54 +	void set_row_vector(const Vector3 &vec, unsigned int row_index);
    1.55 +	Vector3 get_column_vector(unsigned int col_index) const;
    1.56 +	Vector3 get_row_vector(unsigned int row_index) const;
    1.57 +
    1.58 +	void transpose();
    1.59 +	Matrix4x4 transposed() const;
    1.60 +	float determinant() const;
    1.61 +	Matrix4x4 adjoint() const;
    1.62 +	Matrix4x4 inverse() const;
    1.63 +};
    1.64 +
    1.65 +/* binary operations matrix (op) matrix */
    1.66 +Matrix4x4 operator +(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.67 +Matrix4x4 operator -(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.68 +Matrix4x4 operator *(const Matrix4x4 &m1, const Matrix4x4 &m2);
    1.69 +
    1.70 +void operator +=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.71 +void operator -=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.72 +inline void operator *=(Matrix4x4 &m1, const Matrix4x4 &m2);
    1.73 +
    1.74 +/* binary operations matrix (op) scalar and scalar (op) matrix */
    1.75 +Matrix4x4 operator *(const Matrix4x4 &mat, float scalar);
    1.76 +Matrix4x4 operator *(float scalar, const Matrix4x4 &mat);
    1.77 +
    1.78 +void operator *=(Matrix4x4 &mat, float scalar);
    1.79 +
    1.80 +std::ostream &operator <<(std::ostream &out, const Matrix4x4 &mat);
    1.81 +
    1.82 +
    1.83 +#endif
    1.84 +