mirror of
https://github.com/g-truc/glm.git
synced 2025-04-05 21:45:02 +00:00
Fixed angle implementation
This commit is contained in:
parent
e4a52432ff
commit
c9b7b712fb
3 changed files with 30 additions and 11 deletions
|
@ -149,7 +149,7 @@ namespace quaternion
|
|||
detail::tquat<T> const & x
|
||||
)
|
||||
{
|
||||
return acos(x.w) * T(2);
|
||||
return glm::degrees(acos(x.w) * T(2));
|
||||
}
|
||||
|
||||
template <typename T>
|
||||
|
|
|
@ -23,11 +23,12 @@ int test_quat_slerp()
|
|||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat A(0.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat B(90.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat A(glm::vec3(0, 0, 1));
|
||||
glm::quat B(glm::vec3(0, 1, 0));
|
||||
glm::quat C = glm::mix(A, B, 0.5f);
|
||||
|
||||
Error += C == glm::quat(45.f, glm::vec3(0, 0, 1)) ? 0 : 1;
|
||||
glm::quat D(glm::normalize(glm::vec3(0, 1, 1)));
|
||||
|
||||
Error += C == D ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
|
|
@ -11,31 +11,48 @@
|
|||
#include <glm/gtx/quaternion.hpp>
|
||||
#include <glm/gtx/epsilon.hpp>
|
||||
|
||||
int test_quat_angleAxis()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
glm::quat A = glm::angleAxis(0.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat B = glm::angleAxis(90.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat C = glm::mix(A, B, 0.5f);
|
||||
glm::quat D = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
|
||||
|
||||
Error += glm::equalEpsilon(C.x, D.x, 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(C.y, D.y, 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(C.z, D.z, 0.01f) ? 0 : 1;
|
||||
Error += glm::equalEpsilon(C.w, D.w, 0.01f) ? 0 : 1;
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
||||
int test_quat_angle()
|
||||
{
|
||||
int Error = 0;
|
||||
|
||||
{
|
||||
glm::quat Q(45.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat Q = glm::angleAxis(45.0f, glm::vec3(0, 0, 1));
|
||||
glm::quat N = glm::normalize(Q);
|
||||
float L = glm::length(N);
|
||||
Error += L == 1.0f ? 0 : 1;
|
||||
Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1;
|
||||
float A = glm::angle(N);
|
||||
Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::quat Q(45.0f, glm::vec3(0, 0, 2));
|
||||
glm::quat Q = glm::angleAxis(45.0f, glm::normalize(glm::vec3(0, 1, 1)));
|
||||
glm::quat N = glm::normalize(Q);
|
||||
float L = glm::length(N);
|
||||
Error += L == 1.0f ? 0 : 1;
|
||||
Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1;
|
||||
float A = glm::angle(N);
|
||||
Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1;
|
||||
}
|
||||
{
|
||||
glm::quat Q(45.0f, glm::vec3(1, 2, 3));
|
||||
glm::quat Q = glm::angleAxis(45.0f, glm::normalize(glm::vec3(1, 2, 3)));
|
||||
glm::quat N = glm::normalize(Q);
|
||||
float L = glm::length(N);
|
||||
Error += L == 1.0f ? 0 : 1;
|
||||
Error += glm::equalEpsilon(L, 1.0f, 0.01f) ? 0 : 1;
|
||||
float A = glm::angle(N);
|
||||
Error += glm::equalEpsilon(A, 45.0f, 0.01f) ? 0 : 1;
|
||||
}
|
||||
|
@ -48,6 +65,7 @@ int main()
|
|||
int Error = 0;
|
||||
|
||||
Error += test_quat_angle();
|
||||
Error += test_quat_angleAxis();
|
||||
|
||||
return Error;
|
||||
}
|
||||
|
|
Loading…
Add table
Reference in a new issue