glm::closestPointOnLine no longer available?


I need to find the distance from a point to a line.

I get a compiler error when I try to use glm::closestPointOnLine() which is a documented function.

Then I found here that, apparently, this was removed from OF to avoid some compiling warnings.

Is there still a way to use this function? If so, how? If not, what other alternatives do you suggest?

Also, I guess this function should be removed from the OF documentation.

Thank you in advance.


Hi @nununo,

Yes you can still use it I think. The oF Documentation page says to “see also: gtx_closest_point”. After a quick google search, I found the glm documentation page here: GLM_GTX_closest_point: Find closest point.

So you should be able to do the following if you include the header for the function:

// in ofApp.h
#include <glm/gtx/closest_point.hpp> 

// in ofApp.cpp
    glm::vec3 point = glm::vec3(0.0, 500.0, 0.0);
    glm::vec3 a = glm::vec3(0.0, 0.0, 0.0);
    glm::vec3  b = glm::vec3(500.0, 500.0, 0.0);

    glm::vec3 result = glm::closestPointOnLine(point, a, b);

I wonder if there are some other functions in the glm class that are like this one, where they can be used as stated in the oF Documentation but only after including their specific header file(s).

Edit: Yes, there are a bunch of functions like glm::closestPointOnLine() in the GTX Extensions (Experimental) category: GTX Extensions (Experimental)

1 Like

Hey @Theo, in reference to this github topic on glm compiler warnings: core: fix GLM warnings by oxillo · Pull Request #6673 · openframeworks/openFrameworks · GitHub

Is there a way to enable all of the “experimental” glm functions by defining and/or including something in ofApp.h? Or is including each relevant function-specific header(s) the most simple way?

1 Like

Thank you. That’s exactly what I needed!
It was actually simple, but I don’t know enough C++ to find it by myself.

Yeah I know I’m the same way with my C++ skills. The links in your original post helped a whole bunch.

1 Like

I always do my best to explore by myself before asking questions :wink: