i am pretty new to the GLM library for C++ so I am facing some problems with it.
I have a plane made of a position and two spanning vectors, and a line containing it's position and direction - all values are glm::vec3
.
struct Plane {
glm::vec3 position;
glm::vec3 spanVec1;
glm::vec3 spanVec2;
}
struct Line {
glm::vec3 start;
glm::vec3 direction;
}
Now I need the intersection point of both. I am aware that I could find the point with a linear equation, but I would like to ensure that no INBUILD solution from glm is available, so that I don't have to write my own extension (mainly due to performance reasons).
So is there a convenient way to do this within the library? Or at least does the library contain some kind of linear equation solving?
PS: The glm::gtx::intersect
functions are not what I am looking for, since I need the intersection point, while those only return wether or not they intersect (boolean
).
glm::gtx::intersect
doesn't have a line-plane intersection function, but it does have intersectRayPlane
.
You could build a ray-plane intersection by calling that routine twice (once with Line.direction
and once with -line.direction
). Not the most efficient option, but perhaps suitable for many applications.
Note that intersectRayPlane
doesn't return the intersection position directly, but the last (output) parameter is the distance along the ray to the intersection position. So you would get the intersection position with orig + intersectionDistance*dir