I need to build a 3d tube primitive from a set of point. For each point I’ve the position and the direction.
In order to set the normal correctly, i need the vector perpendicular to the direction. Using
Vec3f there was
getPerpendicular method https://github.com/openframeworks/openFrameworks/blob/master/libs/openFrameworks/math/ofVec3f.h#L1787
What is its equivalent in
glm ? I had a look at this documentation https://glm.g-truc.net/0.9.0/api/a00181.html#_details
but it looks not the same thing as it takes 2 vectors as parameters.
My bad, the syntax is the same as the other glm operation
Trying to get used to
glm When I do this in 2d I used to just call
ofVec2.getPerpendicular() with glm I am doing this.
glm::vec2 a = points[i];
glm::vec2 b = points[i-1];
glm::vec2 v = a - b;
glm::vec2 perp = glm::perp(glm::vec2(0, 1), v);
and it looks like this?
what am I doing wrong?
I don’t know, and the answer is indeed hard to find on the web. Weird. But I know you can do it like that:
glm::vec2 perp( -v.y, v.x );
most probably glm doesn’t include such a function cause it can have multiple solutions (2 in 2d). what @lilive proposes is usually how you calculate the perpendicular and it’s what ofVec2f does (but normalized). the second solution would be
glm::vec2 perp( v.y, -v.x );
Yes - I ended up just doing
(-y, x) What do you think of some type of glm utils class?