cleanup before reworking the scripting engine layout:
This commit is contained in:
parent
4ff557d446
commit
803af8c37a
6 changed files with 130 additions and 108 deletions
|
@ -36,14 +36,16 @@ struct quaternion_ : vector4_<T> {
|
||||||
|
|
||||||
typedef vector4_<T> base_type;
|
typedef vector4_<T> base_type;
|
||||||
|
|
||||||
|
using typename base_type::value_type;
|
||||||
using base_type::base_type;
|
using base_type::base_type;
|
||||||
using base_type::x;
|
using base_type::x;
|
||||||
using base_type::y;
|
using base_type::y;
|
||||||
using base_type::z;
|
using base_type::z;
|
||||||
using base_type::w;
|
using base_type::w;
|
||||||
using base_type::lerp;
|
using base_type::lerp;
|
||||||
using base_type::operator*;
|
// using base_type::operator*;
|
||||||
using base_type::operator/;
|
// using base_type::operator/;
|
||||||
|
|
||||||
|
|
||||||
quaternion_(const base_type& other) : base_type(other) {}
|
quaternion_(const base_type& other) : base_type(other) {}
|
||||||
|
|
||||||
|
@ -68,6 +70,10 @@ struct quaternion_ : vector4_<T> {
|
||||||
return conjugate() / this->norm();
|
return conjugate() / this->norm();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
inline static quaternion_ identity() {
|
||||||
|
return quaternion_({0,0,0,1});
|
||||||
|
}
|
||||||
|
|
||||||
const matrix4x4_<T> to_matrix() const {
|
const matrix4x4_<T> to_matrix() const {
|
||||||
|
|
||||||
matrix4x4_<T> m; m.set_identity();
|
matrix4x4_<T> m; m.set_identity();
|
||||||
|
@ -110,10 +116,49 @@ struct quaternion_ : vector4_<T> {
|
||||||
wtemp);
|
wtemp);
|
||||||
}
|
}
|
||||||
|
|
||||||
static const quaternion_<T> normalized_lerp(const quaternion_<T> &a,const quaternion_<T> &b,const T &t) {
|
static const quaternion_ normalized_lerp(const quaternion_ &a,const quaternion_ &b,const T &t) {
|
||||||
return quaternion_<T>(lerp(a,b,t).normalized());
|
return quaternion_(lerp(a,b,t).normalized());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
const quaternion_ slerp(const quaternion_& qa,const quaternion_& qb,const T& t)
|
||||||
|
{
|
||||||
|
using std::abs;
|
||||||
|
using std::sqrt;
|
||||||
|
using std::acos;
|
||||||
|
|
||||||
|
// quaternion to return
|
||||||
|
quaternion_ qm;
|
||||||
|
// Calculate angle between them.
|
||||||
|
T cosHalfTheta = qa.w() * qb.w() + qa.x() * qb.x() + qa.y() * qb.y() + qa.z() * qb.z();
|
||||||
|
// if qa=qb or qa=-qb then theta = 0 and we can return qa
|
||||||
|
if (abs(cosHalfTheta) >= T(1)) {
|
||||||
|
return qa;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Calculate temporary values.
|
||||||
|
const T halfTheta = acos(cosHalfTheta);
|
||||||
|
const T sinHalfTheta = sqrt(1.0 - cosHalfTheta * cosHalfTheta);
|
||||||
|
// if theta = 180 degrees then result is not fully defined
|
||||||
|
// we could rotate around any axis normal to qa or qb
|
||||||
|
if (abs(sinHalfTheta) < 0.001){ // fabs is floating point absolute
|
||||||
|
qm.w() = (qa.w() * T(0.5) + qb.w() * T(0.5));
|
||||||
|
qm.x() = (qa.x() * T(0.5) + qb.x() * T(0.5));
|
||||||
|
qm.y() = (qa.y() * T(0.5) + qb.y() * T(0.5));
|
||||||
|
qm.z() = (qa.z() * T(0.5) + qb.z() * T(0.5));
|
||||||
|
return qm;
|
||||||
|
}
|
||||||
|
const T ratioA = sin((value_type(1) - t) * halfTheta) / sinHalfTheta;
|
||||||
|
const T ratioB = sin(t * halfTheta) / sinHalfTheta;
|
||||||
|
//calculate Quaternion.
|
||||||
|
qm.w() = (qa.w() * ratioA + qb.w() * ratioB);
|
||||||
|
qm.x() = (qa.x() * ratioA + qb.x() * ratioB);
|
||||||
|
qm.y() = (qa.y() * ratioA + qb.y() * ratioB);
|
||||||
|
qm.z() = (qa.z() * ratioA + qb.z() * ratioB);
|
||||||
|
|
||||||
|
return qm;
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
static const quaternion_<T> from_axisangle(const axisangle_<T> &aa) {
|
static const quaternion_<T> from_axisangle(const axisangle_<T> &aa) {
|
||||||
|
|
||||||
using std::sin;
|
using std::sin;
|
||||||
|
|
|
@ -15,10 +15,10 @@ int main(int argc,char **argv) {
|
||||||
std::cout << "qf.conjugate() = " << pw::serialize::matrix(qf.conjugate()) << std::endl;
|
std::cout << "qf.conjugate() = " << pw::serialize::matrix(qf.conjugate()) << std::endl;
|
||||||
|
|
||||||
pw::quaternionf qc = qf.conjugate();
|
pw::quaternionf qc = qf.conjugate();
|
||||||
std::cout << "qf.conjugate() (qc) = " << pw::serialize::matrix(qc) << std::endl;
|
std::cout << "qf.conjugate() (qc) = " << pw::serialize::matrix(qc.to_matrix()) << std::endl;
|
||||||
|
|
||||||
pw::quaternionf qi = qf.inverse();
|
pw::quaternionf qi = qf.inverse();
|
||||||
std::cout << "qf.inverse() (qi) = " << pw::serialize::matrix(qi) << std::endl;
|
std::cout << "qf.inverse() (qi) = " << pw::serialize::matrix(qi.to_matrix()) << std::endl;
|
||||||
|
|
||||||
pw::quaternionf qmid = pw::quaternionf::normalized_lerp(qi,qf,0.5f);
|
pw::quaternionf qmid = pw::quaternionf::normalized_lerp(qi,qf,0.5f);
|
||||||
// std::cout << "qmid.dot() (half between qf and qi) = " << pw::rad_to_deg(quaternionf::angle_between()) << std::endl;
|
// std::cout << "qmid.dot() (half between qf and qi) = " << pw::rad_to_deg(quaternionf::angle_between()) << std::endl;
|
||||||
|
|
|
@ -1,11 +1,16 @@
|
||||||
|
|
||||||
set(scripts
|
set(scripts_demo
|
||||||
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua
|
${CMAKE_SOURCE_DIR}/src/scripts/demos/simple_000.lua
|
||||||
)
|
)
|
||||||
|
|
||||||
|
set(scripts_test
|
||||||
|
${CMAKE_SOURCE_DIR}/src/scripts/tests/test_core.lua
|
||||||
|
)
|
||||||
|
|
||||||
add_executable(pixwerx WIN32 MACOSX_BUNDLE
|
add_executable(pixwerx WIN32 MACOSX_BUNDLE
|
||||||
pixwerx.cpp
|
pixwerx.cpp
|
||||||
${scripts}
|
${scripts_demo}
|
||||||
|
${scripts_test}
|
||||||
)
|
)
|
||||||
|
|
||||||
target_include_directories(pixwerx
|
target_include_directories(pixwerx
|
||||||
|
|
|
@ -7,7 +7,7 @@
|
||||||
#include "pw/core/size.hpp"
|
#include "pw/core/size.hpp"
|
||||||
#include "pw/core/point.hpp"
|
#include "pw/core/point.hpp"
|
||||||
#include "pw/core/timer.hpp"
|
#include "pw/core/timer.hpp"
|
||||||
|
#include "pw/core/mesh.hpp"
|
||||||
|
|
||||||
namespace pw {
|
namespace pw {
|
||||||
|
|
||||||
|
@ -19,42 +19,37 @@ void script_core::load(sol::table &ns)
|
||||||
ns.set("pi",pw::pi<Scalar>());
|
ns.set("pi",pw::pi<Scalar>());
|
||||||
|
|
||||||
|
|
||||||
ns.new_usertype<vector3>(
|
ns.new_usertype<vector3>
|
||||||
|
(
|
||||||
"vector3",
|
"vector3",
|
||||||
sol::constructors<vector3(),vector3(vector3::value_type,vector3::value_type,vector3::value_type)>(),
|
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})
|
"x", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::x), [](vector3& v,vector3::value_type val){ v.x() = val;}),
|
||||||
|
"y", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::y), [](vector3& v,vector3::value_type val){ v.y() = val;}),
|
||||||
|
"z", sol::property(sol::resolve<const vector3::value_type&() const>(&vector3::z), [](vector3& v,vector3::value_type val){ v.z() = val;}),
|
||||||
|
"cross",&vector3::cross,
|
||||||
|
"lerp",&vector3::lerp
|
||||||
);
|
);
|
||||||
|
|
||||||
|
|
||||||
// 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",
|
ns.new_usertype<quaternion>
|
||||||
// sol::constructors<quaternion(), quaternion(Scalar,Scalar,Scalar,Scalar)>(),
|
(
|
||||||
// "set",&quaternion::set,
|
"quaternion",
|
||||||
// "x", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::x), &quaternion::set_x),
|
sol::constructors<quaternion(), quaternion(quaternion::value_type,quaternion::value_type,quaternion::value_type,quaternion::value_type)>(),
|
||||||
// "y", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::y), &quaternion::set_y),
|
"x", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::x), [](quaternion& v,quaternion::value_type val){ v.x() = val;}),
|
||||||
// "z", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::z), &quaternion::set_z),
|
"y", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::y), [](quaternion& v,quaternion::value_type val){ v.y() = val;}),
|
||||||
// "w", scripting::property(scripting::resolve<const Scalar&() const>(&quaternion::w), &quaternion::set_w),
|
"z", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::z), [](quaternion& v,quaternion::value_type val){ v.z() = val;}),
|
||||||
// "dot",&quaternion::dot,
|
"w", sol::property(sol::resolve<const quaternion::value_type&() const>(&quaternion::w), [](quaternion& v,quaternion::value_type val){ v.w() = val;}),
|
||||||
// "inverse",scripting::readonly_property(&quaternion::inverse),
|
"identity",sol::readonly_property(&quaternion::identity),
|
||||||
// "normalized",&quaternion::normalized,
|
"dot",&quaternion::dot,
|
||||||
// "lerp",&quaternion::lerp,
|
"inverse",scripting::readonly_property(&quaternion::inverse),
|
||||||
// "slerp",&quaternion::slerp
|
"normalized",&quaternion::normalized,
|
||||||
// // "v",&vector3d::values,
|
"lerp",&quaternion::lerp,
|
||||||
// // "clone",&vector3d::clone
|
"slerp",&quaternion::slerp
|
||||||
// );
|
);
|
||||||
|
|
||||||
ns.new_usertype<axisangle>("axisangle",
|
ns.new_usertype<axisangle>
|
||||||
|
("axisangle",
|
||||||
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
sol::constructors<axisangle(), axisangle(vector3,Scalar)>(),
|
||||||
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
|
"axis",scripting::property(&axisangle::axis,&axisangle::set_axis),
|
||||||
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
|
"angle",scripting::property(&axisangle::angle,&axisangle::set_angle)
|
||||||
|
@ -89,6 +84,17 @@ void script_core::load(sol::table &ns)
|
||||||
"reset",&timer::reset
|
"reset",&timer::reset
|
||||||
);
|
);
|
||||||
|
|
||||||
|
ns.new_usertype<mesh>
|
||||||
|
(
|
||||||
|
"mesh",
|
||||||
|
sol::constructors<mesh()>()
|
||||||
|
);
|
||||||
|
|
||||||
|
// ns.new_enum<mesh::topology_type>
|
||||||
|
// (
|
||||||
|
// "mesh",
|
||||||
|
// sol::constructors<mesh()>()
|
||||||
|
// );
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -3,68 +3,6 @@ pw.script:initialize()
|
||||||
|
|
||||||
print("hello pixwerx!")
|
print("hello pixwerx!")
|
||||||
|
|
||||||
local v1 = pw.vector3.new(3,2,1)
|
|
||||||
v1:set(0,1,2)
|
|
||||||
|
|
||||||
print("v1 ",v1.x,v1.y,v1.z)
|
|
||||||
|
|
||||||
|
|
||||||
---- objects need to be cloned
|
|
||||||
----local v2 = v:clone()
|
|
||||||
--local v2 = v
|
|
||||||
|
|
||||||
---- manipulate stuff
|
|
||||||
--v.x = 0.2
|
|
||||||
--v.y = pw.pi
|
|
||||||
|
|
||||||
|
|
||||||
--print("v : ", v:v())
|
|
||||||
--print("v2: ", v2:v())
|
|
||||||
|
|
||||||
local q = pw.quaternion.new()
|
|
||||||
print("q",q.x,q.y,q.z,q.w)
|
|
||||||
|
|
||||||
qi = q.inverse
|
|
||||||
print("q.inverse",qi.x,qi.y,qi.z,qi.w)
|
|
||||||
|
|
||||||
local q2 = pw.quaternion.new(0,0,0,1)
|
|
||||||
|
|
||||||
qm = pw.quaternion.lerp(q,qi,0.5)
|
|
||||||
print("q.m",qm.x,qm.y,qm.z,qm.w)
|
|
||||||
|
|
||||||
-- axis angle test
|
|
||||||
local aa = pw.axisangle.new(v1,0.707)
|
|
||||||
|
|
||||||
print("aa.axis",aa.axis.x,aa.axis.y,aa.axis.z)
|
|
||||||
print("aa.angle",aa.angle)
|
|
||||||
|
|
||||||
local n_1 = pw.node.create()
|
|
||||||
n_1.name = "root"
|
|
||||||
|
|
||||||
print("node 1: ", n_1.name)
|
|
||||||
|
|
||||||
--print(pw.node.create())
|
|
||||||
|
|
||||||
n_1:add_child(pw.node.create()).name = "one"
|
|
||||||
n_1:add_child(pw.node.create()).name = "two"
|
|
||||||
n_1:add_child(pw.node.create()).name = "three"
|
|
||||||
n_1:add_child(pw.node.create()).name = "four"
|
|
||||||
n_1:add_child(pw.node.create()).name = "five"
|
|
||||||
|
|
||||||
--n_1:add_child(n_2:shared())
|
|
||||||
|
|
||||||
print("node 1 - child count ",n_1.child_count)
|
|
||||||
|
|
||||||
-- stuff
|
|
||||||
for i = 1,n_1.child_count do
|
|
||||||
print(i,n_1.children[i],n_1.children[i].name)
|
|
||||||
end
|
|
||||||
|
|
||||||
--print(n_1:shared())
|
|
||||||
--print(pw.my_func())
|
|
||||||
|
|
||||||
--n_1:add_child()
|
|
||||||
|
|
||||||
local w = pw.window.new()
|
local w = pw.window.new()
|
||||||
w.visible = false
|
w.visible = false
|
||||||
|
|
||||||
|
|
28
src/scripts/tests/test_core.lua
Normal file
28
src/scripts/tests/test_core.lua
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
-- loading our libraries
|
||||||
|
pw.script:initialize()
|
||||||
|
|
||||||
|
print("hello pixwerx!")
|
||||||
|
|
||||||
|
local v1 = pw.vector3.new(3,2,1)
|
||||||
|
|
||||||
|
print("v1 ",v1.x,v1.y,v1.z)
|
||||||
|
|
||||||
|
local q = pw.quaternion.new()
|
||||||
|
q = pw.quaternion.identity
|
||||||
|
print("q",q.x,q.y,q.z,q.w)
|
||||||
|
|
||||||
|
qi = q.inverse
|
||||||
|
print("q.inverse",qi.x,qi.y,qi.z,qi.w)
|
||||||
|
|
||||||
|
local q2 = pw.quaternion.new(0,0,0,1)
|
||||||
|
|
||||||
|
-- bug!
|
||||||
|
--qm = pw.quaternion.lerp(q,qi,0.5)
|
||||||
|
--print("q.m",qm.x,qm.y,qm.z,qm.w)
|
||||||
|
|
||||||
|
-- axis angle test
|
||||||
|
local aa = pw.axisangle.new(v1,0.707)
|
||||||
|
|
||||||
|
print("aa.axis",aa.axis.x,aa.axis.y,aa.axis.z)
|
||||||
|
print("aa.angle",aa.angle)
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue