Skip to content

Commit

Permalink
Added cast operators for ofVec3 to imVec2. (one way only)
Browse files Browse the repository at this point in the history
Mayn OF 2D functions return 3D vars. This allows parsing them as 2D by wiping off the Z axis.
  • Loading branch information
Daandelange committed Apr 1, 2020
1 parent e314827 commit c4c94f4
Showing 1 changed file with 7 additions and 2 deletions.
9 changes: 7 additions & 2 deletions src/imconfig.h
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,7 @@

//---- Define constructor and implicit cast operators to convert back<>forth between your math types and ImVec2/ImVec4.
// This will be inlined as part of ImVec2 and ImVec4 class declarations.
// Note: ofVec3 can cast to ImVec2 by ignoring z axis too.
#include "ofVectorMath.h"
#include "ofColor.h"

Expand All @@ -69,11 +70,15 @@
ImVec2(const ofVec2f& f) { x = f.x; y = f.y; } \
operator ofVec2f() const { return ofVec2f(x, y); } \
ImVec2(const glm::vec2& f) { x = f.x; y = f.y; } \
operator glm::vec2() const { return glm::vec2(x, y); }
operator glm::vec2() const { return glm::vec2(x, y); } \
\
ImVec2(const ofVec3f& f) { x = f.x; y = f.y; } \
ImVec2(const glm::vec3& f) { x = f.x; y = f.y; }
#else
#define IM_VEC2_CLASS_EXTRA \
ImVec2(const ofVec2f& f) { x = f.x; y = f.y; } \
operator ofVec2f() const { return ofVec2f(x, y); }
operator ofVec2f() const { return ofVec2f(x, y); } \
ImVec2(const ofVec3f& f) { x = f.x; y = f.y; }
#endif

#if OF_VERSION_MINOR >= 10
Expand Down

0 comments on commit c4c94f4

Please sign in to comment.