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
|
@ -1,40 +1,41 @@
|
|||
|
||||
set(hdrs
|
||||
include/pw/core/log.hpp
|
||||
include/pw/core/axisangle.hpp
|
||||
include/pw/core/core.hpp
|
||||
include/pw/core/math.hpp
|
||||
include/pw/core/matrixbase.hpp
|
||||
include/pw/core/matrix.hpp
|
||||
include/pw/core/vector.hpp
|
||||
include/pw/core/quaternion.hpp
|
||||
include/pw/core/serialize.hpp
|
||||
include/pw/core/image.hpp
|
||||
include/pw/core/size.hpp
|
||||
include/pw/core/timer.hpp
|
||||
include/pw/core/globals.hpp
|
||||
)
|
||||
include/pw/core/log.hpp
|
||||
include/pw/core/axisangle.hpp
|
||||
include/pw/core/core.hpp
|
||||
include/pw/core/math.hpp
|
||||
include/pw/core/matrixbase.hpp
|
||||
include/pw/core/matrix.hpp
|
||||
include/pw/core/vector.hpp
|
||||
include/pw/core/quaternion.hpp
|
||||
include/pw/core/serialize.hpp
|
||||
include/pw/core/image.hpp
|
||||
include/pw/core/size.hpp
|
||||
include/pw/core/timer.hpp
|
||||
include/pw/core/globals.hpp
|
||||
)
|
||||
|
||||
set(srcs
|
||||
src/log.cpp
|
||||
src/core.cpp
|
||||
src/serialize.cpp
|
||||
src/timer.cpp
|
||||
${CMAKE_SOURCE_DIR}/README.md
|
||||
${CMAKE_SOURCE_DIR}/LICENSE
|
||||
)
|
||||
src/image.cpp
|
||||
src/log.cpp
|
||||
src/core.cpp
|
||||
src/serialize.cpp
|
||||
src/timer.cpp
|
||||
${CMAKE_SOURCE_DIR}/README.md
|
||||
${CMAKE_SOURCE_DIR}/LICENSE
|
||||
)
|
||||
|
||||
add_library(pwcore
|
||||
STATIC
|
||||
${hdrs}
|
||||
${srcs}
|
||||
)
|
||||
STATIC
|
||||
${hdrs}
|
||||
${srcs}
|
||||
)
|
||||
|
||||
target_include_directories(
|
||||
pwcore
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
pwcore
|
||||
PUBLIC
|
||||
include
|
||||
)
|
||||
|
||||
target_link_libraries(pwcore)
|
||||
|
||||
|
|
|
@ -6,18 +6,18 @@
|
|||
namespace pw {
|
||||
|
||||
template <typename T>
|
||||
class axisangle {
|
||||
class axisangle_ {
|
||||
protected:
|
||||
vector3_<T> _axis;
|
||||
T _angle;
|
||||
public:
|
||||
|
||||
axisangle()
|
||||
: _axis(vector3_<T>::up()),
|
||||
_angle(0)
|
||||
{}
|
||||
axisangle_()
|
||||
: _axis(vector3_<T>::up()),
|
||||
_angle(0)
|
||||
{}
|
||||
|
||||
axisangle(const vector3_<T> &axis,const T &angle)
|
||||
axisangle_(const vector3_<T> &axis,const T &angle)
|
||||
: _axis(axis)
|
||||
, _angle(angle)
|
||||
{
|
||||
|
@ -29,9 +29,43 @@ public:
|
|||
T angle() const { return _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 {
|
||||
|
||||
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
|
||||
|
||||
template <typename T>
|
||||
class matrix44_ : public matrix_<4,4,T>
|
||||
class matrix4x4_ : public matrix_<4,4,T>
|
||||
{
|
||||
public:
|
||||
|
||||
using matrix_<4,4,T>::matrix_;
|
||||
|
||||
|
||||
matrix44_(const matrix_<4,4,T>& i)
|
||||
matrix4x4_(const matrix_<4,4,T>& i)
|
||||
{
|
||||
*this = i;
|
||||
}
|
||||
|
||||
matrix44_& operator = (const matrix_<4,4,T>& rhs) {
|
||||
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);
|
||||
|
@ -600,10 +600,10 @@ matrix44<T>::LookAt(const matrix<3,1,T> &eye, const matrix<3,1,T> &target, const
|
|||
|
||||
// predefined matricies
|
||||
|
||||
typedef matrix44_<real_t> matrix44;
|
||||
typedef matrix4x4_<real_t> matrix4x4;
|
||||
|
||||
typedef matrix44_<double> matrix44d;
|
||||
typedef matrix44_<float> matrix44f;
|
||||
typedef matrix4x4_<double> matrix4x4d;
|
||||
typedef matrix4x4_<float> matrix4x4f;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -31,19 +31,21 @@
|
|||
namespace pw {
|
||||
|
||||
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_ height() { return dim[1]; }
|
||||
|
||||
};
|
||||
|
||||
typedef size<int> sizei;
|
||||
typedef size<float> sizef;
|
||||
typedef size_<real_t> size;
|
||||
|
||||
typedef size_<int> sizei;
|
||||
typedef size_<float> sizef;
|
||||
|
||||
}
|
||||
|
||||
|
|
|
@ -60,7 +60,6 @@ public:
|
|||
return acos( nothr.dot(nself) );
|
||||
}
|
||||
|
||||
|
||||
};
|
||||
|
||||
|
||||
|
@ -106,12 +105,9 @@ public:
|
|||
return vector_<4,T>(x(),y(),z(),w);
|
||||
}
|
||||
|
||||
#if _GCC_STUPID_
|
||||
inline std::tuple<T,T,T> values() const {
|
||||
return std::make_tuple(x(),y(),z());
|
||||
const vector_<2,T> unproject() const {
|
||||
return vector_<2,T>(x()/z(),y()/z());
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
inline static vector3_<T> forward() { 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;
|
||||
|
||||
matrix44f m;
|
||||
matrix4x4f m;
|
||||
|
||||
m.set_identity();
|
||||
|
||||
|
|
|
@ -0,0 +1,7 @@
|
|||
#include "pw/core/image.hpp"
|
||||
|
||||
namespace pw {
|
||||
|
||||
|
||||
|
||||
}
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
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);
|
||||
|
||||
|
|
|
@ -6,7 +6,7 @@
|
|||
|
||||
int main(int argc,char **argv) {
|
||||
|
||||
pw::matrix44d m;
|
||||
pw::matrix4x4d m;
|
||||
|
||||
m.set_identity();
|
||||
|
||||
|
@ -22,18 +22,18 @@ int main(int argc,char **argv) {
|
|||
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;
|
||||
|
||||
|
||||
pw::matrix44d mscale = m * 4.2;
|
||||
pw::matrix4x4d mscale = m * 4.2;
|
||||
|
||||
|
||||
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 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;
|
||||
|
||||
pw::matrix44d r = a * mscale;
|
||||
pw::matrix4x4d r = a * mscale;
|
||||
|
||||
std::cout << "a * mscale = " << pw::serialize::matrix(r) << std::endl;
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
add_subdirectory(glfw-3.2.1)
|
||||
add_subdirectory(lua-5.3.4)
|
||||
add_subdirectory(lua-5.3.5)
|
||||
add_subdirectory(glad)
|
||||
#add_subdirectory(arrrgh)
|
||||
|
||||
|
|
|
@ -49,8 +49,8 @@ public:
|
|||
|
||||
camera();
|
||||
|
||||
void set_projection(const matrix44 &projection);
|
||||
const matrix44& projection() const;
|
||||
void set_projection(const matrix4x4 &projection);
|
||||
const matrix4x4& projection() const;
|
||||
|
||||
// void set_field_of_view(float)
|
||||
|
||||
|
@ -64,7 +64,7 @@ protected:
|
|||
|
||||
|
||||
private:
|
||||
matrix44 _projection;
|
||||
matrix4x4 _projection;
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -16,11 +16,11 @@ public:
|
|||
|
||||
transform();
|
||||
|
||||
inline const matrix44& local() const { return _local; }
|
||||
void set_local(const matrix44 &local);
|
||||
inline const matrix4x4& local() const { return _local; }
|
||||
void set_local(const matrix4x4 &local);
|
||||
|
||||
inline const matrix44& global() const { return _global; }
|
||||
void set_global(const matrix44 &global);
|
||||
inline const matrix4x4& global() const { return _global; }
|
||||
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;
|
||||
|
@ -53,8 +53,8 @@ public:
|
|||
|
||||
protected:
|
||||
|
||||
matrix44 _local;
|
||||
matrix44 _global;
|
||||
matrix4x4 _local;
|
||||
matrix4x4 _global;
|
||||
|
||||
private:
|
||||
|
||||
|
|
|
@ -7,15 +7,15 @@ camera::camera()
|
|||
, _near_plane(0.2f)
|
||||
, _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;
|
||||
}
|
||||
|
||||
const matrix44 &camera::projection() const
|
||||
const matrix4x4 &camera::projection() const
|
||||
{
|
||||
return _projection;
|
||||
}
|
||||
|
|
|
@ -9,14 +9,14 @@ transform::transform()
|
|||
_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
|
||||
_local = local;
|
||||
|
||||
}
|
||||
|
||||
void transform::set_global(const matrix44 &global)
|
||||
void transform::set_global(const matrix4x4 &global)
|
||||
{
|
||||
//TODO need to rebuild **_local** from parent
|
||||
_global = global;
|
||||
|
|
|
@ -24,7 +24,7 @@ add_library(pwscripting
|
|||
target_include_directories(
|
||||
pwscripting
|
||||
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
|
||||
PUBLIC
|
||||
include
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue