I am trying to use GLM vector classes in STL containers. It's okay if I'm not trying to use <algorithm>. Most algorithms rely on an operator ==that is not implemented for GLM classes.
<algorithm>
==
Does anyone know an easy way around this? Without (re) implementing STL algorithms: (
GLM is a great math library that implements GLSL functions in C ++
I just found out that glm actually implements comparison operators in the extension ( here ). But how do I use them in stl?
This question has been replaced by the following: how to use the glm == operator in stl algorithms?
Many STL algorithms take a functor to compare objects (of course, you need to be especially careful when comparing two vectors containing floating point values for equality).
Example:
To sort a std::list<glm::vec3>(for you, regardless of whether there will be any practical sense in sorting vectors), you can use
std::list<glm::vec3>
std::sort(myVec3List.begin(), myVec3List.end(), MyVec3ComparisonFunc)
with
bool MyVec3ComparisonFunc(const glm::vec3 &vecA, const glm::vec3 &vecB) { return vecA[0]<vecB[0] && vecA[1]<vecB[1] && vecA[2]<vecB[2]; }
So, fortunately, there is no need to change GLM or even reinvent the wheel.
You should be able to implement the == operator as a standalone function:
// (Actually more Greg S code than mine.....) bool operator==(const glm::vec3 &vecA, const glm::vec3 &vecB) { const double epsilion = 0.0001; // choose something apprpriate. return fabs(vecA[0] -vecB[0]) < epsilion && fabs(vecA[1] -vecB[1]) < epsilion && fabs(vecA[2] -vecB[2]) < epsilion; }
S .
<
, , . operator< glm::vec3, , "" , , - , "" , . , . 3D-, .
operator<
glm::vec3
, , , . , , , "". , . x, , y z. , (, a.x == b.x, y. , z)
x
y
z
, "" , , , .
. : , .
, , - epsilon, , . epsilon, operator==, .
operator==
, operator== - epsilon, epsilons.
, . . , .
Source: https://habr.com/ru/post/1760044/More articles:Windows PowerShell Snap-In для IIS не работает на 32-разрядной версии? - powershellIs SharePoint compatible with Office 2010? - ms-officeJavascript / jQuery: calling a function in another frame - javascriptLooking at what happens when a C # / ASP.NET thread completes and how to get around problems - multithreadingMVC Binder Binding Problem - asp.netdjango - many for many fields as a drop-down list - djangoPython svg interaction with cairo, opengl and rsvg - pythonHow to add a manufacturer in magento at the product url? - url-rewritingJQuery autocomplete how to search for words instead of string - javascriptHow to add another video to MPMoviePlayer? - iphoneAll Articles