📄 matrix.h
字号:
//
// Matrix.h
//
// $Id: matrix.h,v 1.1.1.1 2001/02/28 00:28:37 cstolte Exp $
//
#ifndef SGL_MATRIX_H
#define SGL_MATRIX_H
extern int InverseMatrix3x3(double mat[3][3], double inv[3][3]);
#ifdef __GNUG__
#include <sgl/defs.h>
template <int sz, class T> class Vec {
public:
Vec(const T &);
Vec() { }
Vec operator-() const;
Vec operator+(const Vec &) const;
Vec &operator+=(const Vec &);
Vec operator-(const Vec &) const;
Vec &operator-=(const Vec &);
Vec operator*(double) const;
Vec &operator*=(double);
Vec operator/(double) const;
Vec &operator/=(double);
Vec operator*(const Vec &) const;
Vec &operator*=(const Vec &);
Vec operator/(const Vec &) const;
Vec &operator/=(const Vec &);
bool operator==(const Vec &) const;
bool operator!=(const Vec &) const;
T lengthsq() const;
T &operator[](int);
const T &operator[](int) const;
friend T dot(const Vec<sz, T> &, const Vec<sz, T> &);
friend Vec<sz, T> MIN(const Vec<sz, T> &, const Vec<sz, T> &);
friend Vec<sz, T> MAX(const Vec<sz, T> &, const Vec<sz, T> &);
friend Vec<sz, T> reflection(const Vec<sz, T> &n, const Vec<sz, T> &wi);
friend bool refraction(const Vec<sz, T> &n, const Vec<sz, T> &wi,
Vec<sz, T> *wt, double ni, double nt);
friend std::ostream &operator<<(std::ostream &, const Vec &);
private:
T v[sz];
};
template <int sz, class T> class Mat {
public:
Mat() { }
Mat(const T[sz * sz]);
Mat(const T &d);
Mat operator-() const;
Mat operator+(const Mat &) const;
Mat &operator+=(const Mat &);
Mat operator-(const Mat &) const;
Mat &operator-=(const Mat &);
Mat operator*(double) const;
Mat &operator*=(double);
friend Mat<sz, T> operator*(double, const Mat<sz, T> &);
friend Vec<sz, T> operator*(const Vec<sz, T> &, const Mat<sz, T> &);
Mat operator*(const Mat &) const;
Mat &operator*=(const Mat &);
Mat operator/(double) const;
Mat &operator/=(double);
bool operator==(const Mat &) const;
bool operator!=(const Mat &) const;
Mat &identity();
Mat &transpose();
Mat &adjoint();
Mat &invert();
Mat inverse() const;
T determinant() const;
// Mat<sz-1, T> minor(int i, int j) const; // hmmmm....
// Vec<sz, T> solve(const Vec<sz, T> &) const;
// Vec<sz, T> solve() const { return solve(Vec<sz, T>(0)); }
Vec<sz, T> &operator[](int i) { return row(i); }
const Vec<sz, T> &operator[](int i) const { return row(i); }
Vec<sz, T> column(int);
Vec<sz, T> &row(int);
const Vec<sz, T> &row(int) const;
friend std::ostream &operator<<(std::ostream &, const Mat &);
private:
Vec<sz, T> m[sz];
static T detHelper(const Mat<sz, T> &, int size);
};
#endif // __GNUG__
#endif /* SGL_MATRIX_H */
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -