Added GetRotateQuat()

This commit is contained in:
hyzboy 2024-08-01 01:39:33 +08:00
parent 6a688a2991
commit 7589d62732
2 changed files with 19 additions and 1 deletions

View File

@ -216,6 +216,7 @@ namespace hgl
}
const Matrix4f GetRotateMatrix(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction);
/**
*

View File

@ -195,4 +195,21 @@ namespace hgl
return glm::rotate(Matrix4f(1.0f),angle,axis);
}
/**
*
*/
const Quatf GetRotateQuat(const Vector3f &world_position,const Vector3f &cur_direction,const Vector3f &new_direction)
{
Vector3f axis=glm::cross(cur_direction,new_direction);
if(glm::length2(axis)<0.0001)
return Quatf(1.0f,0.0f,0.0f,0.0f);
axis=glm::normalize(axis);
float angle=acos(glm::dot(cur_direction,new_direction));
return glm::angleAxis(angle,axis);
}
}//namespace hgl