21 #include "hx3d/math/vector_utils.hpp" 23 #include <glm/gtx/rotate_vector.hpp> 28 glm::vec3
rotate(glm::vec3 vector,
float angle, glm::vec3 axis) {
29 glm::vec3 ret(vector);
32 ret = glm::rotateX(ret, angle);
34 ret = glm::rotateY(ret, angle);
36 ret = glm::rotateZ(ret, angle);
41 glm::vec2
cross(
float v, glm::vec2 vec) {
42 return glm::vec2(-v * vec.y, v * vec.x);
44 glm::vec2
cross(glm::vec2 vec,
float v) {
45 return glm::vec2(v * vec.y, -v * vec.x);
47 float cross(glm::vec2 vec1, glm::vec2 vec2) {
48 return vec1.x * vec2.y - vec1.y * vec2.x;
52 float length = glm::length(vec);
54 float inv = 1.f / length;
55 return {vec.x * inv, vec.y * inv};
62 return vec.x * vec.x + vec.y * vec.y;
67 float a = glm::dot(vec1, vec2);
70 angle = -std::acos(a);
float squareLength(glm::vec2 vec)
Compute the square length of a 2D vector.
glm::vec3 rotate(glm::vec3 vector, float angle, glm::vec3 axis)
Rotate a vector of an angle on one/multiple axis.
const float kEpsilon
Float epsilon.
float angleBetweenVecs(const glm::vec2 vec1, const glm::vec2 vec2)
Compute the angle between two 2D vectors.
glm::vec2 normalize(glm::vec2 vec)
Normalize a 2D vector.
glm::vec2 cross(glm::vec2 vec, float v)
Calculate the cross product vector between a 2D vector and a scalar.