small update to put more transformation code into the right spots
This commit is contained in:
parent
cf0993e2dc
commit
24154087ba
16 changed files with 126 additions and 76 deletions
|
@ -16,6 +16,7 @@ set(hdrs
|
||||||
)
|
)
|
||||||
|
|
||||||
set(srcs
|
set(srcs
|
||||||
|
src/image.cpp
|
||||||
src/log.cpp
|
src/log.cpp
|
||||||
src/core.cpp
|
src/core.cpp
|
||||||
src/serialize.cpp
|
src/serialize.cpp
|
||||||
|
|
|
@ -6,18 +6,18 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class axisangle {
|
class axisangle_ {
|
||||||
protected:
|
protected:
|
||||||
vector3_<T> _axis;
|
vector3_<T> _axis;
|
||||||
T _angle;
|
T _angle;
|
||||||
public:
|
public:
|
||||||
|
|
||||||
axisangle()
|
axisangle_()
|
||||||
: _axis(vector3_<T>::up()),
|
: _axis(vector3_<T>::up()),
|
||||||
_angle(0)
|
_angle(0)
|
||||||
{}
|
{}
|
||||||
|
|
||||||
axisangle(const vector3_<T> &axis,const T &angle)
|
axisangle_(const vector3_<T> &axis,const T &angle)
|
||||||
: _axis(axis)
|
: _axis(axis)
|
||||||
, _angle(angle)
|
, _angle(angle)
|
||||||
{
|
{
|
||||||
|
@ -29,9 +29,43 @@ public:
|
||||||
T angle() const { return _angle; }
|
T angle() const { return _angle; }
|
||||||
void set_angle(const T &angle) { _angle = angle; }
|
void set_angle(const T &angle) { _angle = angle; }
|
||||||
|
|
||||||
|
matrix4x4_<T> to_matrix() const
|
||||||
|
{
|
||||||
|
using std::cos;
|
||||||
|
using std::sin;
|
||||||
|
|
||||||
|
matrix4x4_<T> R; R.set_identity(); // = matrix44<T>::Identity();
|
||||||
|
|
||||||
|
if (_axis.norm() < std::numeric_limits<T>::epsilon()) return R;
|
||||||
|
|
||||||
|
const T _fCos = cos(_angle);
|
||||||
|
|
||||||
|
matrix_<3,1,T> _vCos(_axis * (1 - _fCos));
|
||||||
|
matrix_<3,1,T> _vSin(_axis * sin(_angle));
|
||||||
|
|
||||||
|
// R.at(0) = (_axis(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;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef axisangle<double> axisangled;
|
|
||||||
|
typedef axisangle_<real_t> axisangle;
|
||||||
|
typedef axisangle_<double> axisangled;
|
||||||
|
typedef axisangle_<float> axisanglef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -6,6 +6,16 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
class image {
|
class image {
|
||||||
|
public:
|
||||||
|
|
||||||
|
image() = default;
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
protected:
|
||||||
|
|
||||||
|
std::vector<unsigned char> _data;
|
||||||
|
std::string _uri;
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -320,19 +320,19 @@ void matrix_<R,C,T>::normalize()
|
||||||
// 4x4
|
// 4x4
|
||||||
|
|
||||||
template <typename T>
|
template <typename T>
|
||||||
class matrix44_ : public matrix_<4,4,T>
|
class matrix4x4_ : public matrix_<4,4,T>
|
||||||
{
|
{
|
||||||
public:
|
public:
|
||||||
|
|
||||||
using matrix_<4,4,T>::matrix_;
|
using matrix_<4,4,T>::matrix_;
|
||||||
|
|
||||||
|
|
||||||
matrix44_(const matrix_<4,4,T>& i)
|
matrix4x4_(const matrix_<4,4,T>& i)
|
||||||
{
|
{
|
||||||
*this = i;
|
*this = i;
|
||||||
}
|
}
|
||||||
|
|
||||||
matrix44_& operator = (const matrix_<4,4,T>& rhs) {
|
matrix4x4_& operator = (const matrix_<4,4,T>& rhs) {
|
||||||
if (this != &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(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(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);
|
||||||
|
@ -600,10 +600,10 @@ matrix44<T>::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const
|
||||||
|
|
||||||
// predefined matricies
|
// predefined matricies
|
||||||
|
|
||||||
typedef matrix44_<real_t> matrix44;
|
typedef matrix4x4_<real_t> matrix4x4;
|
||||||
|
|
||||||
typedef matrix44_<double> matrix44d;
|
typedef matrix4x4_<double> matrix4x4d;
|
||||||
typedef matrix44_<float> matrix44f;
|
typedef matrix4x4_<float> matrix4x4f;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -31,19 +31,21 @@
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
template <typename T_>
|
template <typename T_>
|
||||||
struct size {
|
struct size_ {
|
||||||
|
|
||||||
T_ dim[2] = { 0, 0 };
|
T_ dim[2] = { 0, 0 };
|
||||||
|
|
||||||
size(T_ w,T_ h) : dim( { w, h }) {}
|
size_(T_ w,T_ h) : dim( { w, h }) {}
|
||||||
|
|
||||||
const T_ width() { return dim[0]; }
|
const T_ width() { return dim[0]; }
|
||||||
const T_ height() { return dim[1]; }
|
const T_ height() { return dim[1]; }
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
typedef size<int> sizei;
|
typedef size_<real_t> size;
|
||||||
typedef size<float> sizef;
|
|
||||||
|
typedef size_<int> sizei;
|
||||||
|
typedef size_<float> sizef;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -60,7 +60,6 @@ public:
|
||||||
return acos( nothr.dot(nself) );
|
return acos( nothr.dot(nself) );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
@ -106,12 +105,9 @@ public:
|
||||||
return vector_<4,T>(x(),y(),z(),w);
|
return vector_<4,T>(x(),y(),z(),w);
|
||||||
}
|
}
|
||||||
|
|
||||||
#if _GCC_STUPID_
|
const vector_<2,T> unproject() const {
|
||||||
inline std::tuple<T,T,T> values() const {
|
return vector_<2,T>(x()/z(),y()/z());
|
||||||
return std::make_tuple(x(),y(),z());
|
|
||||||
}
|
}
|
||||||
#endif
|
|
||||||
|
|
||||||
|
|
||||||
inline static vector3_<T> forward() { return vector3_<T> ( 0, 0,-1); }
|
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> backward() { return vector3_<T>( 0, 0, 1); }
|
||||||
|
|
|
@ -13,7 +13,7 @@ void test_matrixbase() {
|
||||||
|
|
||||||
using namespace pw;
|
using namespace pw;
|
||||||
|
|
||||||
matrix44f m;
|
matrix4x4f m;
|
||||||
|
|
||||||
m.set_identity();
|
m.set_identity();
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,7 @@
|
||||||
|
#include "pw/core/image.hpp"
|
||||||
|
|
||||||
|
namespace pw {
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
}
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
int main(int argc,char **argv) {
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
pw::axisangle<float> aa = pw::axisangle<float>();
|
pw::axisangle_<float> aa = pw::axisangle_<float>();
|
||||||
|
|
||||||
pw::quaternionf qf = pw::quaternionf::from_axisangle(aa);
|
pw::quaternionf qf = pw::quaternionf::from_axisangle(aa);
|
||||||
|
|
||||||
|
|
|
@ -6,7 +6,7 @@
|
||||||
|
|
||||||
int main(int argc,char **argv) {
|
int main(int argc,char **argv) {
|
||||||
|
|
||||||
pw::matrix44d m;
|
pw::matrix4x4d m;
|
||||||
|
|
||||||
m.set_identity();
|
m.set_identity();
|
||||||
|
|
||||||
|
@ -22,18 +22,18 @@ int main(int argc,char **argv) {
|
||||||
std::cout << "determinant(): " << m.determinant() << std::endl;
|
std::cout << "determinant(): " << m.determinant() << std::endl;
|
||||||
|
|
||||||
|
|
||||||
pw::matrix44d mi = m.get_inverse();
|
pw::matrix4x4d mi = m.get_inverse();
|
||||||
|
|
||||||
std::cout << "mi.at(0,0) : " << mi.at(0,0) << std::endl;
|
std::cout << "mi.at(0,0) : " << mi.at(0,0) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
pw::matrix44d mscale = m * 4.2;
|
pw::matrix4x4d mscale = m * 4.2;
|
||||||
|
|
||||||
|
|
||||||
std::cout << "mscale = " << pw::serialize::matrix(mscale) << std::endl;
|
std::cout << "mscale = " << pw::serialize::matrix(mscale) << std::endl;
|
||||||
|
|
||||||
|
|
||||||
pw::matrix44d a;
|
pw::matrix4x4d a;
|
||||||
|
|
||||||
for (int r = 0; r < m.rows(); r++) {
|
for (int r = 0; r < m.rows(); r++) {
|
||||||
for (int c = 0; c < m.cols(); c++) {
|
for (int c = 0; c < m.cols(); c++) {
|
||||||
|
@ -42,7 +42,7 @@ int main(int argc,char **argv) {
|
||||||
}
|
}
|
||||||
std::cout << "a = " << pw::serialize::matrix(a) << std::endl;
|
std::cout << "a = " << pw::serialize::matrix(a) << std::endl;
|
||||||
|
|
||||||
pw::matrix44d r = a * mscale;
|
pw::matrix4x4d r = a * mscale;
|
||||||
|
|
||||||
std::cout << "a * mscale = " << pw::serialize::matrix(r) << std::endl;
|
std::cout << "a * mscale = " << pw::serialize::matrix(r) << std::endl;
|
||||||
|
|
||||||
|
|
|
@ -1,5 +1,5 @@
|
||||||
add_subdirectory(glfw-3.2.1)
|
add_subdirectory(glfw-3.2.1)
|
||||||
add_subdirectory(lua-5.3.4)
|
add_subdirectory(lua-5.3.5)
|
||||||
add_subdirectory(glad)
|
add_subdirectory(glad)
|
||||||
#add_subdirectory(arrrgh)
|
#add_subdirectory(arrrgh)
|
||||||
|
|
||||||
|
|
|
@ -49,8 +49,8 @@ public:
|
||||||
|
|
||||||
camera();
|
camera();
|
||||||
|
|
||||||
void set_projection(const matrix44 &projection);
|
void set_projection(const matrix4x4 &projection);
|
||||||
const matrix44& projection() const;
|
const matrix4x4& projection() const;
|
||||||
|
|
||||||
// void set_field_of_view(float)
|
// void set_field_of_view(float)
|
||||||
|
|
||||||
|
@ -64,7 +64,7 @@ protected:
|
||||||
|
|
||||||
|
|
||||||
private:
|
private:
|
||||||
matrix44 _projection;
|
matrix4x4 _projection;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -16,11 +16,11 @@ public:
|
||||||
|
|
||||||
transform();
|
transform();
|
||||||
|
|
||||||
inline const matrix44& local() const { return _local; }
|
inline const matrix4x4& local() const { return _local; }
|
||||||
void set_local(const matrix44 &local);
|
void set_local(const matrix4x4 &local);
|
||||||
|
|
||||||
inline const matrix44& global() const { return _global; }
|
inline const matrix4x4& global() const { return _global; }
|
||||||
void set_global(const matrix44 &global);
|
void set_global(const matrix4x4 &global);
|
||||||
|
|
||||||
inline void translate(const real_t &x, const real_t &y, const real_t &z) {
|
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.at(0,3) += x;_local.at(1,3) += y;_local.at(2,3) += z;
|
||||||
|
@ -53,8 +53,8 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
matrix44 _local;
|
matrix4x4 _local;
|
||||||
matrix44 _global;
|
matrix4x4 _global;
|
||||||
|
|
||||||
private:
|
private:
|
||||||
|
|
||||||
|
|
|
@ -7,15 +7,15 @@ camera::camera()
|
||||||
, _near_plane(0.2f)
|
, _near_plane(0.2f)
|
||||||
, _far_plane(1000)
|
, _far_plane(1000)
|
||||||
{
|
{
|
||||||
set_projection(matrix44::perspective_projection(_fov,1,_near_plane,_far_plane));
|
set_projection(matrix4x4::perspective_projection(_fov,1,_near_plane,_far_plane));
|
||||||
}
|
}
|
||||||
|
|
||||||
void camera::set_projection(const matrix44 &projection)
|
void camera::set_projection(const matrix4x4 &projection)
|
||||||
{
|
{
|
||||||
this->_projection = projection;
|
this->_projection = projection;
|
||||||
}
|
}
|
||||||
|
|
||||||
const matrix44 &camera::projection() const
|
const matrix4x4 &camera::projection() const
|
||||||
{
|
{
|
||||||
return _projection;
|
return _projection;
|
||||||
}
|
}
|
||||||
|
|
|
@ -9,14 +9,14 @@ transform::transform()
|
||||||
_global.set_identity();
|
_global.set_identity();
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform::set_local(const matrix44 &local)
|
void transform::set_local(const matrix4x4 &local)
|
||||||
{
|
{
|
||||||
// TODO need to rebuild the transforms: both -> global down and global up
|
// TODO need to rebuild the transforms: both -> global down and global up
|
||||||
_local = local;
|
_local = local;
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void transform::set_global(const matrix44 &global)
|
void transform::set_global(const matrix4x4 &global)
|
||||||
{
|
{
|
||||||
//TODO need to rebuild **_local** from parent
|
//TODO need to rebuild **_local** from parent
|
||||||
_global = global;
|
_global = global;
|
||||||
|
|
|
@ -24,7 +24,7 @@ add_library(pwscripting
|
||||||
target_include_directories(
|
target_include_directories(
|
||||||
pwscripting
|
pwscripting
|
||||||
PRIVATE
|
PRIVATE
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.4/src
|
${CMAKE_SOURCE_DIR}/src/deps/lua-5.3.5/src
|
||||||
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
${CMAKE_SOURCE_DIR}/src/deps/sol2-2.20.6
|
||||||
PUBLIC
|
PUBLIC
|
||||||
include
|
include
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue