bringing all back together
This commit is contained in:
parent
8d563cfc22
commit
4ff557d446
18 changed files with 214 additions and 419 deletions
|
@ -1,13 +1,13 @@
|
|||
#add_subdirectory(deps)
|
||||
add_subdirectory(deps)
|
||||
|
||||
add_subdirectory(core)
|
||||
#add_subdirectory(scene)
|
||||
#add_subdirectory(system)
|
||||
#add_subdirectory(io)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(system)
|
||||
add_subdirectory(io)
|
||||
|
||||
#add_subdirectory(ui)
|
||||
#add_subdirectory(scripting)
|
||||
#add_subdirectory(visual)
|
||||
#add_subdirectory(geometry)
|
||||
add_subdirectory(scripting)
|
||||
add_subdirectory(visual)
|
||||
add_subdirectory(geometry)
|
||||
|
||||
#add_subdirectory(engine)
|
||||
add_subdirectory(engine)
|
||||
|
|
|
@ -26,10 +26,10 @@ set(misc
|
|||
)
|
||||
|
||||
set(srcs
|
||||
# src/buffer.cpp
|
||||
# src/buffer.cpp
|
||||
src/image.cpp
|
||||
src/debug.cpp
|
||||
# src/mesh.cpp
|
||||
src/mesh.cpp
|
||||
src/core.cpp
|
||||
src/serialize.cpp
|
||||
src/timer.cpp
|
||||
|
|
|
@ -57,15 +57,12 @@ struct matrix_ : matrixbase_<T, matrix_<R, C, T>>
|
|||
return *this;
|
||||
}
|
||||
|
||||
|
||||
explicit matrix_(std::initializer_list<T> args)
|
||||
matrix_(std::initializer_list<T> args)
|
||||
{
|
||||
typename std::initializer_list<T>::iterator it = args.begin();
|
||||
for (;it != args.end();it++) data[it-args.begin()] = *it;
|
||||
}
|
||||
|
||||
|
||||
|
||||
template <typename... Arguments>
|
||||
matrix_& set(Arguments ...values)
|
||||
{
|
||||
|
@ -200,7 +197,11 @@ struct matrix_ : matrixbase_<T, matrix_<R, C, T>>
|
|||
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;
|
||||
}
|
||||
};
|
||||
|
||||
template <> inline
|
||||
|
@ -236,48 +237,79 @@ auto operator * (const matrix_<R, Ca, T>& A,
|
|||
|
||||
|
||||
template <typename T> using matrix2x2_ = matrix_<2, 2, T>;
|
||||
//template <typename T> using matrix3x3_ = matrix_<T, 3, 3>;
|
||||
//template <typename T> using matrix4x4_ = matrix_<T, 4, 4>;
|
||||
template <typename T> using matrix3x3_ = matrix_<3, 3, T>;
|
||||
template <typename T> using matrix4x4_ = matrix_<4, 4, T>;
|
||||
|
||||
using matrix2x2f = matrix_<2, 2,float>;
|
||||
using matrix2x2d = matrix_<2, 2,double>;
|
||||
using matrix2x2 = matrix_<2, 2,real_t>;
|
||||
|
||||
//using matrix3x3f = matrix_<float, 3, 3>;
|
||||
//using matrix3x3d = matrix_<double, 3, 3>;
|
||||
//using matrix3x3 = matrix_<real_t, 3, 3>;
|
||||
using matrix3x3f = matrix_<3, 3,float>;
|
||||
using matrix3x3d = matrix_<3, 3,double>;
|
||||
using matrix3x3 = matrix_<3, 3,real_t>;
|
||||
|
||||
//using matrix4x4f = matrix_<float, 4, 4>;
|
||||
//using matrix4x4d = matrix_<double, 4, 4>;
|
||||
//using matrix4x4 = matrix_<real_t, 4, 4>;
|
||||
using matrix4x4f = matrix_<4, 4,float>;
|
||||
using matrix4x4d = matrix_<4, 4,double>;
|
||||
using matrix4x4 = matrix_<4, 4,real_t>;
|
||||
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
//template <typename T>
|
||||
//struct matrix_tools {
|
||||
template <typename T>
|
||||
struct transform_tools {
|
||||
|
||||
// inline static
|
||||
// matrix4x4_<T> projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar)
|
||||
// {
|
||||
// matrix4x4_<T> frustum;
|
||||
inline static
|
||||
matrix4x4_<T> projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar)
|
||||
{
|
||||
matrix4x4_<T> frustum;
|
||||
|
||||
// frustum.fill(0);
|
||||
frustum.fill(0);
|
||||
|
||||
// frustum(0,0) = T(2) * zNear/(Right-Left);
|
||||
// frustum(1,1) = T(2) * zNear/(Top-Bottom);
|
||||
frustum(0,0) = T(2) * zNear/(Right-Left);
|
||||
frustum(1,1) = T(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) = -(T(2) * zFar*zNear)/(zFar-zNear); //D
|
||||
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) = -(T(2) * zFar*zNear)/(zFar-zNear); //D
|
||||
|
||||
// frustum(2,3) = -T(1);
|
||||
frustum(2,3) = -T(1);
|
||||
|
||||
// return frustum;
|
||||
// }
|
||||
//};
|
||||
return frustum;
|
||||
}
|
||||
|
||||
inline static
|
||||
matrix_<4,4,T> orthogonal_projection(T Left, T Right,
|
||||
T Bottom,T Top,
|
||||
T Near, T Far)
|
||||
{
|
||||
|
||||
matrix_<4,4,T> ortho;
|
||||
|
||||
ortho.fill(0);
|
||||
ortho(0,0) = 2 / (Right-Left);
|
||||
ortho(1,1) = 2 / (Top-Bottom);
|
||||
ortho(2,2) = -2 / (Far-Near);
|
||||
|
||||
ortho(0,3) = -(Right+Left)/(Right-Left);
|
||||
ortho(1,3) = -(Top+Bottom)/(Top-Bottom);
|
||||
ortho(2,3) = -(Far+Near)/(Far-Near);
|
||||
|
||||
ortho(3,3) = 1;
|
||||
|
||||
return ortho;
|
||||
}
|
||||
|
||||
inline static
|
||||
matrix_<4,4,T> perspective_projection(T fovY, T aspectRatio, T zNear, T zFar)
|
||||
{
|
||||
const T height = zNear * tan(fovY/T(360) * pi<T>()); // half height of near plane
|
||||
const T width = height * aspectRatio; // half width of near plane
|
||||
|
||||
return projection_from_frustum(-width, width, -height, height, zNear, zFar );
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
@ -624,57 +656,6 @@ public:
|
|||
return *this;
|
||||
}
|
||||
|
||||
inline static
|
||||
matrix_<4,4,T> projection_from_frustum(T Left,T Right,T Bottom,T Top,T zNear,T zFar)
|
||||
{
|
||||
matrix_<4,4,T> frustum;
|
||||
|
||||
frustum.fill(0);
|
||||
|
||||
frustum.at(0,0) = 2 * zNear/(Right-Left);
|
||||
frustum.at(1,1) = 2 * zNear/(Top-Bottom);
|
||||
|
||||
frustum.at(0,2) = (Right+Left)/(Right-Left); //A
|
||||
frustum.at(1,2) = (Top+Bottom)/(Top-Bottom); //B
|
||||
frustum.at(2,2) = - (zFar+zNear)/(zFar-zNear); //C
|
||||
frustum.at(3,2) = -(2 * zFar*zNear)/(zFar-zNear); //D
|
||||
|
||||
frustum.at(2,3) = -1;
|
||||
|
||||
return frustum;
|
||||
}
|
||||
|
||||
inline static
|
||||
matrix_<4,4,T> orthogonal_projection(T Left, T Right,
|
||||
T Bottom,T Top,
|
||||
T Near, T Far)
|
||||
{
|
||||
|
||||
matrix_<4,4,T> ortho;
|
||||
|
||||
ortho.fill(0);
|
||||
ortho(0,0) = 2 / (Right-Left);
|
||||
ortho(1,1) = 2 / (Top-Bottom);
|
||||
ortho(2,2) = -2 / (Far-Near);
|
||||
|
||||
ortho(0,3) = -(Right+Left)/(Right-Left);
|
||||
ortho(1,3) = -(Top+Bottom)/(Top-Bottom);
|
||||
ortho(2,3) = -(Far+Near)/(Far-Near);
|
||||
|
||||
ortho(3,3) = 1;
|
||||
|
||||
return ortho;
|
||||
}
|
||||
|
||||
|
||||
inline static
|
||||
matrix_<4,4,T> perspective_projection(T fovY, T aspectRatio, T zNear, T zFar)
|
||||
{
|
||||
const T height = zNear * tan(fovY/T(360) * pi<T>()); // half height of near plane
|
||||
const T width = height * aspectRatio; // half width of near plane
|
||||
|
||||
return projection_from_frustum(-width, width, -height, height, zNear, zFar );
|
||||
}
|
||||
|
||||
|
||||
#if TACIT_PIXEL_STUFF_NEEDS_TO_MOVE_TO_SCENE
|
||||
|
|
|
@ -1,6 +1,3 @@
|
|||
#ifndef PW_CORE_MESH_HPP
|
||||
#define PW_CORE_MESH_HPP
|
||||
|
||||
/*
|
||||
* Copyright (c) 1999-2019 Hartmut Seichter
|
||||
*
|
||||
|
@ -23,6 +20,9 @@
|
|||
* SOFTWARE.
|
||||
*
|
||||
*/
|
||||
#ifndef PW_CORE_MESH_HPP
|
||||
#define PW_CORE_MESH_HPP
|
||||
|
||||
#include <pw/core/globals.hpp>
|
||||
#include <pw/core/vector.hpp>
|
||||
|
||||
|
|
|
@ -34,16 +34,18 @@ namespace pw {
|
|||
template <typename T>
|
||||
struct quaternion_ : vector4_<T> {
|
||||
|
||||
typedef vector4_<T> Base;
|
||||
typedef vector4_<T> base_type;
|
||||
|
||||
using Base::Base;
|
||||
using Base::x;
|
||||
using Base::y;
|
||||
using Base::z;
|
||||
using Base::w;
|
||||
using Base::lerp;
|
||||
using Base::operator*;
|
||||
using Base::operator/;
|
||||
using base_type::base_type;
|
||||
using base_type::x;
|
||||
using base_type::y;
|
||||
using base_type::z;
|
||||
using base_type::w;
|
||||
using base_type::lerp;
|
||||
using base_type::operator*;
|
||||
using base_type::operator/;
|
||||
|
||||
quaternion_(const base_type& other) : base_type(other) {}
|
||||
|
||||
inline const quaternion_ operator * (const quaternion_& rhs) const {
|
||||
return quaternion_(
|
||||
|
@ -97,7 +99,7 @@ struct quaternion_ : vector4_<T> {
|
|||
return m;
|
||||
}
|
||||
|
||||
static quaternion_<T> from_matrix(const matrix_<T,4,4> &m) {
|
||||
static quaternion_<T> from_matrix(const matrix_<4,4,T> &m) {
|
||||
using std::sqrt;
|
||||
const T wtemp = sqrt(T(1) + m(0,0) + m(1,1) + m(2,2)) / T(2);
|
||||
const T w4 = T(4.0) * wtemp;
|
||||
|
|
|
@ -27,19 +27,6 @@
|
|||
|
||||
namespace pw {
|
||||
|
||||
//template <std::size_t N,typename T>
|
||||
//struct vector_ : matrix_<N,1,T>
|
||||
//{
|
||||
// static const size_t coefficients = N;
|
||||
|
||||
// using matrix_<N,1,T>::matrix_;
|
||||
// using matrix_<N,1,T>::operator =;
|
||||
|
||||
//// static T angle_between(const vector_ &a,const vector_ &b) {
|
||||
//// return std::acos( dot( a.normalized(), b.normalized() ) );
|
||||
//// }
|
||||
//};
|
||||
|
||||
template <typename T>
|
||||
struct vector2_ : matrix_<2,1,T> {
|
||||
|
||||
|
@ -49,6 +36,7 @@ struct vector2_ : matrix_<2,1,T> {
|
|||
using base_type::operator = ;
|
||||
|
||||
vector2_(const base_type& m) : base_type(m) {}
|
||||
vector2_(T x_,T y_) : base_type({x_,y_}) {}
|
||||
|
||||
inline const T& x() const { return (*this)[0]; }
|
||||
inline T& x() { return (*this)[0]; }
|
||||
|
@ -58,6 +46,10 @@ struct vector2_ : matrix_<2,1,T> {
|
|||
|
||||
inline auto homogenous(T w = 1) const { return matrix_<3,1,T>( { x(),y(),w } ); }
|
||||
|
||||
static T angle_between(const vector2_ &a,const vector2_ &b) {
|
||||
return std::acos( dot( a.normalized(), b.normalized() ) );
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
template <typename T>
|
||||
|
@ -69,7 +61,7 @@ struct vector3_ : matrix_<3,1,T> {
|
|||
using base_type::operator = ;
|
||||
|
||||
vector3_(const base_type& m) : base_type(m) {}
|
||||
|
||||
vector3_(T x_,T y_,T z_) : base_type({x_,y_,z_}) {}
|
||||
|
||||
inline const T& x() const { return (*this)[0]; }
|
||||
inline T& x() { return (*this)[0]; }
|
||||
|
@ -83,6 +75,16 @@ struct vector3_ : matrix_<3,1,T> {
|
|||
inline auto xy() const { return vector2_( { x(),y() } ); }
|
||||
inline auto homogenous(T w = 1) const { return matrix_<4,1,T>( { x(),y(),z(),w } ); }
|
||||
|
||||
inline const vector3_ cross(const vector3_& rhs) const {
|
||||
return vector3_( {
|
||||
(*this)[1] * rhs[2] - rhs[1] * (*this)[2],
|
||||
(*this)[2] * rhs[0] - rhs[2] * (*this)[0],
|
||||
(*this)[0] * rhs[1] - rhs[0] * (*this)[1]
|
||||
}
|
||||
);
|
||||
}
|
||||
|
||||
|
||||
inline static vector3_<T> forward() { return vector3_<T> ( { T(0), T(0),-T(1) } ); }
|
||||
inline static vector3_<T> backward() { return vector3_<T>( { T(0), T(0), T(1) } ); }
|
||||
inline static vector3_<T> right() { return vector3_<T> ( { T(1), T(0), T(0) } ); }
|
||||
|
@ -92,15 +94,16 @@ struct vector3_ : matrix_<3,1,T> {
|
|||
|
||||
};
|
||||
|
||||
|
||||
#if defined(_D)
|
||||
|
||||
|
||||
|
||||
template <typename T>
|
||||
struct vector4_ : vector_<T,4> {
|
||||
struct vector4_ : matrix_<4,1,T> {
|
||||
|
||||
using vector_<T,4>::vector_;
|
||||
typedef matrix_<4,1,T> base_type;
|
||||
|
||||
using base_type::base_type;
|
||||
using base_type::operator = ;
|
||||
|
||||
vector4_(T x_,T y_,T z_,T w_) : base_type({x_,y_,z_,w_}) {}
|
||||
vector4_(const base_type& m) : base_type(m) {}
|
||||
|
||||
inline const T& x() const { return (*this)[0]; }
|
||||
inline T& x() { return (*this)[0]; }
|
||||
|
@ -117,221 +120,24 @@ struct vector4_ : vector_<T,4> {
|
|||
inline auto xyz() const { return vector3_<T>({ x(),y(),z() } ); }
|
||||
|
||||
inline auto project() const { return vector3_<T>({ x()/w(),y()/w(),z()/w() } ); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
#endif
|
||||
//
|
||||
//
|
||||
//
|
||||
|
||||
using vector2f = vector2_<float>;
|
||||
using vector2d = vector2_<double>;
|
||||
//using vector2 = vector2_<real_t>;
|
||||
using vector2 = vector2_<real_t>;
|
||||
|
||||
//using vector3f = vector3_<float>;
|
||||
//using vector3d = vector3_<double>;
|
||||
//using vector3 = vector3_<real_t>;
|
||||
|
||||
//using vector4f = vector4_<float>;
|
||||
//using vector4d = vector4_<double>;
|
||||
//using vector4 = vector4_<real_t>;
|
||||
using vector3f = vector3_<float>;
|
||||
using vector3d = vector3_<double>;
|
||||
using vector3 = vector3_<real_t>;
|
||||
|
||||
using vector4f = vector4_<float>;
|
||||
using vector4d = vector4_<double>;
|
||||
using vector4 = vector4_<real_t>;
|
||||
|
||||
}
|
||||
|
||||
|
||||
#if defined(___OLDSTUFF)
|
||||
|
||||
template <unsigned int components,typename T>
|
||||
class vector_ : public matrix_<components,1,T> {
|
||||
public:
|
||||
|
||||
using typename matrix_<components,1,T>::value_type;
|
||||
using matrix_<components,1,T>::operator = ;
|
||||
|
||||
vector_() : matrix_<components,1,T>() {}
|
||||
|
||||
vector_(const vector_& other) : matrix_<components,1,T>(other) {}
|
||||
|
||||
vector_(const matrix_<components,1,T>& other) : matrix_<components,1,T>(other) {}
|
||||
|
||||
T& operator()(unsigned int c) { return matrixbase<T>::at(c); }
|
||||
const T& operator()(unsigned int c) const { return matrixbase<T>::at(c); }
|
||||
|
||||
|
||||
const T dot(const vector_<components,T>& other) const {
|
||||
T res = 0;
|
||||
for (unsigned int i = 0; i < components; i++) res += (*this)(i) * other(i);
|
||||
return res;
|
||||
}
|
||||
|
||||
const T angle_to(const vector_<components,T>& other) const {
|
||||
using std::acos;
|
||||
vector_<components,T> nself(*this); vector_<components,T> nothr = other;
|
||||
nself.normalize(); nothr.normalize();
|
||||
return acos( nothr.dot(nself) );
|
||||
}
|
||||
|
||||
|
||||
vector_<components+1,T> homogenous(const T& w) const {
|
||||
return vector_<components+1,T>();
|
||||
}
|
||||
|
||||
const vector_<2,T> project() const {
|
||||
return vector_<2,T>(x()/z(),y()/z());
|
||||
}
|
||||
|
||||
};
|
||||
|
||||
|
||||
// Vec3 -----------------------------------------------------------------------
|
||||
|
||||
template <class T>
|
||||
class vector3_ : public vector_<3,T> {
|
||||
public:
|
||||
|
||||
using vector_<3,T>::operator=;
|
||||
|
||||
vector3_() : vector_<3,T>() {}
|
||||
|
||||
vector3_(const vector_<3,T>& other) : vector_<3, T> (other) {}
|
||||
|
||||
vector3_(T c1, T c2, T c3) { this->set(c1,c2,c3); }
|
||||
|
||||
void set(T c1, T c2, T c3) { (*this)(0) = c1; (*this)(1) = c2; (*this)(2) = c3; }
|
||||
|
||||
vector3_ clone() const { return vector3_(*this); }
|
||||
|
||||
inline void set_x(const T& v) { x() = v; }
|
||||
inline void set_y(const T& v) { y() = v; }
|
||||
inline void set_z(const T& v) { z() = v; }
|
||||
|
||||
inline const vector3_ cross(const vector3_<T>& vec2) const {
|
||||
return vector3_<T>((*this)(1) * vec2(2) - vec2(1) * (*this)(2),
|
||||
(*this)(2) * vec2(0) - vec2(2) * (*this)(0),
|
||||
(*this)(0) * vec2(1) - vec2(0) * (*this)(1));
|
||||
}
|
||||
|
||||
inline const T& x() const { return (*this)(0); }
|
||||
inline T& x() { return (*this)(0); }
|
||||
|
||||
const T& y() const { return (*this)(1); }
|
||||
T& y() { return (*this)(1); }
|
||||
|
||||
const T& z() const { return (*this)(2); }
|
||||
T& z() { return (*this)(2); }
|
||||
|
||||
|
||||
|
||||
inline static vector3_<T> forward() { return vector3_<T> ( 0, 0,-1); }
|
||||
inline static vector3_<T> backward() { return vector3_<T>( 0, 0, 1); }
|
||||
inline static vector3_<T> right() { return vector3_<T> ( 1, 0, 0); }
|
||||
inline static vector3_<T> left() { return vector3_<T> (-1, 0, 0); }
|
||||
inline static vector3_<T> up() { return vector3_<T> ( 0, 1, 0); }
|
||||
inline static vector3_<T> down() { return vector3_<T> ( 0,-1, 0); }
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
||||
// Vec2x -----------------------------------------------------------------------
|
||||
|
||||
template <class T> class vector2_ : public vector_<2,T> {
|
||||
public:
|
||||
|
||||
vector2_() {}
|
||||
|
||||
vector2_(T v1,T v2) {
|
||||
this->set(v1,v2);
|
||||
}
|
||||
|
||||
void set(T v1,T v2) {
|
||||
(*this)(0) = v1; (*this)(1) = v2;
|
||||
}
|
||||
|
||||
const T& x() const { return (*this)(0); }
|
||||
T& x() { return (*this)(0); }
|
||||
|
||||
const T& y() const { return (*this)(1); }
|
||||
T& y() { return (*this)(1); }
|
||||
|
||||
};
|
||||
|
||||
// Vec4 -----------------------------------------------------------------------
|
||||
|
||||
template <typename T> class vector4_ : public vector_<4,T> {
|
||||
public:
|
||||
|
||||
using vector_<4,T>::vector_;
|
||||
|
||||
vector4_(const T& v1,const T& v2,const T& v3,const T& v4) {
|
||||
this->set(v1,v2,v3,v4);
|
||||
}
|
||||
|
||||
void set(const T& v1,const T& v2,const T& v3,const T& v4) {
|
||||
(*this)(0) = v1;
|
||||
(*this)(1) = v2;
|
||||
(*this)(2) = v3;
|
||||
(*this)(3) = v4;
|
||||
}
|
||||
|
||||
inline const vector3_<T> xyz() const { return vector3_<T>(x(),y(),z()); }
|
||||
inline const vector2_<T> xy() const { return vector2_<T>(x(),y()); }
|
||||
|
||||
const T& x() const { return (*this)(0); }
|
||||
T& x() { return (*this)(0); }
|
||||
|
||||
const T& y() const { return (*this)(1); }
|
||||
T& y() { return (*this)(1); }
|
||||
|
||||
const T& z() const { return (*this)(2); }
|
||||
T& z() { return (*this)(2); }
|
||||
|
||||
const T& w() const { return (*this)(3); }
|
||||
T& w() { return (*this)(3); }
|
||||
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
typedef vector2_<unsigned char> vector2ub;
|
||||
typedef vector2_<char> vector2b;
|
||||
typedef vector2_<unsigned short> vector2us;
|
||||
typedef vector2_<short> vector2s;
|
||||
typedef vector2_<unsigned int> vector2ui;
|
||||
typedef vector2_<int> vector2i;
|
||||
typedef vector2_<unsigned long> vector2ul;
|
||||
typedef vector2_<long> vector2l;
|
||||
|
||||
typedef vector2_<double> vector2d;
|
||||
typedef vector2_<float> vector2f;
|
||||
typedef vector2_<real_t> vector2;
|
||||
|
||||
typedef vector3_<real_t> vector3;
|
||||
typedef vector3_<double> vector3d;
|
||||
typedef vector3_<float> vector3f;
|
||||
typedef vector3_<int> vector3i;
|
||||
typedef vector3_<unsigned int> vector3ui;
|
||||
|
||||
|
||||
typedef vector4_<real_t> vector4;
|
||||
typedef vector4_<double> vector4d;
|
||||
typedef vector4_<float> vector4f;
|
||||
typedef vector4_<int> vector4i;
|
||||
typedef vector4_<unsigned int> vector4ui;
|
||||
|
||||
}
|
||||
|
||||
|
||||
//////////////////////////////////////////////////////////////////////////
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
|
||||
#endif
|
||||
|
|
|
@ -6,14 +6,8 @@ namespace pw {
|
|||
void mesh::apply(const matrix4x4 &m)
|
||||
{
|
||||
for (auto &v : _vertices)
|
||||
{
|
||||
// v = vector4(m * v.project(1)).un_project();
|
||||
|
||||
// auto vh = v.project(1);
|
||||
// m.mul(vh);
|
||||
}
|
||||
v = vector4(m * v.homogenous()).project();
|
||||
}
|
||||
|
||||
|
||||
|
||||
}
|
||||
|
|
|
@ -5,25 +5,25 @@ add_executable(pwcore_test_matrix
|
|||
target_link_libraries(pwcore_test_matrix
|
||||
pwcore)
|
||||
|
||||
#add_executable(pwcore_test_vector
|
||||
# pwcore_test_vector.cpp
|
||||
# )
|
||||
add_executable(pwcore_test_vector
|
||||
pwcore_test_vector.cpp
|
||||
)
|
||||
|
||||
#target_link_libraries(pwcore_test_vector
|
||||
# pwcore)
|
||||
target_link_libraries(pwcore_test_vector
|
||||
pwcore)
|
||||
|
||||
|
||||
#add_executable(pwcore_test_quaternion
|
||||
# pwcore_test_quaternion.cpp
|
||||
# )
|
||||
add_executable(pwcore_test_quaternion
|
||||
pwcore_test_quaternion.cpp
|
||||
)
|
||||
|
||||
#target_link_libraries(pwcore_test_quaternion
|
||||
# pwcore)
|
||||
target_link_libraries(pwcore_test_quaternion
|
||||
pwcore)
|
||||
|
||||
|
||||
#add_executable(pwcore_test_axisangle
|
||||
# pwcore_test_axisangle.cpp
|
||||
# )
|
||||
add_executable(pwcore_test_axisangle
|
||||
pwcore_test_axisangle.cpp
|
||||
)
|
||||
|
||||
#target_link_libraries(pwcore_test_axisangle
|
||||
# pwcore)
|
||||
target_link_libraries(pwcore_test_axisangle
|
||||
pwcore)
|
||||
|
|
|
@ -13,6 +13,5 @@ int main(int argc,char **argv) {
|
|||
std::cout << "aa as quaternion as matrix = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
||||
std::cout << "aa.matrix() = " << pw::serialize::matrix(qf.to_matrix()) << std::endl;
|
||||
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
|
|
@ -36,6 +36,7 @@ int main(int argc,char **argv) {
|
|||
auto v2_b = m22_inv * v2_f;
|
||||
|
||||
vector2_<float> r_m22 = m22.row(0).transposed();
|
||||
vector2_<float> c_m22 = m22.column(1);
|
||||
|
||||
auto r_m22_h = r_m22.homogenous();
|
||||
|
||||
|
|
|
@ -6,9 +6,16 @@
|
|||
|
||||
int main(int argc,char **argv) {
|
||||
|
||||
pw::vector2_<float> v2;
|
||||
pw::vector2_<float> v2_A = { 3.2, 1.2 };
|
||||
pw::vector2_<float> v2_B = { 3.2, 1.2 };
|
||||
|
||||
v2.x = 0.1f;
|
||||
|
||||
auto AB_lerp = pw::vector2f::lerp(v2_A,v2_B,0.5);
|
||||
|
||||
|
||||
|
||||
|
||||
// v2 = 0.1f;
|
||||
|
||||
// pw::vector4_<float> v4;
|
||||
// pw::vector3f v;
|
||||
|
|
|
@ -8,15 +8,15 @@ mesh primitives::box(real_t size_x,real_t size_y, real_t size_z)
|
|||
|
||||
mesh::vertex3array_t vertices;
|
||||
|
||||
vertices.push_back(vector3(-size_x / 2,-size_y / 2, size_z / 2)); // 0
|
||||
vertices.push_back(vector3( size_x / 2,-size_y / 2, size_z / 2)); // 1
|
||||
vertices.push_back(vector3( size_x / 2, size_y / 2, size_z / 2)); // 2
|
||||
vertices.push_back(vector3(-size_x / 2, size_y / 2, size_z / 2)); // 3
|
||||
vertices.push_back( { -size_x / 2,-size_y / 2, size_z / 2 } ); // 0
|
||||
vertices.push_back( { size_x / 2,-size_y / 2, size_z / 2 } ); // 1
|
||||
vertices.push_back( { size_x / 2, size_y / 2, size_z / 2 } ); // 2
|
||||
vertices.push_back( {-size_x / 2, size_y / 2, size_z / 2} ); // 3
|
||||
|
||||
vertices.push_back(vector3(-size_x / 2,-size_y / 2,-size_z / 2)); // 4
|
||||
vertices.push_back(vector3( size_x / 2,-size_y / 2,-size_z / 2)); // 5
|
||||
vertices.push_back(vector3( size_x / 2, size_y / 2,-size_z / 2)); // 6
|
||||
vertices.push_back(vector3(-size_x / 2, size_y / 2,-size_z / 2)); // 7
|
||||
vertices.push_back( {-size_x / 2,-size_y / 2,-size_z / 2} ); // 4
|
||||
vertices.push_back( { size_x / 2,-size_y / 2,-size_z / 2}); // 5
|
||||
vertices.push_back( { size_x / 2, size_y / 2,-size_z / 2}); // 6
|
||||
vertices.push_back( {-size_x / 2, size_y / 2,-size_z / 2}); // 7
|
||||
|
||||
mesh::indexarray_t indices = {
|
||||
0, 1, 2, // 0
|
||||
|
|
|
@ -23,17 +23,17 @@ public:
|
|||
void set_global(const matrix4x4 &global);
|
||||
|
||||
inline void translate(const real_t &x, const real_t &y, const real_t &z) {
|
||||
_local.at(0,3) += x;_local.at(1,3) += y;_local.at(2,3) += z;
|
||||
_local(0,3) += x;_local(1,3) += y;_local(2,3) += z;
|
||||
update_global_from_local();
|
||||
}
|
||||
|
||||
inline void rotate(const quaternion& q) {
|
||||
_local *= q.to_matrix();
|
||||
_local = _local * q.to_matrix();
|
||||
update_global_from_local();
|
||||
}
|
||||
|
||||
inline void scale(const real_t &x, const real_t &y, const real_t &z) {
|
||||
_local.at(0,0) *= x; _local.at(1,1) *= y; _local.at(2,2) *= z;
|
||||
_local(0,0) *= x; _local(1,1) *= y; _local(2,2) *= z;
|
||||
update_global_from_local();
|
||||
}
|
||||
|
||||
|
@ -42,7 +42,7 @@ public:
|
|||
}
|
||||
|
||||
inline void set_translation(const real_t &x, const real_t &y, const real_t &z) {
|
||||
_local.at(0,3) = x;_local.at(1,3) = y;_local.at(2,3) = z;
|
||||
_local(0,3) = x;_local(1,3) = y;_local(2,3) = z;
|
||||
update_global_from_local();
|
||||
}
|
||||
|
||||
|
|
|
@ -7,12 +7,14 @@ camera::camera()
|
|||
, _near_plane(0.2f)
|
||||
, _far_plane(1000)
|
||||
{
|
||||
set_projection(matrix4x4::perspective_projection(_fov,1,_near_plane,_far_plane));
|
||||
set_projection(transform_tools<real_t>::perspective_projection(_fov,1,_near_plane,_far_plane));
|
||||
}
|
||||
|
||||
void camera::set_projection(const matrix4x4 &projection)
|
||||
{
|
||||
this->_projection = projection;
|
||||
|
||||
// recompute the simplified parameters
|
||||
}
|
||||
|
||||
const matrix4x4 &camera::projection() const
|
||||
|
|
|
@ -53,7 +53,7 @@ int main(int argc,char **argv) {
|
|||
// auto t = n->transform();
|
||||
|
||||
// if (t)
|
||||
std::cout << n->transform().local().at(0,0) << std::endl;
|
||||
std::cout << n->transform().local()(0,0) << std::endl;
|
||||
// else {
|
||||
// std::cerr << "no transform?" << std::endl;
|
||||
// }
|
||||
|
|
|
@ -19,36 +19,40 @@ void script_core::load(sol::table &ns)
|
|||
ns.set("pi",pw::pi<Scalar>());
|
||||
|
||||
|
||||
ns.new_usertype<vector3>("vector3",
|
||||
sol::constructors<vector3(), vector3(Scalar,Scalar,Scalar)>(),
|
||||
"set",&vector3::set,
|
||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::x), &vector3::set_x),
|
||||
"y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::y), &vector3::set_y),
|
||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::z), &vector3::set_z),
|
||||
"norm",&vector3::norm,
|
||||
"cross",&vector3::cross,
|
||||
"dot",&vector3::dot,
|
||||
// sol::meta_function::addition, sol::resolve<vector3(const vector3&, const vector3&)>(::operator+),
|
||||
// sol::meta_function::subtraction, &vector3::operator-
|
||||
// "v",&vector3::values,
|
||||
"clone",&vector3::clone
|
||||
ns.new_usertype<vector3>(
|
||||
"vector3",
|
||||
sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
|
||||
"x", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::x), [](vector3::value_type v){ x() = v})
|
||||
);
|
||||
|
||||
ns.new_usertype<quaternion>("quaternion",
|
||||
sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
|
||||
"set",&quaternion::set,
|
||||
"x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
|
||||
"y", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::y), &quaternion::set_y),
|
||||
"z", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::z), &quaternion::set_z),
|
||||
"w", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::w), &quaternion::set_w),
|
||||
"dot",&quaternion::dot,
|
||||
"inverse",scripting::readonly_property(&quaternion::inverse),
|
||||
"normalized",&quaternion::normalized,
|
||||
"lerp",&quaternion::lerp,
|
||||
"slerp",&quaternion::slerp
|
||||
// "v",&vector3d::values,
|
||||
// "clone",&vector3d::clone
|
||||
);
|
||||
|
||||
// ns.new_usertype<vector3>("vector3",
|
||||
// sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
|
||||
// "x",&vector3::x
|
||||
//// "set",&vector3::set,
|
||||
//// "x", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::x), &vector3::set_x),
|
||||
//// "y", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::y), &vector3::set_y),
|
||||
//// "z", scripting::property(scripting::resolve<const Scalar&() const>(&vector3::z), &vector3::set_z),
|
||||
//// "norm",&vector3::norm,
|
||||
//// "cross",&vector3::cross,
|
||||
//// "dot",&vector3::dot
|
||||
// );
|
||||
|
||||
// ns.new_usertype<quaternion>("quaternion",
|
||||
// sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
|
||||
// "set",&quaternion::set,
|
||||
// "x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
|
||||
// "y", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::y), &quaternion::set_y),
|
||||
// "z", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::z), &quaternion::set_z),
|
||||
// "w", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::w), &quaternion::set_w),
|
||||
// "dot",&quaternion::dot,
|
||||
// "inverse",scripting::readonly_property(&quaternion::inverse),
|
||||
// "normalized",&quaternion::normalized,
|
||||
// "lerp",&quaternion::lerp,
|
||||
// "slerp",&quaternion::slerp
|
||||
// // "v",&vector3d::values,
|
||||
// // "clone",&vector3d::clone
|
||||
// );
|
||||
|
||||
ns.new_usertype<axisangle>("axisangle",
|
||||
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
||||
|
|
|
@ -9,7 +9,6 @@ namespace pw {
|
|||
// include external namespace of sol
|
||||
namespace scripting = sol;
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
|
|
@ -149,7 +149,7 @@ struct shader::impl
|
|||
|
||||
void bind(int location,const matrix4x4f& m)
|
||||
{
|
||||
glUniformMatrix4fv(location,1,GL_FALSE,m.data()); // TODO transpose?
|
||||
glUniformMatrix4fv(location,1,GL_FALSE,m.data); // TODO transpose?
|
||||
}
|
||||
};
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue