Add explicit template instantiation for most common matrix, vector, and quaternion types
This commit is contained in:
parent
106c7009b5
commit
f40559f543
@ -26,6 +26,8 @@
|
||||
//Provide aliases for common matrix, vector, and quaternion types
|
||||
|
||||
namespace math{
|
||||
|
||||
//Must forward declare type traits for use in concepts because you can't forward declare concepts
|
||||
template<class... Ms>
|
||||
struct is_vector;
|
||||
template<class... Qs>
|
||||
@ -33,6 +35,7 @@ namespace math{
|
||||
template<class... Ms>
|
||||
struct is_matrix;
|
||||
|
||||
//Create concepts that depend on the type traits
|
||||
template<class T>
|
||||
concept Quaternion = is_quaternion<T>::value;
|
||||
template<class T>
|
||||
@ -177,16 +180,6 @@ namespace math{
|
||||
static constexpr bool value = (detail::is_matrix_helper<Ms>::value && ...);
|
||||
};
|
||||
|
||||
template<class T, class U>
|
||||
concept Compatible_Scalar = requires(T&& t, U&& u){
|
||||
requires !is_matrix<T>::value;
|
||||
requires std::is_convertible_v<decltype(u * t),std::decay_t<T>>;
|
||||
requires std::is_convertible_v<decltype(u / t),std::decay_t<T>>;
|
||||
requires std::is_convertible_v<decltype(u + t),std::decay_t<T>>;
|
||||
requires std::is_convertible_v<decltype(u - t),std::decay_t<T>>;
|
||||
};
|
||||
|
||||
|
||||
}
|
||||
|
||||
#endif
|
||||
|
||||
@ -232,6 +232,10 @@ namespace math{
|
||||
template<Scalar T, Scalar U, size_t C, size_t R>
|
||||
constexpr decltype(auto) operator-=(matrix<T,R,C>& left, const matrix<U,R,C>& right);
|
||||
|
||||
extern template class matrix<float,2,2>;
|
||||
extern template class matrix<float,3,3>;
|
||||
extern template class matrix<float,4,4>;
|
||||
|
||||
}
|
||||
|
||||
#include "mat.tpp"
|
||||
|
||||
@ -141,6 +141,7 @@ namespace math{
|
||||
template<Scalar T, Scalar U>
|
||||
decltype(auto) operator/=(quaternion<T>& left, U&& right);
|
||||
|
||||
extern template class quaternion<float>;
|
||||
}
|
||||
|
||||
#include "quat.tpp"
|
||||
|
||||
@ -99,7 +99,7 @@ namespace math{
|
||||
quaternion(angles.x(), angles.y(), angles.z()){}
|
||||
template<Scalar T>
|
||||
quaternion<T>::quaternion(value_type angle, const vec3<value_type>& axis):
|
||||
quaternion(angle, axis.get_x(), axis.get_y(), axis.get_z()){}
|
||||
quaternion(angle, axis.x(), axis.y(), axis.z()){}
|
||||
template<Scalar T>
|
||||
quaternion<T>::quaternion(value_type angle, value_type x, value_type y, value_type z){
|
||||
angle /= value_type{2.0};
|
||||
@ -181,11 +181,11 @@ namespace math{
|
||||
auto quaternion<T>::get_axis(void)const -> vec3<value_type>{
|
||||
quaternion tmp(*this);
|
||||
if(m_data[0] > value_type{1.0})
|
||||
tmp.set_normalized();
|
||||
tmp = tmp.normalize();
|
||||
value_type s = std::sqrt(1 - tmp.m_data[0] * tmp.m_data[0]);
|
||||
if(s <= value_type{0.001})
|
||||
return vec3<T>(1, 0, 0);
|
||||
return vec3<T>(tmp.data[1] / s, tmp.data[2] / s, tmp.data[3] / s);
|
||||
return vec3<T>(tmp.m_data[1] / s, tmp.m_data[2] / s, tmp.m_data[3] / s);
|
||||
}
|
||||
template<Scalar T>
|
||||
void quaternion<T>::set_angle(value_type t){
|
||||
|
||||
@ -117,6 +117,10 @@ namespace math{
|
||||
template<Scalar T, Scalar U, size_t R>
|
||||
constexpr decltype(auto) operator-=(vector<T,R>& left, const vector<U,R>& right);
|
||||
|
||||
extern template class vector<float,2>;
|
||||
extern template class vector<float,3>;
|
||||
extern template class vector<float,4>;
|
||||
|
||||
}
|
||||
|
||||
#include "vec.tpp"
|
||||
|
||||
2
makefile
2
makefile
@ -19,7 +19,7 @@ ifeq ($(OS),Windows_NT)
|
||||
WINDOWS::=1
|
||||
endif
|
||||
|
||||
SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip src/util
|
||||
SOURCE_DIRS::=src src/audio src/audio/impl src/gfx src/gfx/ogl src/egn src/ttt src/wip src/util src/math
|
||||
SOURCES::=
|
||||
OBJDIR::=obj
|
||||
DEPDIR::=$(OBJDIR)/dep
|
||||
|
||||
28
src/math/mat.cpp
Normal file
28
src/math/mat.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
This file is a part of our_dick
|
||||
Copyright (C) 2022 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "math/mat.hpp"
|
||||
#include "math/fwd_declare.hpp"
|
||||
|
||||
namespace math{
|
||||
|
||||
template class matrix<float,2,2>;
|
||||
template class matrix<float,3,3>;
|
||||
template class matrix<float,4,4>;
|
||||
|
||||
}
|
||||
26
src/math/quat.cpp
Normal file
26
src/math/quat.cpp
Normal file
@ -0,0 +1,26 @@
|
||||
/**
|
||||
This file is a part of our_dick
|
||||
Copyright (C) 2022 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "math/quat.hpp"
|
||||
#include "math/fwd_declare.hpp"
|
||||
|
||||
namespace math{
|
||||
|
||||
template class quaternion<float>;
|
||||
|
||||
}
|
||||
28
src/math/vec.cpp
Normal file
28
src/math/vec.cpp
Normal file
@ -0,0 +1,28 @@
|
||||
/**
|
||||
This file is a part of our_dick
|
||||
Copyright (C) 2022 rexy712
|
||||
|
||||
This program is free software: you can redistribute it and/or modify
|
||||
it under the terms of the GNU Affero General Public License as published by
|
||||
the Free Software Foundation, either version 3 of the License, or
|
||||
(at your option) any later version.
|
||||
|
||||
This program is distributed in the hope that it will be useful,
|
||||
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
||||
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
||||
GNU Affero General Public License for more details.
|
||||
|
||||
You should have received a copy of the GNU Affero General Public License
|
||||
along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||
*/
|
||||
|
||||
#include "math/vec.hpp"
|
||||
#include "math/fwd_declare.hpp"
|
||||
|
||||
namespace math{
|
||||
|
||||
template class vector<float,2>;
|
||||
template class vector<float,3>;
|
||||
template class vector<float,4>;
|
||||
|
||||
}
|
||||
Loading…
x
Reference in New Issue
Block a user