mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +02:00
Merge pull request #6373 from Atlante45/rotationBetween
Rotation between
This commit is contained in:
commit
39f44115be
3 changed files with 5 additions and 27 deletions
|
@ -64,15 +64,15 @@ glm::quat Quat::inverse(const glm::quat& q) {
|
|||
}
|
||||
|
||||
glm::vec3 Quat::getFront(const glm::quat& orientation) {
|
||||
return orientation * IDENTITY_FRONT;
|
||||
return orientation * Vectors::FRONT;
|
||||
}
|
||||
|
||||
glm::vec3 Quat::getRight(const glm::quat& orientation) {
|
||||
return orientation * IDENTITY_RIGHT;
|
||||
return orientation * Vectors::RIGHT;
|
||||
}
|
||||
|
||||
glm::vec3 Quat::getUp(const glm::quat& orientation) {
|
||||
return orientation * IDENTITY_UP;
|
||||
return orientation * Vectors::UP;
|
||||
}
|
||||
|
||||
glm::vec3 Quat::safeEulerAngles(const glm::quat& orientation) {
|
||||
|
|
|
@ -201,30 +201,7 @@ float angleBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
|||
|
||||
// Helper function return the rotation from the first vector onto the second
|
||||
glm::quat rotationBetween(const glm::vec3& v1, const glm::vec3& v2) {
|
||||
float angle = angleBetween(v1, v2);
|
||||
if (glm::isnan(angle) || angle < EPSILON) {
|
||||
return glm::quat();
|
||||
}
|
||||
glm::vec3 axis;
|
||||
if (angle > 179.99f * RADIANS_PER_DEGREE) { // 180 degree rotation; must use another axis
|
||||
axis = glm::cross(v1, glm::vec3(1.0f, 0.0f, 0.0f));
|
||||
float axisLength = glm::length(axis);
|
||||
if (axisLength < EPSILON) { // parallel to x; y will work
|
||||
axis = glm::normalize(glm::cross(v1, glm::vec3(0.0f, 1.0f, 0.0f)));
|
||||
} else {
|
||||
axis /= axisLength;
|
||||
}
|
||||
} else {
|
||||
axis = glm::normalize(glm::cross(v1, v2));
|
||||
// It is possible for axis to be nan even when angle is not less than EPSILON.
|
||||
// For example when angle is small but not tiny but v1 and v2 and have very short lengths.
|
||||
if (glm::isnan(glm::dot(axis, axis))) {
|
||||
// set angle and axis to values that will generate an identity rotation
|
||||
angle = 0.0f;
|
||||
axis = glm::vec3(1.0f, 0.0f, 0.0f);
|
||||
}
|
||||
}
|
||||
return glm::angleAxis(angle, axis);
|
||||
return glm::rotation(glm::normalize(v1), glm::normalize(v2));
|
||||
}
|
||||
|
||||
bool isPointBehindTrianglesPlane(glm::vec3 point, glm::vec3 p0, glm::vec3 p1, glm::vec3 p2) {
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
|
||||
#include <glm/glm.hpp>
|
||||
#include <glm/gtc/quaternion.hpp>
|
||||
#include <glm/gtx/quaternion.hpp>
|
||||
|
||||
// Bring the most commonly used GLM types into the default namespace
|
||||
using glm::ivec2;
|
||||
|
|
Loading…
Reference in a new issue