From d65aba4d68e81b6b0b0fa02d999d1cb416f2f318 Mon Sep 17 00:00:00 2001 From: Hartmut Seichter Date: Sat, 24 Jun 2023 08:34:15 +0200 Subject: [PATCH] some minor refresh --- .vscode/launch.json | 7 + .vscode/settings.json | 20 +- .vscode/tasks.json | 28 + CMakeLists.txt | 4 +- src/core/include/pw/core/matrix.hpp | 977 ++++++---------------------- src/deps/lua-5.4.2/CMakeLists.txt | 2 +- src/visual/src/renderer.cpp | 2 +- src/visual/src/shader.cpp | 6 +- 8 files changed, 278 insertions(+), 768 deletions(-) create mode 100644 .vscode/launch.json create mode 100644 .vscode/tasks.json diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 0000000..5c7247b --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,7 @@ +{ + // Use IntelliSense to learn about possible attributes. + // Hover to view descriptions of existing attributes. + // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387 + "version": "0.2.0", + "configurations": [] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json index 4d69525..36bf36d 100644 --- a/.vscode/settings.json +++ b/.vscode/settings.json @@ -1,4 +1,22 @@ { "C_Cpp.default.configurationProvider": "ms-vscode.cmake-tools", - "cmake.configureOnOpen": true + "cmake.configureOnOpen": true, + "files.associations": { + "array": "cpp", + "cwchar": "cpp", + "unordered_map": "cpp", + "vector": "cpp", + "exception": "cpp", + "functional": "cpp", + "initializer_list": "cpp", + "iosfwd": "cpp", + "istream": "cpp", + "new": "cpp", + "ostream": "cpp", + "stdexcept": "cpp", + "streambuf": "cpp", + "type_traits": "cpp", + "tuple": "cpp" + }, + "mesonbuild.configureOnOpen": false } \ No newline at end of file diff --git a/.vscode/tasks.json b/.vscode/tasks.json new file mode 100644 index 0000000..05054c5 --- /dev/null +++ b/.vscode/tasks.json @@ -0,0 +1,28 @@ +{ + "tasks": [ + { + "type": "cppbuild", + "label": "C/C++: g++ build active file", + "command": "/usr/bin/g++", + "args": [ + "-fdiagnostics-color=always", + "-g", + "${file}", + "-o", + "${fileDirname}/${fileBasenameNoExtension}" + ], + "options": { + "cwd": "${fileDirname}" + }, + "problemMatcher": [ + "$gcc" + ], + "group": { + "kind": "build", + "isDefault": true + }, + "detail": "Task generated by Debugger." + } + ], + "version": "2.0.0" +} \ No newline at end of file diff --git a/CMakeLists.txt b/CMakeLists.txt index 3cfa15f..52ddf60 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -7,9 +7,9 @@ cmake_minimum_required(VERSION 3.8) project(pixwerx) # -# pixwerx ist C++17 +# pixwerx ist C++20 # -set (CMAKE_CXX_STANDARD 23) +set (CMAKE_CXX_STANDARD 20) # internal cmake modules set(CMAKE_MODULE_PATH ${CMAKE_CURRENT_SOURCE_DIR}/etc/cmake ${CMAKE_MODULE_PATH}) diff --git a/src/core/include/pw/core/matrix.hpp b/src/core/include/pw/core/matrix.hpp index 7d76f78..afacaea 100644 --- a/src/core/include/pw/core/matrix.hpp +++ b/src/core/include/pw/core/matrix.hpp @@ -28,795 +28,252 @@ #include #include +#include -namespace pw { - -template -struct matrix_ : matrixbase_> +namespace pw { - T data[R*C]; - using matrixbase_>::matrixbase_; - - static constexpr std::size_t rows { R }; - static constexpr std::size_t cols { C }; - - static constexpr std::size_t coefficients { R * C }; - - using col_type = matrix_; - using row_type = matrix_<1,C,T>; - using transpose_type = matrix_; - - matrix_(const matrix_& other) + template + struct matrix_ : matrixbase_> { - *this = other; - } + T data[R * C]; - matrix_& operator = (const matrix_& other) - { - for (size_t i = 0; i < other.size();i++) (*this)[i] = other[i]; - return *this; - } + using matrixbase_>::matrixbase_; - matrix_(std::initializer_list args) - { - typename std::initializer_list::iterator it = args.begin(); - for (;it != args.end();it++) data[it-args.begin()] = *it; - } + static constexpr std::size_t rows{R}; + static constexpr std::size_t cols{C}; - template - matrix_& set(Arguments ...values) - { - static_assert(sizeof...(Arguments) == R*C, "Incorrect number of arguments"); - data = {values... }; - return *this; - } + static constexpr std::size_t coefficients{R * C}; - inline size_t offset(size_t r,size_t c) const { - return (RowMajor) ? r * C + c : c * R + r; - } + using col_type = matrix_; + using row_type = matrix_<1, C, T>; + using transpose_type = matrix_; - inline T& operator () (std::size_t r, std::size_t c) { - return data[offset(r,c)]; - } - - inline const T& operator () (std::size_t r, std::size_t c) const { - return data[offset(r,c)]; - } - - inline const T *ptr() const { return &data[0]; } - - //! set identity - inline matrix_& set_identity() - { - for (std::size_t r = 0;r < rows; r++) - for (std::size_t c = 0; c < cols; c++) - (*this)(r,c) = (c == r) ? T(1) : T(0); - return *this; - } - - template - auto slice(std::size_t r,std::size_t c) const - { - matrix_ s; - for (std::size_t ri = 0;ri < Rs;ri++) - for (std::size_t ci = 0;ci < Cs;ci++) - s(ri,ci) = (*this)(ri+r,ci+c); - return s; - } - - template - matrix_& set_slice(const matrix_& s, - std::size_t r,std::size_t c) - { - for (std::size_t ri = 0;ri < Rs;ri++) - for (std::size_t ci = 0;ci < Cs;ci++) - (*this)(ri+r,ci+c) = s(ri,ci); - return *this; - } - - - template - auto minor(std::size_t r0,std::size_t c0) const - { - matrix_ m; - size_t r = 0; - for (size_t ri = 0; ri < R; ri++) { - size_t c = 0; - if (ri == r0) - continue; - for (size_t ci = 0; ci < C; ci++) - { - if (ci == c0) - continue; - m(r,c) = (*this)(ri,ci); - c++; - } - r++; - } - return m; - } - - T determinant() const { - T det(0); - for (size_t c = 0; c < C; c++) - det += ((c % 2 == 0) ? (*this)(0,c) : -(*this)(0,c)) - * this->minor(0,c).determinant(); - return det; - } - - auto transposed() const { - transpose_type res; - for (size_t r = rows;r-->0;) - for (size_t c = cols;c-->0;) - res(c,r) = (*this)(r,c); - return res; - } - - auto inverse() const { - T invDet = T(1) / this->determinant(); - matrix_ inv; - for (int j = 0; j < C; j++) - for (int i = 0; i < R; i++) - { - const T minorDet = this->minor(j,i).determinant(); - const T coFactor = ((i + j) % 2 == 1) ? -minorDet : minorDet; - inv(i, j) = invDet * coFactor; - } - return inv; - } - - inline bool row_major() const { - return RowMajor; - } - - inline bool square() const { return R == C; } - - - inline const matrix_ operator + (const matrix_ &other) const { - matrix_ res(*this); - for (size_t r = 0; r < R;r++) - for (size_t c = 0; c < C;c++) - res(r,c) += other(r,c); - return res; - } - - inline const matrix_ operator - (const matrix_ &other) const { - matrix_ res(*this); - for (size_t r = 0; r < R;r++) - for (size_t c = 0; c < C;c++) - res(r,c) -= other(r,c); - return res; - } - - auto row(size_t row_) const { - row_type r; - for (size_t i = 0; i < cols; i++) r[i] = (*this)(row_,i); - return r; - } - - auto column(size_t col_) const { - col_type c; - for (size_t i = 0; i < rows; i++) c[i] = (*this)(i,col_); - return c; - } - - static constexpr auto identity() { - matrix_ res; - for (std::size_t r = 0;r < rows; r++) - for (std::size_t c = 0; c < cols; c++) - res(r,c) = (c == r) ? T(1) : T(0); - return res; - } -}; - -template <> inline -float matrix_<1,1,float>::determinant() const -{ - return (*this)(0,0); -} - -template <> inline -double matrix_<1,1,double>::determinant() const -{ - return (*this)(0,0); -} - - -template -auto operator * (const matrix_& A, - const matrix_& B - ) -{ - matrix_ result; result.zero(); // zero the output - for (size_t r = 0; r < R; r++) - for (size_t c = 0; c < Cb; c++) - for (size_t iI = 0; iI < R; iI++) - result(r,c) += A(r,iI) * B(iI,c); // inner product - return result; -} - - -// -// -// - -template using matrix2x2_ = matrix_<2, 2, T>; -template using matrix3x3_ = matrix_<3, 3, T>; -template using matrix4x4_ = matrix_<4, 4, T>; - -using matrix2x2f = matrix2x2_; -using matrix2x2d = matrix2x2_; -using matrix2x2 = matrix2x2_; - -using matrix3x3f = matrix3x3_; -using matrix3x3d = matrix3x3_; -using matrix3x3 = matrix3x3_; - -using matrix4x4f = matrix4x4_; -using matrix4x4d = matrix4x4_; -using matrix4x4 = matrix4x4_; - - - -} - - -#if __OLD - -template -class matrix_ : public matrixbase { - - T m[R*C]; - -public: - - using typename matrixbase::value_type; - using typename matrixbase::size_type; - - matrix_(); - - matrix_(const matrix_& mtc); - - matrix_& operator = (const matrix_& other); - - matrix_(std::initializer_list il) - { - this->set(il); - } - - matrix_ set(std::initializer_list il) - { - int i = 0; - for (T e : il) (*this).at(i++) = e; - } - - matrix_ transposed() const; - - inline matrix_& operator *= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) *= b; return *this; } - inline matrix_& operator /= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) /= b; return *this; } - inline matrix_& operator += (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += b; return *this; } - inline matrix_& operator -= (const T& b) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= b; return *this; } - - inline matrix_& operator += (const matrix_& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) += other.at(i); return *this; } - inline matrix_& operator -= (const matrix_& other) { for (unsigned int i = this->cells(); i--> 0;) this->at(i) -= other.at(i); return *this; } - - inline const matrix_ normalized() const { - const T one_over_n = T(1) / this->norm(); - return *this * one_over_n; - } - - - inline const matrix_ - get_inverse() const - { - matrix_ resMat; - - for ( unsigned int r = 0; r < C; ++r) { - for ( unsigned int j = 0; j < R; ++j) { - short sgn = ( (r+j)%2) ? -1 : 1; - matrix_ minor; - this->get_minor(minor,r,j); - resMat.at(r,j) = minor.determinant() * sgn; - } - } - - resMat = resMat.transposed(); - resMat *= (static_cast(1)/this->determinant()); - return resMat; - } - - inline - matrix_& invert() { - *this = this->get_inverse(); - return *this; - } - - void get_minor(matrix_& res, unsigned int r0, unsigned int c0) const; - - T determinant() const; - - T squared_norm() const; - - T norm() const; - - matrix_& operator *= (const matrix_& rhs); - - matrix_& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; } - - const matrix_ reshape() const { - matrix_ m; - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - m(r,c) = (*this)(c,r); - return m; - } - - const matrix_ get_column(unsigned int col) const { - matrix_ c; for (unsigned int r = 0; r < R; ++r) c(r,0) = (this)(r,col); - return c; - } - - const matrix_<1,C,T> get_row(unsigned int row) const { - matrix_<1,C,T> r; for (unsigned int c = 0; c < C; ++c) r(0,c) = (this)(row,c); - return r; - } - - void normalize(); - - template - matrix_ operator * (const matrix_& B) const - { - // aC == bR - // set all null - matrix_ res; - res.fill(0); - - // compute all resulting cells - for (unsigned int r = 0; r < R; ++r) { - for (unsigned int c = 0; c < bC; ++c) { - // building inner product - for (unsigned int iI = 0; iI < R;iI++) { - res.at(r,c) += (*this).at(r,iI) * B.at(iI,c); - } - } - } - return res; - } -}; - -///////////////////////////////////////////////////////////////////////////// - -template -inline matrix_ operator * (const matrix_& a, const T& b) -{ - matrix_ res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * b; - return res; -} - -template -inline matrix_ operator / (const matrix_& a, const T& b) -{ - matrix_ res; T oneOverB(1./b); - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) * oneOverB; - return res; -} - -template -inline matrix_ operator + (const matrix_& a, const T& b) -{ - matrix_ res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b; - return res; -} - -template -inline matrix_ operator - (const matrix_& a, const T& b) -{ - matrix_ res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b; - return res; -} - -template -inline matrix_ operator + (const matrix_& a, const matrix_& b) -{ - matrix_ res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) + b.at(i); - return res; -} - -template -inline matrix_ operator - (const matrix_& a, const matrix_& b) -{ - matrix_ res; - for (unsigned int i = res.cells(); i--> 0;) res.at(i) = a.at(i) - b.at(i); - return res; -} - - - -//template -//matrix_ static inline -//mul(const matrix_& A, const matrix_& B) -//{ -// // aC == bR -// // set all null -// matrix_ res; -// res.fill(0); - -// // compute all resulting cells -// for (unsigned int r = 0; r < aR; ++r) { -// for (unsigned int c = 0; c < bC; ++c) { -// // building inner product -// for (unsigned int iI = 0; iI < aCbR;iI++) { -// res.at(r,c) += A.at(r,iI) * B.at(iI,c); -// } -// } -// } -// return res; -//} - - -///////////////////////////////////////////////////////////////////////////// - - - - -///////////////////////////////////////////////////////////////////////////// - -template -matrix_& matrix_::operator *= (const matrix_& rhs) -{ - *this = *this * rhs; - return *this; -} - -///////////////////////////////////////////////////////////////////////////// - -template -matrix_::matrix_() - : matrixbase(R,C,&m[0],true) -{ -} - -template -matrix_::matrix_(const matrix_ &mtc) : - matrixbase(R,C,&m[0],true) -{ - *this = mtc; -} - -template -matrix_ &matrix_::operator = (const matrix_ &other) -{ - if (this != &other) - for (unsigned int r = 0; r < R;++r) - for (unsigned int c = 0; c < C;++c) - (*this).at(r,c) = other.at(r,c); - return *this; -} - -template -matrix_ matrix_::transposed() const -{ - matrix_ res; - for (unsigned int r = this->rows();r-->0;) - for (unsigned int c = this->cols();c-->0;) - res.at(c,r) = this->at(r,c); - return res; -} - -template -void matrix_::get_minor(matrix_& res,unsigned int r0, unsigned int c0) const -{ - unsigned int r = 0; - for (unsigned int ri = 0; ri < R; ri++) - { - unsigned int c = 0; - if (ri == r0) continue; - for (unsigned int ci = 0; ci < C; ci++) + matrix_ &operator=(const matrix_ &other) { - if (ci == c0) continue; - res.data()[r*(C-1)+c] = this->data()[ri*C + ci];//(*this)(ri,ci); - c++; - } - r++; - } -} - -template inline -T matrix_::determinant() const -{ - T res(0); - - matrix_ minor; - - // using Laplace Expansion at compile time - for (unsigned int c = 0; c < C; c++) { - this->get_minor(minor,0,c); - res += ((c % 2 == 0) ? m[c] : -m[c]) * minor.determinant(); - } - - return res; -} - -template inline -T matrix_::squared_norm() const -{ - T res(0); - - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - res += ((*this).at(r,c) * (*this).at(r,c)); - return res; -} - - -template inline -T matrix_::norm() const -{ - using std::sqrt; - - return sqrt(this->squared_norm()); -} - -template inline -void matrix_::normalize() -{ - T n = norm(); - if (n > 0) { - for (unsigned int r = 0; r < R; ++r) - for (unsigned int c = 0; c < C; ++c) - (*this)(r,c) /= n; - } -} - -///////////////////////////////////////////////////////////////////////////// - -// explicit specializations - -// 4x4 - -template -class matrix4x4_ : public matrix_<4,4,T> -{ -public: - - using matrix_<4,4,T>::matrix_; - - - matrix4x4_(const matrix_<4,4,T>& i) - { - *this = i; - } - - matrix4x4_& operator = (const matrix_<4,4,T>& rhs) { - if (this != &rhs){ - this->at(0,0) = rhs.at(0,0);this->at(0,1) = rhs.at(0,1);this->at(0,2) = rhs.at(0,2);this->at(0,3) = rhs.at(0,3); - this->at(1,0) = rhs.at(1,0);this->at(1,1) = rhs.at(1,1);this->at(1,2) = rhs.at(1,2);this->at(1,3) = rhs.at(1,3); - this->at(2,0) = rhs.at(2,0);this->at(2,1) = rhs.at(2,1);this->at(2,2) = rhs.at(2,2);this->at(2,3) = rhs.at(2,3); - this->at(3,0) = rhs.at(3,0);this->at(3,1) = rhs.at(3,1);this->at(3,2) = rhs.at(3,2);this->at(3,3) = rhs.at(3,3); + for (size_t i = 0; i < other.size(); i++) + (*this)[i] = other[i]; + return *this; } - return *this; - } + matrix_(std::initializer_list args) + { + typename std::initializer_list::iterator it = args.begin(); + for (; it != args.end(); it++) + data[it - args.begin()] = *it; + } + template + matrix_ &set(Arguments... values) + { + static_assert(sizeof...(Arguments) == R * C, "Incorrect number of arguments"); + data = {values...}; + return *this; + } + inline size_t offset(size_t r, size_t c) const + { + return (RowMajor) ? r * C + c : c * R + r; + } -#if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE + inline T &operator()(std::size_t r, std::size_t c) + { + return data[offset(r, c)]; + } - matrix<4,4,T>& - translate(const T& v1,const T& v2,const T& v3) + inline const T &operator()(std::size_t r, std::size_t c) const + { + return data[offset(r, c)]; + } + + inline const T *ptr() const { return &data[0]; } + + //! set identity + inline matrix_ &set_identity() + { + for (std::size_t r = 0; r < rows; r++) + for (std::size_t c = 0; c < cols; c++) + (*this)(r, c) = (c == r) ? T(1) : T(0); + return *this; + } + + inline matrix_ &set_uniform(const T& v) + { + std::fill(std::begin(data),std::end(data),v); + return *this; + } + + template + auto slice(std::size_t r, std::size_t c) const + { + matrix_ s; + for (std::size_t ri = 0; ri < Rs; ri++) + for (std::size_t ci = 0; ci < Cs; ci++) + s(ri, ci) = (*this)(ri + r, ci + c); + return s; + } + + template + matrix_ &set_slice(const matrix_ &s, + std::size_t r, std::size_t c) + { + for (std::size_t ri = 0; ri < Rs; ri++) + for (std::size_t ci = 0; ci < Cs; ci++) + (*this)(ri + r, ci + c) = s(ri, ci); + return *this; + } + + template + auto minor(std::size_t r0, std::size_t c0) const + { + matrix_ m; + size_t r = 0; + for (size_t ri = 0; ri < R; ri++) + { + size_t c = 0; + if (ri == r0) + continue; + for (size_t ci = 0; ci < C; ci++) + { + if (ci == c0) + continue; + m(r, c) = (*this)(ri, ci); + c++; + } + r++; + } + return m; + } + + T determinant() const + { + T det(0); + for (size_t c = 0; c < C; c++) + det += ((c % 2 == 0) ? (*this)(0, c) : -(*this)(0, c)) * this->minor(0, c).determinant(); + return det; + } + + auto transposed() const + { + transpose_type res; + for (size_t r = rows; r-- > 0;) + for (size_t c = cols; c-- > 0;) + res(c, r) = (*this)(r, c); + return res; + } + + auto inverse() const + { + T invDet = T(1) / this->determinant(); + matrix_ inv; + for (int j = 0; j < C; j++) + for (int i = 0; i < R; i++) + { + const T minorDet = this->minor(j, i).determinant(); + const T coFactor = ((i + j) % 2 == 1) ? -minorDet : minorDet; + inv(i, j) = invDet * coFactor; + } + return inv; + } + + inline bool row_major() const + { + return RowMajor; + } + + inline bool square() const { return R == C; } + + inline const matrix_ operator+(const matrix_ &other) const + { + matrix_ res(*this); + for (size_t r = 0; r < R; r++) + for (size_t c = 0; c < C; c++) + res(r, c) += other(r, c); + return res; + } + + inline const matrix_ operator-(const matrix_ &other) const + { + matrix_ res(*this); + for (size_t r = 0; r < R; r++) + for (size_t c = 0; c < C; c++) + res(r, c) -= other(r, c); + return res; + } + + auto row(size_t row_) const + { + row_type r; + for (size_t i = 0; i < cols; i++) + r[i] = (*this)(row_, i); + return r; + } + + auto column(size_t col_) const + { + col_type c; + for (size_t i = 0; i < rows; i++) + c[i] = (*this)(i, col_); + return c; + } + + static constexpr auto identity() + { + matrix_ res; + for (std::size_t r = 0; r < rows; r++) + for (std::size_t c = 0; c < cols; c++) + res(r, c) = (c == r) ? T(1) : T(0); + return res; + } + }; + + template <> + inline float matrix_<1, 1, float>::determinant() const { - this->at(12) += v1; - this->at(13) += v2; - this->at(14) += v3; - return *this; + return (*this)(0, 0); } - matrix<4,4,T>& - setTranslation(const T& v1,const T& v2,const T& v3) + template <> + inline double matrix_<1, 1, double>::determinant() const { - this->identity(); - this->at(12) = v1; - this->at(13) = v2; - this->at(14) = v3; - return *this; + return (*this)(0, 0); } - matrix<4,4,T>& - setScale(const T& v1,const T& v2,const T& v3) + template + auto operator*(const matrix_ &A, + const matrix_ &B) { - this->identity(); - (*this)(0,0) = v1; - (*this)(1,1) = v2; - (*this)(2,2) = v3; - return *this; + matrix_ result; + result.zero(); // zero the output + for (size_t r = 0; r < R; r++) + for (size_t c = 0; c < Cb; c++) + for (size_t iI = 0; iI < R; iI++) + result(r, c) += A(r, iI) * B(iI, c); // inner product + return result; } - matrix<4,4,T>& - scale(const T& v1,const T& v2,const T& v3) - { - (*this)(0,0) *= v1; - (*this)(1,1) *= v2; - (*this)(2,2) *= v3; - return *this; - } + // + // common matrix types + // + template + using matrix2x2_ = matrix_<2, 2, T>; + template + using matrix3x3_ = matrix_<3, 3, T>; + template + using matrix4x4_ = matrix_<4, 4, T>; - static - matrix<4,4,T> - Translation(const T& v1,const T& v2,const T& v3) - { - matrix44 res = matrix44::Identity(); res.setTranslation(v1,v2,v3); - return res; - } + using matrix2x2f = matrix2x2_; + using matrix2x2d = matrix2x2_; + using matrix2x2 = matrix2x2_; - inline static - matrix<4,4,T> - AngleAxis(const T& radianRotation,const matrix<3,1,T>& vec); - - - - inline static - matrix<4,4,T> Frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar) - { - matrix<4,4,T> frustum; - - frustum.fill(0); - - frustum(0,0) = 2 * zNear/(Right-Left); - frustum(1,1) = 2 * zNear/(Top-Bottom); - - frustum(0,2) = (Right+Left)/(Right-Left); //A - frustum(1,2) = (Top+Bottom)/(Top-Bottom); //B - frustum(2,2) = - (zFar+zNear)/(zFar-zNear); //C - frustum(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D - - frustum(2,3) = -1; - - return frustum; - } - - - inline static - matrix<4,4,T> LookAt(const matrix<3,1,T>& eye, - const matrix<3,1,T>& target, - const matrix<3,1,T>& up); - - - matrix<4,4,T>& - rotate(const matrix<3,1,T>& vec, const T& rotation) - { - matrix44 rot = matrix44::AngleAxis(rotation,vec); *this *= rot; - return *this; - } - -#endif - - -}; - -// -// Specializations -// - -template <> inline -float matrix_<1,1,float>::determinant() const -{ - return this->at(0); -} - -template <> inline -double matrix_<1,1,double>::determinant() const -{ - return this->at(0); -} - - -#if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE - -template -class matrix31 : public matrix<3,1,T> { -public: - - using matrix<3,1,T>::operator =; - - inline static - matrix<3,1,T> Cross(const matrix<3,1,T>& vec1, const matrix<3,1,T>& vec2) - { - matrix<3,1,T> res; - - res.at(0) = vec1.at(1) * vec2.at(2) - vec2.at(1) * vec1.at(2); - res.at(1) = vec1.at(2) * vec2.at(0) - vec2.at(2) * vec1.at(0); - res.at(2) = vec1.at(0) * vec2.at(1) - vec2.at(0) * vec1.at(1); - - return res; - } -}; - -template -matrix<4,4,T> -matrix44::AngleAxis(const T &radianRotation, const matrix<3,1,T> &vec) -{ - matrix44 R = matrix44::Identity(); - - if (vec.norm() < std::numeric_limits::epsilon()) return R; - - T _fCos = (T) cos (radianRotation); - - matrix<3,1,T> _vCos(vec * (1 - _fCos)); - matrix<3,1,T> _vSin(vec * (T)sin(radianRotation)); - - R.at(0) = (T) ((vec(0,0) * _vCos(0,0)) + _fCos); - R.at(4) = (T) ((vec(0,0) * _vCos(1,0)) - _vSin(2,0)); - R.at(8) = (T) ((vec(0,0) * _vCos(2,0)) + _vSin(1,0)); - - R.at(1) = (T) ((vec(1,0) * _vCos(0,0)) + _vSin(2,0)); - R.at(5) = (T) ((vec(1,0) * _vCos(1,0)) + _fCos); - R.at(9) = (T) ((vec(1,0) * _vCos(2,0)) - _vSin(0,0)); - - R.at(2) = (T) ((vec(2,0) * _vCos(0,0)) - _vSin(1,0)); - R.at(6) = (T) ((vec(2,0) * _vCos(1,0)) + _vSin(0,0)); - R.at(10)= (T) ((vec(2,0) * _vCos(2,0)) + _fCos); - - return R; -} - -template -matrix<4,4,T> -matrix44::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const matrix<3,1,T> &up) -{ - matrix<4,4,T> lookat = matrix<4,4,T>::Identity(); - - matrix<3,1,T> L; L = target - eye; - L.normalize(); - matrix<3,1,T> S = matrix31::Cross(L,up); - S.normalize(); - matrix<3,1,T> Ud = matrix31::Cross(S,L); - Ud.normalize(); - - lookat(0,0) = S.at(0); - lookat(0,1) = S.at(1); - lookat(0,2) = S.at(2); - lookat(0,3) = T(0); - - lookat(1,0) = Ud.at(0); - lookat(1,1) = Ud.at(1); - lookat(1,2) = Ud.at(2); - lookat(1,3) = T(0); - - lookat(2,0) = -L.at(0); - lookat(2,1) = -L.at(1); - lookat(2,2) = -L.at(2); - lookat(3,2) = T(0); - - lookat(3,0) = eye.at(0); - lookat(3,1) = eye.at(1); - lookat(3,2) = eye.at(2); - lookat(3,3) = 1; - - return lookat; + using matrix3x3f = matrix3x3_; + using matrix3x3d = matrix3x3_; + using matrix3x3 = matrix3x3_; + using matrix4x4f = matrix4x4_; + using matrix4x4d = matrix4x4_; + using matrix4x4 = matrix4x4_; } #endif - - -// predefined matricies - -typedef matrix4x4_ matrix4x4; - -typedef matrix4x4_ matrix4x4d; -typedef matrix4x4_ matrix4x4f; - -} - -#endif - - -#endif - - diff --git a/src/deps/lua-5.4.2/CMakeLists.txt b/src/deps/lua-5.4.2/CMakeLists.txt index fc3850d..3cc3ed1 100644 --- a/src/deps/lua-5.4.2/CMakeLists.txt +++ b/src/deps/lua-5.4.2/CMakeLists.txt @@ -1,4 +1,4 @@ -cmake_minimum_required (VERSION 2.6) +cmake_minimum_required (VERSION 3.20) project (lua) diff --git a/src/visual/src/renderer.cpp b/src/visual/src/renderer.cpp index 0e9bbb1..81a7b23 100644 --- a/src/visual/src/renderer.cpp +++ b/src/visual/src/renderer.cpp @@ -124,7 +124,7 @@ struct renderer::impl { this->_change_count = m.change_count(); -#if 0 +#if 1 // get errors auto error = glGetError(); if (error != GL_NO_ERROR) { diff --git a/src/visual/src/shader.cpp b/src/visual/src/shader.cpp index 064f172..630e428 100644 --- a/src/visual/src/shader.cpp +++ b/src/visual/src/shader.cpp @@ -159,17 +159,17 @@ struct shader::impl void bind(int location,const matrix3x3f& m) { - glUniformMatrix3fv(location,1,GL_FALSE,m.data); + glUniformMatrix3fv(location,1,GL_FALSE,m.ptr()); } void bind(int location,const matrix4x4f& m) { - glUniformMatrix4fv(location,1,GL_FALSE,m.data); + glUniformMatrix4fv(location,1,GL_FALSE,m.ptr()); } void bind(int location,const vector4f& v) { - glUniform4fv(location,1,v.data); + glUniform4fv(location,1,v.ptr()); } void bind(int location,const float& v)