merge mesh
This commit is contained in:
commit
a197dd98e8
5 changed files with 77 additions and 24 deletions
|
@ -48,6 +48,11 @@ public:
|
||||||
|
|
||||||
matrix_& operator = (const matrix_& other);
|
matrix_& operator = (const matrix_& other);
|
||||||
|
|
||||||
|
matrix_(std::initializer_list<T> il)
|
||||||
|
{
|
||||||
|
// for (int i = 0;i < il.size();i++) (*this).at(i) = il[i];
|
||||||
|
}
|
||||||
|
|
||||||
matrix_ transposed() const;
|
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; }
|
||||||
|
@ -102,7 +107,7 @@ public:
|
||||||
matrix_<R,C,T>& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; }
|
matrix_<R,C,T>& copy_from_data(const T* src) { for (unsigned int i = 0; i < R*C; ++i) { (*this).at(i) = src[i]; } return *this; }
|
||||||
|
|
||||||
matrix_<R,C,T> operator * (const matrix_<R,C,T>& rhs) const {
|
matrix_<R,C,T> operator * (const matrix_<R,C,T>& rhs) const {
|
||||||
return mul(*this,rhs);
|
return mul(rhs);
|
||||||
}
|
}
|
||||||
|
|
||||||
const matrix_<C,R,T> reshape() const {
|
const matrix_<C,R,T> reshape() const {
|
||||||
|
@ -124,6 +129,26 @@ public:
|
||||||
}
|
}
|
||||||
|
|
||||||
void normalize();
|
void normalize();
|
||||||
|
|
||||||
|
template <unsigned int bC>
|
||||||
|
matrix_<R,bC,T> mul(const matrix_<R,bC,T>& B) const
|
||||||
|
{
|
||||||
|
// aC == bR
|
||||||
|
// set all null
|
||||||
|
matrix_<R,bC,T> 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;
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
/////////////////////////////////////////////////////////////////////////////
|
/////////////////////////////////////////////////////////////////////////////
|
||||||
|
@ -176,28 +201,32 @@ inline matrix_<R,C,T> operator - (const matrix_<R,C,T>& a, const matrix_<R,C,T>&
|
||||||
return res;
|
return res;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
//template <unsigned int aR,unsigned int aCbR, unsigned int bC, typename T>
|
||||||
|
//matrix_<aR,bC,T> static inline
|
||||||
|
//mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
|
||||||
|
//{
|
||||||
|
// // aC == bR
|
||||||
|
// // set all null
|
||||||
|
// matrix_<aR,bC,T> 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 <unsigned int aR,unsigned int aCbR, unsigned int bC, typename T>
|
|
||||||
matrix_<aR,bC,T> static inline
|
|
||||||
mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
|
|
||||||
{
|
|
||||||
// aC == bR
|
|
||||||
// set all null
|
|
||||||
matrix_<aR,bC,T> 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;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
@ -206,7 +235,7 @@ mul(const matrix_<aR,aCbR,T>& A, const matrix_<aCbR,bC,T>& B)
|
||||||
template <unsigned int R, unsigned int C,typename T>
|
template <unsigned int R, unsigned int C,typename T>
|
||||||
matrix_<R,C,T>& matrix_<R,C,T>::operator *= (const matrix_& rhs)
|
matrix_<R,C,T>& matrix_<R,C,T>::operator *= (const matrix_& rhs)
|
||||||
{
|
{
|
||||||
*this = mul(*this,rhs);
|
*this = mul(rhs);
|
||||||
return *this;
|
return *this;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -23,6 +23,9 @@
|
||||||
#ifndef PW_CORE_MATRIXBASE_HPP
|
#ifndef PW_CORE_MATRIXBASE_HPP
|
||||||
#define PW_CORE_MATRIXBASE_HPP
|
#define PW_CORE_MATRIXBASE_HPP
|
||||||
|
|
||||||
|
|
||||||
|
#include <initializer_list>
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
/**
|
/**
|
||||||
|
@ -36,6 +39,9 @@ public:
|
||||||
typedef unsigned int size_type;
|
typedef unsigned int size_type;
|
||||||
|
|
||||||
|
|
||||||
|
matrixbase() {}
|
||||||
|
|
||||||
|
|
||||||
//! assignment constructor
|
//! assignment constructor
|
||||||
explicit matrixbase(int rows, int cols,T* ptr,bool row_major,int data_offset = 0)
|
explicit matrixbase(int rows, int cols,T* ptr,bool row_major,int data_offset = 0)
|
||||||
: _data(ptr)
|
: _data(ptr)
|
||||||
|
@ -47,6 +53,11 @@ public:
|
||||||
{
|
{
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// matrixbase(std::initializer_list<T> il)
|
||||||
|
// {
|
||||||
|
// for (int i = 0;i < il.size();i++) this->at(i) = il[i];
|
||||||
|
// }
|
||||||
|
|
||||||
inline const T& get_element(int e) const { return this->at(e); }
|
inline const T& get_element(int e) const { return this->at(e); }
|
||||||
inline void set_element(int e,const T &v) { this->at(e) = v; }
|
inline void set_element(int e,const T &v) { this->at(e) = v; }
|
||||||
|
|
||||||
|
|
|
@ -54,6 +54,8 @@ public:
|
||||||
void set_topology(topology_type t) { _topology = t; }
|
void set_topology(topology_type t) { _topology = t; }
|
||||||
topology_type topology() { return _topology; }
|
topology_type topology() { return _topology; }
|
||||||
|
|
||||||
|
void apply(const matrix4x4& m);
|
||||||
|
|
||||||
void reset();
|
void reset();
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
|
@ -98,8 +98,8 @@ public:
|
||||||
T& z() { return (*this)(2); }
|
T& z() { return (*this)(2); }
|
||||||
|
|
||||||
|
|
||||||
const vector_<4,T> project(const T& w) const {
|
vector_<4,T> project(const T& w) const {
|
||||||
return vector_<4,T>(x(),y(),z(),w);
|
return vector_<4,T>({ x(),y(),z(),w } );
|
||||||
}
|
}
|
||||||
|
|
||||||
const vector_<2,T> unproject() const {
|
const vector_<2,T> unproject() const {
|
||||||
|
|
|
@ -3,6 +3,17 @@
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
void mesh::apply(const matrix4x4 &m)
|
||||||
|
{
|
||||||
|
for (auto &v : _vertices)
|
||||||
|
{
|
||||||
|
// v = m * v.project(1);
|
||||||
|
|
||||||
|
auto vh = v.project(1);
|
||||||
|
m.mul(vh);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue