Commit for 2018.05.12.7z
This commit is contained in:
parent
04bdadac44
commit
067cc8a4f5
@ -50,7 +50,7 @@ namespace uf {
|
||||
// Quaternion ops
|
||||
template<typename T> pod::Matrix4t<typename T::type_t> matrix( const T& quaternion );
|
||||
template<typename T> pod::Quaternion<T> axisAngle( const pod::Vector3t<T>& axis, T angle );
|
||||
template<typename T> T unitVectors( const pod::Vector3t<typename T::type_t>& u, const pod::Vector3t<typename T::type_t>& v );
|
||||
template<typename T> pod::Quaternion<T> unitVectors( const pod::Vector3t<T>& u, const pod::Vector3t<T>& v );
|
||||
template<typename T> pod::Quaternion<T> lookAt( const pod::Vector3t<T>& source, const pod::Vector3t<T>& destination );
|
||||
|
||||
template<typename T> T conjugate( const T& quaternion );
|
||||
|
||||
@ -180,13 +180,10 @@ template<typename T> pod::Quaternion<T> uf::quaternion::axisAngle( const pod::Ve
|
||||
uf::quaternion::normalize(q);
|
||||
return q;
|
||||
}
|
||||
template<typename T> T uf::quaternion::unitVectors( const pod::Vector3t<typename T::type_t>& u, const pod::Vector3t<typename T::type_t>& v ) {
|
||||
typename T::type_t dot = uf::vector::dot(u, v);
|
||||
if ( dot + 1.0 < 0.00001 ) {
|
||||
return uf::quaternion::axisAngle( uf::vector::normalize(u), 180 );
|
||||
}
|
||||
|
||||
typename T::type_t mag = sqrt( 2.0 + 2.0 * dot );
|
||||
template<typename T> pod::Quaternion<T> uf::quaternion::unitVectors( const pod::Vector3t<T>& u, const pod::Vector3t<T>& v ) {
|
||||
T dot = uf::vector::dot(u, v);
|
||||
if ( dot + 1.0 < 0.00001 ) return uf::quaternion::axisAngle( uf::vector::normalize(u), 3.1415926 );
|
||||
T mag = sqrt( 2.0 + 2.0 * dot );
|
||||
pod::Vector3t<T> w = uf::vector::multiply(uf::vector::cross(u, v), (1.0 / mag));
|
||||
return {
|
||||
.x = w.x,
|
||||
@ -196,14 +193,18 @@ template<typename T> T uf::quaternion::unitVectors( const pod::Vector3t<typename
|
||||
};
|
||||
}
|
||||
template<typename T> pod::Quaternion<T> uf::quaternion::lookAt( const pod::Vector3t<T>& source, const pod::Vector3t<T>& destination ) {
|
||||
pod::Vector3t<T> forward = uf::vector::subtract( destination, source );
|
||||
T dot = uf::vector::dot( {0, 0, 1}, forward );
|
||||
pod::Vector3 forward = uf::vector::normalize(destination - source);
|
||||
return uf::quaternion::unitVectors({0,0,1}, forward);
|
||||
/*
|
||||
pod::Vector3t<T> forward = uf::vector::normalize(uf::vector::subtract( destination, source ));
|
||||
T dot = uf::vector::dot( {0, 0, -1}, forward );
|
||||
T eps = 0.000001f;
|
||||
if ( dot + 1 < eps ) return uf::quaternion::axisAngle( {0, 1, 0}, 3.1415926 );
|
||||
if ( dot - 1 < eps ) return uf::quaternion::identity<T>();
|
||||
if ( fabs(dot + 1) < eps ) return uf::quaternion::axisAngle( {0, 1, 0}, 3.1415926 );
|
||||
if ( fabs(dot - 1) < eps ) return uf::quaternion::identity<T>();
|
||||
T angle = acos(dot);
|
||||
pod::Vector3t<T> axis = uf::vector::normalize(uf::vector::cross( {0, 0, 1}, forward ));
|
||||
return uf::quaternion::axisAngle(axis, angle);
|
||||
*/
|
||||
}
|
||||
|
||||
template<typename T> T uf::quaternion::conjugate( const T& quaternion ) {
|
||||
|
||||
@ -74,9 +74,9 @@ void ext::Gui::render() {
|
||||
pod::Vector4 offset = { metadata["gui"]["uv"][0].asDouble(), metadata["gui"]["uv"][1].asDouble(), metadata["gui"]["uv"][2].asDouble(), metadata["gui"]["uv"][3].asDouble() };
|
||||
pod::Matrix4 matrix = uf::transform::model(transform);
|
||||
if ( metadata["gui"]["world"].asBool() ) {
|
||||
pod::Matrix4 rotation = uf::quaternion::matrix( uf::vector::multiply( { 1, 1, 1, -1 }, player.getComponent<pod::Transform<>>().orientation) );
|
||||
pod::Transform<> flatten = uf::transform::flatten(camera.getTransform(), true);
|
||||
pod::Matrix4 rotation = uf::quaternion::matrix( uf::vector::multiply( { 1, 1, 1, -1 }, flatten.orientation) );
|
||||
matrix = matrix * rotation;
|
||||
// matrix = camera.getProjection() * camera.getView() * matrix;
|
||||
}
|
||||
|
||||
shader.bind(); { int i = 0; for ( auto& texture : buffer.getBuffers() ) {
|
||||
|
||||
Loading…
Reference in New Issue
Block a user