diff --git a/libs/openFrameworks/3d/ofNode.h b/libs/openFrameworks/3d/ofNode.h index 3a512645c43..43147655760 100644 --- a/libs/openFrameworks/3d/ofNode.h +++ b/libs/openFrameworks/3d/ofNode.h @@ -542,7 +542,7 @@ class ofNode { std::array axis; - glm::mat4 localTransformMatrix; + glm::mat4 localTransformMatrix {}; bool legacyCustomDrawOverrided; std::set children; diff --git a/libs/openFrameworks/graphics/ofPolyline.h b/libs/openFrameworks/graphics/ofPolyline.h index 7fbb48fe3a1..c27a6a02756 100644 --- a/libs/openFrameworks/graphics/ofPolyline.h +++ b/libs/openFrameworks/graphics/ofPolyline.h @@ -5,6 +5,7 @@ #define GLM_FORCE_CTOR_INIT #include "glm/fwd.hpp" +#include "ofConstants.h" #include #include @@ -49,15 +50,13 @@ /// next. Storing this position means that you can easily create continuous /// drawings without difficulty. - - class ofRectangle; -template +template class ofPolyline_ { public: - using VertexType = T; - + using VertexType = T; + /// \name Constructors /// \{ @@ -65,22 +64,22 @@ class ofPolyline_ { ofPolyline_(); /// \brief Creates an ofPolyline from a vector of glm::vec2 or T objects. - ofPolyline_(const std::vector& verts); + ofPolyline_(const std::vector & verts); - static ofPolyline_ fromRectangle(const ofRectangle& rect); + static ofPolyline_ fromRectangle(const ofRectangle & rect); - /// \} - /// \name Add and Remove Vertices - /// \{ + /// \} + /// \name Add and Remove Vertices + /// \{ /// \brief Removes all the points from the ofPolyline. void clear(); /// \brief Adds a point using an T at the end of the ofPolyline. - void addVertex( const T& p ); + void addVertex(const T & p); - /// \brief Adds a point using floats at the end of the ofPolyline. - void addVertex( float x, float y, float z=0 ); + /// \brief Adds a point using floats at the end of the ofPolyline. + void addVertex(float x, float y, float z = 0); /// \brief Add multiple points at the end of the ofPolyline using a vector of /// T objects @@ -102,16 +101,15 @@ class ofPolyline_ { /// ofPolyline p; /// p.addVertices(verts); /// ~~~~ - void addVertices( const std::vector& verts ); + void addVertices(const std::vector & verts); /// \brief Adds multiple points at the end of the ofPolyline using a pointer to /// an array of T objects. - void addVertices(const T* verts, int numverts); + void addVertices(const T * verts, int numverts); - void insertVertex(const T &p, int index); + void insertVertex(const T & p, int index); void insertVertex(float x, float y, float z, int index); - /// \brief Remove a vertex at a given index. /// /// This function print an error and ignore the input if the index is @@ -144,8 +142,8 @@ class ofPolyline_ { /// i++; /// } /// ~~~~ - const T& operator[] (int index) const; - T& operator[] (int index); + const T & operator[](int index) const; + T & operator[](int index); /// \brief Gets a vector of vertices that the line contains std::vector & getVertices(); @@ -166,12 +164,12 @@ class ofPolyline_ { /// \brief Add a straight line from the last point added, or from 0,0 if no point /// is set, to the point indicated by the T passesd in. - void lineTo(const T & to ){ addVertex(to); } + void lineTo(const T & to) { addVertex(to); } /// \brief Add a straight line from the last point added, or from 0,0 if no point /// is set, to the point indicated by the floats x,y,z passesd in. - void lineTo(float x, float y, float z=0){ - addVertex(x,y,z); + void lineTo(float x, float y, float z = 0) { + addVertex(x, y, z); } /// \brief Adds an arc around the T `center` with the width of `radiusX` @@ -218,7 +216,7 @@ class ofPolyline_ { /// /// ![Arc Example](graphics/ofpolyline_arc.jpg) void arc(const T & center, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { - arc(center, radiusX, radiusY, angleBegin, angleEnd, true, circleResolution); + arc(center, radiusX, radiusY, angleBegin, angleEnd, true, circleResolution); } /// \brief Adds an arc around the coordinates (`x`,`y`) with the width of @@ -229,7 +227,7 @@ class ofPolyline_ { /// /// Optionally, you can specify `circleResolution`, which is the number /// of line segments a circle would be drawn with. - void arc(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20){ + void arc(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { arc(T(x, y, 0.f), radiusX, radiusY, angleBegin, angleEnd, true, circleResolution); } @@ -241,21 +239,19 @@ class ofPolyline_ { /// /// Optionally, you can specify `circleResolution`, which is the number of /// line segments a circle would be drawn with. - void arc(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20){ + void arc(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { arc(T(x, y, z), radiusX, radiusY, angleBegin, angleEnd, true, circleResolution); } void arcNegative(const T & center, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { arc(center, radiusX, radiusY, angleBegin, angleEnd, false, circleResolution); } - void arcNegative(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20){ - arc(T(x,y,0.f), radiusX, radiusY, angleBegin, angleEnd, false, circleResolution); + void arcNegative(float x, float y, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { + arc(T(x, y, 0.f), radiusX, radiusY, angleBegin, angleEnd, false, circleResolution); } - void arcNegative(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20){ + void arcNegative(float x, float y, float z, float radiusX, float radiusY, float angleBegin, float angleEnd, int circleResolution = 20) { arc(T(x, y, z), radiusX, radiusY, angleBegin, angleEnd, false, circleResolution); } - - /// \brief Adds a curve to an T object passed in /// /// ~~~~{.cpp} @@ -269,12 +265,12 @@ class ofPolyline_ { /// /// \note You need at least 4 points to be able to use curveTo() /// \sa [Catmull-Rom splines wiki](http://en.wikipedia.org/wiki/Centripetal_Catmull%E2%80%93Rom_spline) - void curveTo( const T & to, int curveResolution = 20 ); + void curveTo(const T & to, int curveResolution = 20); /// \brief Adds a curve to the x,y,z points passed in with the optional /// resolution. - void curveTo(float x, float y, float z = 0, int curveResolution = 20 ){ - curveTo({x,y,z},curveResolution); + void curveTo(float x, float y, float z = 0, int curveResolution = 20) { + curveTo({ x, y, z }, curveResolution); } /// \brief Adds a cubic bezier line from the current drawing point with the 2 @@ -287,20 +283,20 @@ class ofPolyline_ { /// ~~~~ /// ![polyline bezier](bezier.jpg) /// The control points are shown in red. - void bezierTo( const T & cp1, const T & cp2, const T & to, int curveResolution = 20); + void bezierTo(const T & cp1, const T & cp2, const T & to, int curveResolution = 20); /// \brief Adds a cubic bezier line from the current drawing point with the 2 /// control points indicated by the coordinates cx1, cy1 and cx2, cy2, /// that ends at the coordinates x, y. - void bezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution = 20){ - bezierTo({cx1,cy1,0.f}, {cx2,cy2,0.f}, {x,y,0.f}, curveResolution); + void bezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution = 20) { + bezierTo({ cx1, cy1, 0.f }, { cx2, cy2, 0.f }, { x, y, 0.f }, curveResolution); } /// \brief Adds a cubic bezier line in 3D space from the current drawing point /// with the 2 control points indicated by the coordinates cx1, cy1, cz1 /// and cx2, cy2, cz2, that ends at the coordinates x, y, z. - void bezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z, int curveResolution = 20){ - bezierTo({cx1,cy1,cz1}, {cx2,cy2,cz2}, {x,y,z}, curveResolution); + void bezierTo(float cx1, float cy1, float cz1, float cx2, float cy2, float cz2, float x, float y, float z, int curveResolution = 20) { + bezierTo({ cx1, cy1, cz1 }, { cx2, cy2, cz2 }, { x, y, z }, curveResolution); } /// \brief Adds a quadratic bezier line in 3D space from the current drawing @@ -314,15 +310,15 @@ class ofPolyline_ { /// \brief Adds a quadratic bezier line in 2D space from the current drawing /// point with the beginning indicated by the point p1, the control point /// at p2, and that ends at the point p3. - void quadBezierTo( const T & p1, const T & p2, const T & p3, int curveResolution = 20 ){ - quadBezierTo(p1.x,p1.y,p1.z,p2.x,p2.y,p2.z,p3.x,p3.y,p3.z,curveResolution); + void quadBezierTo(const T & p1, const T & p2, const T & p3, int curveResolution = 20) { + quadBezierTo(p1.x, p1.y, p1.z, p2.x, p2.y, p2.z, p3.x, p3.y, p3.z, curveResolution); } /// \brief Adds a quadratic bezier line in 2D space from the current drawing /// point with the beginning indicated by the coordinates cx1, cy1, the /// control point at cx2, cy2, and that ends at the coordinates x, y. - void quadBezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution = 20){ - quadBezierTo(cx1,cy1,0,cx2,cy2,0,x,y,0,curveResolution); + void quadBezierTo(float cx1, float cy1, float cx2, float cy2, float x, float y, int curveResolution = 20) { + quadBezierTo(cx1, cy1, 0, cx2, cy2, 0, x, y, 0, curveResolution); } /// \} @@ -360,7 +356,7 @@ class ofPolyline_ { /// \param tolerance determines how dis-similar points need to be to stay in the line. /// Higher tolerance means more points removed, lower tolerance means less /// points removed. - void simplify(float tolerance=0.3f); + void simplify(float tolerance = 0.3f); /// \} /// \name Transform polyline @@ -395,10 +391,9 @@ class ofPolyline_ { /// \brief Closes the ofPolyline, meaning that all the vertices will be linked /// and can be "walked". - void setClosed( bool tf ); + void setClosed(bool tf); bool isClosed() const; - /// \brief Returns whether the vertices within the line have changed. bool hasChanged(); void flagHasChanged(); @@ -407,13 +402,12 @@ class ofPolyline_ { /// \name Geometric Functions /// \{ - /// \brief Tests whether the x,y coordinates are within a closed ofPolyline. - static bool inside(float x, float y, const ofPolyline_ & polyline); + [[deprecated("call inside() on the polygon")]] static bool inside(float x, float y, const ofPolyline_ & polyline); + [[deprecated("call inside() on the polygon")]] static bool inside(const T & p, const ofPolyline_ & polyline); + /// \brief Tests whether the x,y coordinates are within a closed ofPolyline. bool inside(float x, float y) const; - /// \brief Tests whether the T is within a closed ofPolyline. - static bool inside(const T & p, const ofPolyline_ & polyline); /// \brief Tests whether the T is within a closed ofPolyline. bool inside(const T & p) const; @@ -435,8 +429,7 @@ class ofPolyline_ { /// \brief Gets the point on the line closest to the target. You can also /// optionally pass a pointer to/address of an unsigned int to get the /// index of the closest vertex - T getClosestPoint(const T& target, unsigned int* nearestIndex = nullptr) const; - + T getClosestPoint(const T & target, unsigned int * nearestIndex = nullptr) const; /// \} /// \name Other Functions @@ -533,7 +526,6 @@ class ofPolyline_ { /// \} - private: void setCircleResolution(int res); float wrapAngle(float angleRad); @@ -542,28 +534,27 @@ class ofPolyline_ { T rightVector; // cache - mutable std::vector lengths; // cumulative lengths, stored per point (lengths[n] is the distance to the n'th point, zero based) - mutable std::vector tangents; // tangent at vertex, stored per point - mutable std::vector normals; // - mutable std::vector rotations; // rotation axes between adjacent segments, stored per point (cross product) - mutable std::vector angles; // angle (rad) between adjacent segments, stored per point (asin(cross product)) + mutable std::vector lengths; // cumulative lengths, stored per point (lengths[n] is the distance to the n'th point, zero based) + mutable std::vector tangents; // tangent at vertex, stored per point + mutable std::vector normals; // + mutable std::vector rotations; // rotation axes between adjacent segments, stored per point (cross product) + mutable std::vector angles; // angle (rad) between adjacent segments, stored per point (asin(cross product)) mutable T centroid2D; mutable float area; - std::deque curveVertices; std::vector circlePoints; bool bClosed; - bool bHasChanged; // public API has access to this - mutable bool bCacheIsDirty; // used only internally, no public API to read + bool bHasChanged; // public API has access to this + mutable bool bCacheIsDirty; // used only internally, no public API to read void updateCache(bool bForceUpdate = false) const; // given an interpolated index (e.g. 5.75) return neighboring indices and interolation factor (e.g. 5, 6, 0.75) - void getInterpolationParams(float findex, int &i1, int &i2, float &t) const; + void getInterpolationParams(float findex, int & i1, int & i2, float & t) const; - void calcData(int index, T &tangent, float &angle, T &rotation, T &normal) const; + void calcData(int index, T & tangent, float & angle, T & rotation, T & normal) const; }; #include "ofPolyline.inl" @@ -575,19 +566,18 @@ using ofPolyline = ofPolyline_; /// \param y The y dimension of the coordinate. /// \param polygon a vector of glm::vec3s defining a polygon. /// \returns True if the point defined by the coordinates is enclosed, false otherwise. -template -bool ofInsidePoly(float x, float y, const std::vector& polygon){ - return ofPolyline_::inside(x,y, ofPolyline_(polygon)); +template +bool ofInsidePoly(float x, float y, const std::vector & polygon) { + return ofPolyline_::inside(x, y, ofPolyline_(polygon)); } - /// \brief Determine if an glm::vec3 is within the polygon defined by a vector of glm::vec3s. /// \param p A point to check. /// \param poly A vector of glm::vec3s defining a polygon. /// \returns True if the glm::vec3 is enclosed, false otherwise. -template -bool ofInsidePoly(const T& p, const std::vector& poly){ - return ofPolyline_::inside(p.x,p.y, ofPolyline_(poly)); +template +bool ofInsidePoly(const T & p, const std::vector & poly) { + return ofPolyline_::inside(p.x, p.y, ofPolyline_(poly)); } #endif diff --git a/libs/openFrameworks/math/ofQuaternion.h b/libs/openFrameworks/math/ofQuaternion.h index 00eca944301..0da99cc40c5 100644 --- a/libs/openFrameworks/math/ofQuaternion.h +++ b/libs/openFrameworks/math/ofQuaternion.h @@ -30,7 +30,7 @@ class ofQuaternion { public: // float _v[4]; /// \cond INTERNAL - ofVec4f _v; + ofVec4f _v {}; /// \endcond diff --git a/libs/openFrameworks/math/ofVec2f.h b/libs/openFrameworks/math/ofVec2f.h index cecf23843e6..ae7a5665f0d 100644 --- a/libs/openFrameworks/math/ofVec2f.h +++ b/libs/openFrameworks/math/ofVec2f.h @@ -1,8 +1,5 @@ #pragma once -#include "ofMath.h" -#include "ofMathConstants.h" - #define GLM_FORCE_CTOR_INIT #include "glm/vec2.hpp" #include "glm/fwd.hpp" @@ -12,39 +9,39 @@ class ofVec3f; class ofVec4f; /// \brief -/// ofVec2f is a class for storing a two dimensional vector. +/// ofVec2f is a class for storing a two dimensional vector. /// /// Moving through space requires knowledge of where things are and where they are going. /// Vector Maths is the class of mathematics that gives us control over these /// things in space, allowing for elegant and intuitive descriptions of complex /// structures and movement. Vectors are at the heart of animations, particle /// systems, and 2D and 3D graphics. -/// +/// /// Vectors in mathematics in general are entities with magnitude (also called /// length) and direction. A vector whose magnitude is 1 (ie a vector that is /// *normalized*) is called a *unit vector*. Unit vectors are very handy for /// storing directions as they can be easily scaled up (or down) to represent /// motion in a particular direction with a particular length. -/// +/// /// *You will also see the term vector used to describe an array of objects in C++ /// (such as text strings). Don't let this confuse you, they are quite different: /// one of them is a mathematical term for a fixed-length list of numbers that /// you can do mathematical operations on, the other is a C++-specific term that /// means 'dynamically sizeable array'.* -/// +/// /// ofVec2f has two member variables, x and y, which allow to conveniently store /// 2D properties of an object such as its position, velocity, or acceleration. -/// +/// /// ~~~~{.cpp} /// ofVec2f v1; // v1.x is 0, v1.y is 0 /// v1.set( 10, 50 ); // now v1.x is 10, v1.y is 50 /// ~~~~ -/// +/// /// Using ofVec2f greatly simplifies arithmetic operations in two dimensions. For /// example if you have two vectors v1 and v2, both of which represent a 2D change /// in position, you can find the total change of position of both of them just by /// doing an addition v1 + v2: -/// +/// /// ~~~~{.cpp} /// ofVec2f v1(5, 2); // v1 represents walking 5 steps forward then 2 steps sideways /// ofVec2f v2; @@ -52,17 +49,17 @@ class ofVec4f; /// // what happens if you do v1 followed by v2? just add v1 and v2 together: /// ofVec2f result = v1 + v2; // result is 6 steps forward then 3 steps sideways /// ~~~~ -/// +/// /// You can scale an ofVec2f by multiplying it with a float: -/// +/// /// ~~~~{.cpp} /// ofVec2f v1(5, 2); // walk 5 steps forward and 2 steps right /// // what happens if we do v1 three times? /// ofVec2f result = v1 * 3; // result is 15 steps forward and 6 steps right /// ~~~~ -/// +/// /// This also works for subtraction and division. -/// +/// /// As you can see this really makes dealing with vectors as easy as dealing with /// single floats or ints, and can reduce the number of lines of code you have to /// write by half, at the same time making your code much easier to read and @@ -75,19 +72,19 @@ class ofVec2f { /// \cond INTERNAL static const int DIM = 2; //// \endcond - + /// \brief Stores the `x` component of the vector. float x; /// \brief Stores the `y` component of the vector. float y; - - //--------------------- + + //--------------------- /// \name Construct a 2D vector /// \{ - + /// \brief Construct a 2D vector. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1; // default: v1.x is 0, v1.y is 0 /// ofVec2f v2 = ofVec2f(40, 20); // v2.x is 40, v2.y is 20 @@ -97,10 +94,10 @@ class ofVec2f { ofVec2f(); /// \brief Construct a 2D vector with `x` and `y` set to `scalar` - explicit ofVec2f( float scalar ); - + explicit ofVec2f(float scalar); + /// \brief Construct a 2D vector with specific `x` and `y components - /// + /// /// ~~~~{.cpp} /// ofVec2f v1; // default: v1.x is 0, v1.y is 0 /// ofVec2f v2 = ofVec2f(40, 20); // v2.x is 40, v2.y is 20 @@ -109,28 +106,28 @@ class ofVec2f { /// /// \param x The x component /// \param y The y component - ofVec2f( float x, float y ); + ofVec2f(float x, float y); /// \brief Create a 2D vector (ofVec2f) from a 3D vector (ofVec3f) by /// \throwing away the z component of the 3D vector. /// /// ~~~~{.cpp} - /// ofVec3f mom3d(40, 20, 50); // 3d vector + /// ofVec3f mom3d(40, 20, 50); // 3d vector /// ofVec2f v(mom3d); // v.x is 40, v.y is 20 /// ~~~~ - /// - ofVec2f( const ofVec3f& vec ); + /// + ofVec2f(const ofVec3f & vec); /// \brief Create a 2D vector (ofVec2f) from a 4D vector (ofVec4f) by throwing away the z /// and w components of the 4D vector. - /// + /// /// ~~~~{.cpp} - /// ofVec4f mom4d(40, 20, 50, 80); // 4d vector + /// ofVec4f mom4d(40, 20, 50, 80); // 4d vector /// ofVec2f v(mom4d); // v.x is 40, v.y is 20 /// ~~~~ - /// - ofVec2f( const ofVec4f& vec ); - + /// + ofVec2f(const ofVec4f & vec); + /// \} ofVec2f(const glm::vec2 & v); @@ -143,83 +140,79 @@ class ofVec2f { /// \name Access components /// \{ - /// \brief Returns a pointer to the memory position of the first element of the vector (x); /// the second element (y) immediately follows it in memory. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1 = ofVec2f(40, 20); /// float * v1Ptr = v1.getPtr(); /// float x = *(v1Ptr); // x is 40 /// float y = *(v1Ptr+1); // y is 20 /// ~~~~ - /// + /// /// This is very useful when using arrays of ofVec2fs to store geometry /// information, as it allows the vector to be treated as a simple C array of - /// floats that can be passed verbatim to OpenGL. + /// floats that can be passed verbatim to OpenGL. float * getPtr() { - return (float*)&x; + return (float *)&x; } const float * getPtr() const { return (const float *)&x; } - + /// \brief Allows to access the x and y components of an ofVec2f as though it is an array - /// + /// /// ~~~~{.cpp} /// ofVec2f v1 = ofVec2f(40, 20); /// float x = v1[0]; // x is 40 /// float y = v1[1]; // y is 20 /// ~~~~ - /// + /// /// This function can be handy if you want to do the same operation to both x and /// y components, as it means you can just make a for loop that repeats twice. - float& operator[]( int n ){ + float & operator[](int n) { return getPtr()[n]; } - - float operator[]( int n ) const { + + float operator[](int n) const { return getPtr()[n]; } - - - + /// \brief Set x and y components of this vector with just one function call. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1;//#include "ofConstants.h" //#include "glm/fwd.hpp" /// v1.set(40, 20); /// ~~~~ - /// - void set( float x, float y ); + /// + void set(float x, float y); /// \brief Set the x and y components of this vector by copying the corresponding values from vec. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(40, 20); /// ofVec2f v2; /// v2.set(v1); // v2.x is 40, v2.y is 20 /// ~~~~ - /// - void set( const ofVec2f& vec ); - - void set( float scalar ); + /// + void set(const ofVec2f & vec); - /// \} + void set(float scalar); + + /// \} - //--------------------- - /// \name Comparison + //--------------------- + /// \name Comparison /// \{ - /// \brief Check for equality between two ofVec2f - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1(40, 20); - /// ofVec2f v2(50, 30); - /// ofVec2f v3(40, 20); + /// ofVec2f v1(40, 20); + /// ofVec2f v2(50, 30); + /// ofVec2f v3(40, 20); /// // ( v1 == v2 ) is false /// // ( v1 == v3 ) is true /// ~~~~ @@ -227,14 +220,14 @@ class ofVec2f { /// \returns true if each component is the same as the corresponding /// component in vec, ie if x == vec.x and y == vec.y; otherwise returns /// false. - bool operator==( const ofVec2f& vec ) const; + bool operator==(const ofVec2f & vec) const; - /// \brief Check for inequality between two ofVec2f - /// + /// \brief Check for inequality between two ofVec2f + /// /// ~~~~{.cpp} - /// ofVec2f v1(40, 20); - /// ofVec2f v2(50, 30); - /// ofVec2f v3(40, 20); + /// ofVec2f v1(40, 20); + /// ofVec2f v2(50, 30); + /// ofVec2f v3(40, 20); /// // ( v1 != v2 ) is true /// // ( v1 != v3 ) is false /// ~~~~ @@ -242,319 +235,298 @@ class ofVec2f { /// \returns true if any component is different to its corresponding /// component in vec, ie if 'x != vec.x' or 'y != vec.y', otherwise returns /// false. - bool operator!=( const ofVec2f& vec ) const; + bool operator!=(const ofVec2f & vec) const; /// \brief Returns true if each component is *close enough* to its corresponding /// component in vec, where what is *close enough* is determined by the value of /// tolerance: - /// + /// /// ~~~~{.cpp} /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(40.01, 19.999); /// // v1.match(v2, 0.1) returns true /// // v1.match(v2, 0.001) returns false /// ~~~~ - /// + /// /// This is handy if, for example, you want to find out when a point becomes /// *close enough* to another point to trigger an event. - /// - bool match( const ofVec2f& vec, float tolerance = 0.0001f ) const; - + /// + bool match(const ofVec2f & vec, float tolerance = 0.0001f) const; + /// \brief Determine if two vectors are aligned - /// - /// ~~~~{.cpp} + /// + /// ~~~~{.cpp} /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(4, 2); /// v1.isAligned(v2) // returns true /// ~~~~ - /// \param vec The vector to compare alignment with - /// \param tolerance an angle tolerance/threshold (specified in degrees) for deciding if the vectors are sufficiently aligned. - /// \returns true if both vectors are aligned (pointing in the same direction). - bool isAligned( const ofVec2f& vec, float tolerance = 0.0001f ) const; - - /// \brief Determine if two vectors are aligned with tolerance in radians - /// \param vec The vector to compare alignment with - /// \param tolerance an angle tolerance/threshold (specified in radians) for deciding if the vectors are sufficiently aligned. - /// \sa isAligned() - bool isAlignedRad( const ofVec2f& vec, float tolerance = 0.0001f ) const; - - /// \brief Determine if two vectors are aligned - /// - /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); - /// ofVec2f v2 = ofVec2f(4, 2); - /// v1.align(v2) // returns true - /// ~~~~ - /// \param vec The vector to compare alignment with - /// \param tolerance an angle tolerance/threshold (specified in degrees) for deciding if the vectors are sufficiently aligned. - /// \returns true if both vectors are aligned (pointing in the same direction). - bool align( const ofVec2f& vec, float tolerance = 0.0001f ) const; - - /// \brief Determine if two vectors are aligned with tolerance in radians - /// \param vec The vector to compare alignment with - /// \param tolerance an angle tolerance/threshold (specified in radians) for deciding if the vectors are sufficiently aligned. - /// \sa align() - bool alignRad( const ofVec2f& vec, float tolerance = 0.0001f ) const; - + /// \param vec The vector to compare alignment with + /// \param tolerance an angle tolerance/threshold (specified in degrees) for deciding if the vectors are sufficiently aligned. + /// \returns true if both vectors are aligned (pointing in the same direction). + bool isAligned(const ofVec2f & vec, float tolerance = 0.0001f) const; + + /// \brief Determine if two vectors are aligned with tolerance in radians + /// \param vec The vector to compare alignment with + /// \param tolerance an angle tolerance/threshold (specified in radians) for deciding if the vectors are sufficiently aligned. + /// \sa isAligned() + bool isAlignedRad(const ofVec2f & vec, float tolerance = 0.0001f) const; + + [[deprecated("use isAligned()")]] bool align(const ofVec2f & vec, float tolerance = 0.0001f) const; + [[deprecated("use isAlignedRad()")]] bool alignRad(const ofVec2f & vec, float tolerance = 0.0001f) const; + /// \} //--------------------- /// \name Operators /// \{ - /// \brief Super easy vector addition. Returns a new vector (x+vec.x,y+vec.y). - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(25, 50); /// ofVec3f v3 = v1 + v2; // v3 is (65, 70) /// ~~~~ - ofVec2f operator+( const ofVec2f& vec ) const; - - /// \brief Returns a new vector with a float value f added to both x and y members. - /// + ofVec2f operator+(const ofVec2f & vec) const; + + /// \brief Returns a new vector with a float value f added to both x and y members. + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// ofVec2f v2 = v1 + 10; // (12, 15) /// ~~~~ - ofVec2f operator+( const float f ) const; + ofVec2f operator+(const float f) const; /// \brief Super easy addition assignment. Adds vec.x to x, and adds vec.y to y. - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(25, 50); /// v1 += v2; // v1 is (65, 70) /// ~~~~ - ofVec2f& operator+=( const ofVec2f& vec ); + ofVec2f & operator+=(const ofVec2f & vec); /// \brief Adds a float value f to both x and y members. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// v1 += 10; // (12, 15) /// ~~~~ - ofVec2f& operator+=( const float f ); + ofVec2f & operator+=(const float f); - /// \brief Super easy vector subtraction. Returns a new vector (x-vec.x,y-vec.y). - /// + /// \brief Super easy vector subtraction. Returns a new vector (x-vec.x,y-vec.y). + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(25, 50); /// ofVec3f v3 = v1 - v2; // v3 is (15, -30) /// ~~~~ - ofVec2f operator-( const ofVec2f& vec ) const; - + ofVec2f operator-(const ofVec2f & vec) const; + /// \brief Returns a new vector with a float value f subtracted from both x and y members. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// ofVec2f v2 = v1 - 10; // (-8, -5) /// ~~~~ - ofVec2f operator-( const float f ) const; + ofVec2f operator-(const float f) const; /// \brief Returns a new ofVec2f that is the inverted version (mirrored in X and Y) of this vector. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// ofVec2f v2 = -v1; // (-2, -5) - /// ~~~~ - ofVec2f operator-() const; + /// ~~~~ + ofVec2f operator-() const; /// \brief Super easy subtraction assignment. Subtracts vec.x from x, and subtracts vec.y from y. - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(25, 50); /// v1 -= v2; // v1 is (15, -30) /// ~~~~ - ofVec2f& operator-=( const ofVec2f& vec ); + ofVec2f & operator-=(const ofVec2f & vec); - /// \brief Subtract a float value f from both x and y members. - /// + /// \brief Subtract a float value f from both x and y members. + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// v1 -= 10; // (-8, -5) /// ~~~~ - ofVec2f& operator-=( const float f ); + ofVec2f & operator-=(const float f); /// \brief Returns a new vector (x*vec.x , y*vec.y). - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(2, 4); /// ofVec2f v3 = v1 * v2; // (80, 80) /// ~~~~ - /// + /// /// Useful for scaling a 2D point by a non-uniform scale. - /// - ofVec2f operator*( const ofVec2f& vec ) const; - + /// + ofVec2f operator*(const ofVec2f & vec) const; + /// \brief Return a new ofVec2f that is this vector scaled by multiplying both x /// and y members by the float. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// ofVec2f v2 = v1 * 4; // (8, 20) /// ~~~~ - ofVec2f operator*( const float f ) const; + ofVec2f operator*(const float f) const; /// \brief Multiplies x by vec.x, and multiplies y by vec.y. - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(2, 4); /// v1 *= v2; // v1 is now (80, 80) /// ~~~~ - /// + /// /// Useful for scaling a 2D point by a non-uniform scale. - ofVec2f& operator*=( const ofVec2f& vec ); + ofVec2f & operator*=(const ofVec2f & vec); /// \brief Scale this vector by multiplying both x and y members by f. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// v1 *= 4; // (8, 20) /// ~~~~ - ofVec2f& operator*=( const float f ); + ofVec2f & operator*=(const float f); /// \brief Returns a new vector (x/vec.x,y/vec.y). - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(2, 4); /// ofVec3f v3 = v1 / v2; // (20, 5) /// ~~~~ - /// + /// /// Useful for scaling a 2D point by a non-uniform scale. - ofVec2f operator/( const ofVec2f& vec ) const; + ofVec2f operator/(const ofVec2f & vec) const; /// \brief Return a new ofVec2f that is this vector scaled by dividing /// both x and y members by f. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// ofVec2f v2 = v1 / 4; // (0.5, 1.25) /// ~~~~ - ofVec2f operator/( const float f ) const; + ofVec2f operator/(const float f) const; /// \brief Divides x by vec.x, and divides y by vec.y. - /// + /// /// ~~~~{.cpp} - /// ofVec2f v1 = ofVec2f(40, 20); + /// ofVec2f v1 = ofVec2f(40, 20); /// ofVec2f v2 = ofVec2f(2, 4); /// v1 *= v2; // v1 is now (20, 5) /// ~~~~ - /// + /// /// Useful for scaling a 2D point by a non-uniform scale. - ofVec2f& operator/=( const ofVec2f& vec ); - + ofVec2f & operator/=(const ofVec2f & vec); + /// \brief Scale this vector by dividing both x and y members by f. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(2, 5); /// v1 /= 4; // (0.5, 1.25) /// ~~~~ - ofVec2f& operator/=( const float f ); + ofVec2f & operator/=(const float f); - /// \cond INTERNAL - friend std::ostream& operator<<(std::ostream& os, const ofVec2f& vec); - friend std::istream& operator>>(std::istream& is, const ofVec2f& vec); + friend std::ostream & operator<<(std::ostream & os, const ofVec2f & vec); + friend std::istream & operator>>(std::istream & is, const ofVec2f & vec); /// \endcond - + /// \} - + //--------------------- /// \name Simple manipulations /// \{ /// Return a new ofVec2f that is the result of scaling this vector up or down so /// that it has the requested length. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1( 3, 4 ); // length is 5 /// ofVec2f v2 = v1.getScaled( 15 ); // ( 9, 12 ), length is now 15 - /// ~~~~ofVec2f - /// + /// ~~~~ofVec2f + /// /// \sa scale() - ofVec2f getScaled( const float length ) const; - + ofVec2f getScaled(const float length) const; + /// \brief Scales this vector up or down so that it has the requested length. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1( 3, 4 ); // length is 5 /// v1.scale( 15 ); // v1 is now (9, 12), with length 15 /// ~~~~ /// /// \sa getScaled() - ofVec2f& scale( const float length ); - - - /// \brief Returns a new vector that is the result of rotating this vector + ofVec2f & scale(const float length); + + /// \brief Returns a new vector that is the result of rotating this vector /// by 'angle' degrees about the origin. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(1, 0); /// ofVec2f v2 = v1.getRotated(45); // v2 is (0.707, 0.707) /// ~~~~ - /// + /// /// \sa getRotatedRad() /// \sa rotate() - ofVec2f getRotated( float angle ) const; + ofVec2f getRotated(float angle) const; /// \brief Returns a new vector that is the result of rotating this vector /// by 'angle' degrees about the point 'pivot'. /// - ofVec2f getRotated( float angle, const ofVec2f& pivot ) const; - - /// \brief Returns a new vector that is the result of rotating this vector + ofVec2f getRotated(float angle, const ofVec2f & pivot) const; + + /// \brief Returns a new vector that is the result of rotating this vector /// by 'angle' radians about the origin. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(1, 0); /// ofVec2f v2 = v1.getRotatedRad(PI / 4); // v2 is (0.707, 0.707) /// ~~~~ - /// - ofVec2f getRotatedRad( float angle ) const; + /// + ofVec2f getRotatedRad(float angle) const; /// \brief Returns a new vector that is the result of rotating this vector - /// by 'angle' radians about the origin. + /// by 'angle' radians about the origin. /// - ofVec2f getRotatedRad( float angle, const ofVec2f& pivot ) const; - + ofVec2f getRotatedRad(float angle, const ofVec2f & pivot) const; /// \brief Rotates this vector by 'angle' degrees about the origin. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(1, 0); /// v1.rotate(45); // v1 is now (0.707, 0.707) /// ~~~~ /// /// \sa getRotated() - ofVec2f& rotate( float angle ); + ofVec2f & rotate(float angle); /// \brief Rotates this vector by 'angle' degrees about the point 'pivot'. - ofVec2f& rotate( float angle, const ofVec2f& pivot ); - + ofVec2f & rotate(float angle, const ofVec2f & pivot); + /// \brief Rotates this vector by 'angle' radians about the origin. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(1, 0); /// v1.rotateRad(PI / 4); // v1 is now (0.707, 0.707) /// ~~~~ /// /// \sa getRotatedRad() - ofVec2f& rotateRad( float angle ); - + ofVec2f & rotateRad(float angle); + /// \brief Rotates this vector by 'angle' radians about the point 'pivot'. - ofVec2f& rotateRad( float angle, const ofVec2f& pivot ); - - - + ofVec2f & rotateRad(float angle, const ofVec2f & pivot); + /// \brief Get vector mapped to new coordinate system - /// + /// /// In most cases you want `vx` and `vy` to be perpendicular and of unit length; if /// they are not perpendicular you will have shearing as part of the mapping, and /// if they are not of unit length you will have scaling as part of the mapping. @@ -563,65 +535,62 @@ class ofVec2f { /// its default coordinate system -- origin (0,0), X direction (1,0), Y direction /// (0,1) -- to a new coordinate system defined with origin at origin, X direction /// vx, and Y direction vy. - ofVec2f getMapped( const ofVec2f& origin, - const ofVec2f& vx, - const ofVec2f& vy ) const; - + ofVec2f getMapped(const ofVec2f & origin, + const ofVec2f & vx, + const ofVec2f & vy) const; /// \brief Maps this vector from its default coordinate system -- origin (0,0), X /// direction (1,0), Y direction (0,1) -- to a new coordinate system defined with /// origin at origin, X direction vx, and Y direction vy. - /// + /// /// In most case you want vx and vy to be perpendicular and of unit length; if /// they are not perpendicular you will have shearing as part of the mapping, and /// if they are not of unit length you will have scaling as part of the mapping. - /// + /// /// \sa perpendicular() - ofVec2f& map( const ofVec2f& origin, - const ofVec2f& vx, const ofVec2f& vy ); + ofVec2f & map(const ofVec2f & origin, + const ofVec2f & vx, const ofVec2f & vy); + /// \} - /// \} - - //--------------------- /// \name Distance /// \{ - /// \brief Distance between two points. - /// - /// Treats both this vector and pnt as points in 2D space, and calculates and - /// returns the distance between them. - /// + /// \brief Distance between two points. + /// + /// Treats both this vector and pnt as points in 2D space, and calculates and + /// returns the distance between them. + /// /// ~~~~{.cpp} /// ofVec2f p1( 3, 4 ); /// ofVec2f p2( 6, 8 ); /// float distance = p1.distance( p2 ); // distance is 5 /// ~~~~ - /// + /// /// Distance involves a square root calculation, which is one of the slowest /// things you can do in programming. If you don't need an exact number but rather /// just a rough idea of distance (for example when finding the shortest distance /// of a bunch of points to a reference point, where it doesn't matter exactly /// what the distances are, you just want the shortest), you can use /// squareDistance() instead. - /// + /// /// \param pnt The point to calculate the distance to /// \returns The distance as float /// \sa squareDistance() - float distance( const ofVec2f& pnt) const; + float distance(const ofVec2f & pnt) const; - /// \brief Distance between two points squared. - /// + /// \brief Distance between two points squared. + /// /// Treats both this vector and pnt as points in 2D space, and calculates and /// returns the squared distance between them. - /// + /// /// ~~~~{.cpp} /// ofVec2f p1( 3, 4 ); /// ofVec2f p2( 6, 8 ); /// float distance = p1.distance( p2 ); // distance is 5 /// ~~~~ - /// + /// /// Use as a much faster alternative to [distance](#distance) if you don't need to /// know an exact number but rather just a rough idea of distance (for example /// when finding the shortest distance of a bunch of points to a reference point, @@ -631,24 +600,24 @@ class ofVec2f { /// /// \returns The distance squared as float /// \sa distance() - float squareDistance( const ofVec2f& pnt ) const; - + float squareDistance(const ofVec2f & pnt) const; + /// \} //--------------------- /// \name Interpolation /// \{ - /// \brief Linear interpolation - /// + /// \brief Linear interpolation + /// /// Perform a linear interpolation of this vector's position towards pnt /// and return the interpolated position without altering the original - /// vector. - /// + /// vector. + /// /// `p` is normally between 0 and 1 and where 0 means stay the original position and 1 /// means move all the way to pnt, but you can also have p greater than 1 /// overshoot pnt, or less than 0 to move backwards away from pnt. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1( 0, 5 ); /// ofVec2f v2( 10, 10 ); @@ -659,16 +628,16 @@ class ofVec2f { /// \param pnt The point to move towards /// \param p The amount to move towards pnt /// \sa interpolate() - ofVec2f getInterpolated( const ofVec2f& pnt, float p ) const; - - /// \brief Linear interpolation - /// + ofVec2f getInterpolated(const ofVec2f & pnt, float p) const; + + /// \brief Linear interpolation + /// /// Perform a linear interpolation of this vector's position towards pnt. p /// controls the amount to move towards pnt. p is normally between 0 and 1 and /// where 0 means stay the original position and 1 means move all the way to pnt, /// but you can also have p greater than 1 overshoot pnt, or less than 0 to move /// backwards away from pnt. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1( 0, 5 ); /// ofVec2f v2( 10, 10 ); @@ -678,12 +647,12 @@ class ofVec2f { /// v1.interpolate( v2, 0.5 ); // v1 is now (8.75, 9.375) /// v1.interpolate( v2, 0.5 ); // v1 is now (9.375, 9.6875) /// ~~~~ - /// + /// /// \sa getInterpolated() - ofVec2f& interpolate( const ofVec2f& pnt, float p ); + ofVec2f & interpolate(const ofVec2f & pnt, float p); /// \brief Calculate and return the midpoint between this vector and pnt. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(5, 0); /// ofVec2f v2(10, 10); @@ -693,10 +662,10 @@ class ofVec2f { /// \param pnt The vector to find the middle to /// \returns The middle between this vector and `pnt` /// \sa middle() - ofVec2f getMiddle( const ofVec2f& pnt ) const; + ofVec2f getMiddle(const ofVec2f & pnt) const; /// \brief Set this vector to the midpoint between itself and pnt. - /// + /// /// ~~~~{.cpp} /// ofVec2f v1( 0, 5 ); /// ofVec2f v2( 10, 10 ); @@ -704,16 +673,16 @@ class ofVec2f { /// v1.middle( v2 ); // v1 is now (7.5, 8.75) /// v1.middle( v2 ); // v1 is now (8.75, 9.375) /// v1.middle( v2 ); // v1 is now (9.375, 9.6875) - /// ~~~~ - /// + /// ~~~~ + /// /// \sa getMiddle() - ofVec2f& middle( const ofVec2f& pnt ); + ofVec2f & middle(const ofVec2f & pnt); - /// \brief Average vector over an array of points - /// - /// Sets this vector to be the average (*centre of gravity* or *centroid*) - /// of a given array of ofVec2f. - /// + /// \brief Average vector over an array of points + /// + /// Sets this vector to be the average (*centre of gravity* or *centroid*) + /// of a given array of ofVec2f. + /// /// ~~~~{.cpp} /// int numPoints = 10; /// ofVec2f points[numPoints]; @@ -721,43 +690,43 @@ class ofVec2f { /// points[i].set( ofRandom(0,100), ofRandom(0,100) ); /// } /// ofVec2f centroid; - /// centroid.average( points, numPoints ); + /// centroid.average( points, numPoints ); /// // centroid now is the centre of gravity/average of all the random points /// ~~~~ - /// + /// /// \param points The array of ofVec2f to avarage over /// \param num specifies the number of ofVec2f in the array. /// \returns Vector that is the avarage of the points in the array - ofVec2f& average( const ofVec2f* points, std::size_t num ); - - /// \} + ofVec2f & average(const ofVec2f * points, std::size_t num); - //--------------------- + /// \} + + //--------------------- /// \name Limit /// \{ - /// \brief Returns a normalized copy of this vector. - /// + /// \brief Returns a normalized copy of this vector. + /// /// *Normalization* means to scale the vector so that its length /// (magnitude) is exactly 1, at which stage all that is left is the /// direction. A normalized vector is usually called a *unit vector*, and - /// can be used to represent a pure direction (heading). - /// + /// can be used to represent a pure direction (heading). + /// /// ~~~~{.cpp} /// ofVec2f v1(5, 0); /// ofVec2f v1Normalized = v1.getNormalized(); // (1, 0) /// ofVec2f v2(5, 5); /// ofVec2f v2Normalized = v2.getNormalized(); // (√2, √2) /// ~~~~ - ofVec2f getNormalized() const; + ofVec2f getNormalized() const; /// \brief Normalize the vector. - /// + /// /// *Normalizing* means to scale the vector so that its length (magnitude) is /// exactly 1, at which stage all that is left is the direction. A normalized /// vector is usually called a *unit vector*, and can be used to represent a pure /// direction (heading). - /// + /// /// ~~~~{.cpp} /// ofVec2f v1(5, 0); /// v1.normalize(); // v2 is now (1, 0) @@ -765,57 +734,52 @@ class ofVec2f { /// v2.normalize(); // v2 is now (√2, √2) /// ~~~~ /// \sa getNormalized() - ofVec2f& normalize(); - - - - /// \brief Get vector limited by length - /// + ofVec2f & normalize(); + + /// \brief Get vector limited by length + /// /// ~~~~{.cpp} /// ofVec2f v1(5, 1); // length is about 5.1 /// ofVec2f v2(2, 1); // length is about 2.2 - /// ofVec2f v1Limited = v1.getLimited(3); + /// ofVec2f v1Limited = v1.getLimited(3); /// // v1Limited is (2.9417, 0.58835) which has length of 3 in the same direction as v1 /// ofVec2f v2Limited = v2.getLimited(3); /// // v2Limited is (2, 1) (same as v2) /// ~~~~ - /// + /// /// \sa limit() /// \param max The maximum length of the vector to return /// \returns A copy of this vector with its length (magnitude) restricted to a - /// maximum of max units by scaling down if necessary. - ofVec2f getLimited(float max) const; - + /// maximum of max units by scaling down if necessary. + ofVec2f getLimited(float max) const; - /// \brief Restrict the length (magnitude) of this vector to a maximum of max units by scaling down if necessary. - /// + /// \brief Restrict the length (magnitude) of this vector to a maximum of max units by scaling down if necessary. + /// /// ~~~~{.cpp} /// ofVec2f v1(5, 1); // length is about 5.1 /// ofVec2f v2(2, 1); // length is about 2.2 - /// v1.limit(3); + /// v1.limit(3); /// // v1 is now (2.9417, 0.58835) which has length of 3 in the same direction as at initialization /// v2.limit(3); /// // v2 is unchanged /// ~~~~ /// /// \sa limit() - ofVec2f& limit(float max); + ofVec2f & limit(float max); - /// \} //--------------------- /// \name Measurement /// \{ - /// \brief Return the length (magnitude) of this vector. - /// + /// /// ~~~~{.cpp} /// ofVec2f v(3, 4); /// float len = v.length(); // len is 5 (3,4,5 triangle) /// ~~~~ - /// + /// /// length() involves a square root calculation, which is one of the slowest things /// you can do in programming. If you don't need an exact number but rather just a /// rough idea of a length (for example when finding the shortest distance of a @@ -824,15 +788,15 @@ class ofVec2f { /// lengthSquared() instead. /// /// \sa lengthSquared() - float length() const; - + float length() const; + /// \brief Return the squared length (squared magnitude) of this vector. - /// + /// /// ~~~~{.cpp} /// ofVec2f v(3, 4); /// float len = v.length(); // len is 5 (3,4,5 triangle) /// ~~~~ - /// + /// /// Use as a much faster alternative to length() if you don't /// need to know an accurate length but rather just a rough idea of a /// length (for example when finding the shortest distance of a bunch of @@ -841,10 +805,10 @@ class ofVec2f { /// calculation that is ordinarily required to calculate a length. /// /// \sa length() - float lengthSquared() const; + float lengthSquared() const; - /// \brief Calculate the angle to another vector in degrees - /// + /// \brief Calculate the angle to another vector in degrees + /// /// ~~~~{.cpp} /// ofVec2f v1(1,0); /// ofVec2f v2(0,1); @@ -852,10 +816,10 @@ class ofVec2f { /// ~~~~ /// \param vec The vector to calculate the angle to /// \returns The angle in degrees (-180...180) - float angle( const ofVec2f& vec ) const; + float angle(const ofVec2f & vec) const; - /// \brief Calculate the angle to another vector in radians - /// + /// \brief Calculate the angle to another vector in radians + /// /// ~~~~{.cpp} /// ofVec2f v1(1,0); /// ofVec2f v2(0,1); @@ -863,8 +827,8 @@ class ofVec2f { /// ~~~~ /// \param vec The vector to calculate the angle to /// \returns The angle in radians (-PI...PI) - float angleRad( const ofVec2f& vec ) const; - + float angleRad(const ofVec2f & vec) const; + /// \} //--------------------- @@ -873,31 +837,31 @@ class ofVec2f { /// \brief Return the *normalized* ofVec2f that is perpendicular to this vector /// (ie rotated 90 degrees and normalized). - /// + /// /// ![PERPENDICULAR](math/perpendicular.png) /// Image courtesy of Wikipedia - /// + /// /// ~~~~{.cpp} /// ofVec2f v(2, 5); /// ofVec2f u = v.getPerpendicular(); // u is (0.928, -0.371) /// ~~~~ - /// + /// /// \sa perpendicular() - ofVec2f getPerpendicular() const; + ofVec2f getPerpendicular() const; /// \brief Set this vector to its own **normalized** perpendicular (by /// rotating 90 degrees and normalizing). - /// + /// /// ![PERPENDICULAR](math/perpendicular.png) /// Image courtesy of Wikipedia - /// + /// /// ~~~~{.cpp} /// ofVec2f v(2, 5); /// v.perpendicular(); // v is (0.928, -0.371) /// ~~~~ /// \sa getPerpendicular() - ofVec2f& perpendicular(); - + ofVec2f & perpendicular(); + /// \brief Returns the dot product of this vector with 'vec'. /// /// The *dot product* of two vectors, also known as the *scalar product*, is @@ -913,7 +877,7 @@ class ofVec2f { /// /// The dot product is in contrast to the *cross product*, which returns a /// vector rather than a scalar. - /// + /// /// ~~~~{.cpp} /// ofVec2f a1(2, 0); // magnitude 2, parallel to x-axis /// ofVec2f b1(3, 4); // magnitude 5, 53.13 degree angle to a1 @@ -927,17 +891,20 @@ class ofVec2f { /// ofVec2f b3(0, -1); // magnitude 1, 180 degree angle to a3 /// dot = a3.dot(b3); // dot is 1 * 1 * cos(180) = -1.0 /// ~~~~ - /// - float dot( const ofVec2f& vec ) const; - - + /// + float dot(const ofVec2f & vec) const; + /// \} + //--------------------------------------------------- + // this methods are deprecated in 006 please dont use: + /// \cond INTERNAL + // getScaled + OF_DEPRECATED_MSG("Use member method getScaled() instead.", ofVec2f rescaled(const float length) const); - //--------------------------------------------------- - // this methods are deprecated in 006 please dont use: - /// \cond INTERNAL + // scale + OF_DEPRECATED_MSG("Use member method scale() instead.", ofVec2f & rescale(const float length)); [[deprecated("Use member method getScaled()")]] ofVec2f rescaled( const float length ) const; @@ -981,141 +948,174 @@ class ofVec2f { /// \endcond }; + // getNormalized + OF_DEPRECATED_MSG("Use member method getNormalized() instead.", ofVec2f normalized() const); + // getLimited + OF_DEPRECATED_MSG("Use member method getLimited() instead.", ofVec2f limited(float max) const); -/// \cond INTERNAL + // getPerpendicular + OF_DEPRECATED_MSG("Use member method getPerpendicular() instead.", ofVec2f perpendiculared() const); -// Non-Member operators -// -ofVec2f operator+( float f, const ofVec2f& vec ); -ofVec2f operator-( float f, const ofVec2f& vec ); -ofVec2f operator*( float f, const ofVec2f& vec ); -ofVec2f operator/( float f, const ofVec2f& vec ); + // getInterpolated + OF_DEPRECATED_MSG("Use member method getInterpolated() instead.", ofVec2f interpolated(const ofVec2f & pnt, float p) const); + // getMiddled + OF_DEPRECATED_MSG("Use member method getMiddled() instead.", ofVec2f middled(const ofVec2f & pnt) const); -/// \endcond + // getMapped + OF_DEPRECATED_MSG("Use member method getMapped() instead.", ofVec2f mapped(const ofVec2f & origin, const ofVec2f & vx, const ofVec2f & vy) const); + + // squareDistance + OF_DEPRECATED_MSG("Use member method squareDistance() instead.", float distanceSquared(const ofVec2f & pnt) const); + // use getRotated + OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec2f rotated(float angle, const ofVec2f & pivot) const); + // return all zero vector + static ofVec2f zero() { return ofVec2f(0, 0); } + // return all one vector + static ofVec2f one() { return ofVec2f(1, 1); } + + /// \endcond +}; + +/// \cond INTERNAL + +// Non-Member operators +// +ofVec2f operator+(float f, const ofVec2f & vec); +ofVec2f operator-(float f, const ofVec2f & vec); +ofVec2f operator*(float f, const ofVec2f & vec); +ofVec2f operator/(float f, const ofVec2f & vec); + +/// \endcond ///////////////// // Implementation ///////////////// /// \cond INTERNAL - -inline ofVec2f::ofVec2f(): x(0), y(0) {} -inline ofVec2f::ofVec2f( float _scalar ): x(_scalar), y(_scalar) {} -inline ofVec2f::ofVec2f( float _x, float _y ):x(_x), y(_y) {} -inline ofVec2f::ofVec2f(const glm::vec2 & v): x(v.x), y(v.y) {} +inline ofVec2f::ofVec2f() + : x(0) + , y(0) { } +inline ofVec2f::ofVec2f(float _scalar) + : x(_scalar) + , y(_scalar) { } +inline ofVec2f::ofVec2f(float _x, float _y) + : x(_x) + , y(_y) { } +inline ofVec2f::ofVec2f(const glm::vec2 & v) + : x(v.x) + , y(v.y) { } // Getters and Setters. // // -inline void ofVec2f::set( float _scalar ) { +inline void ofVec2f::set(float _scalar) { x = _scalar; y = _scalar; } -inline void ofVec2f::set( float _x, float _y ) { +inline void ofVec2f::set(float _x, float _y) { x = _x; y = _y; } -inline void ofVec2f::set( const ofVec2f& vec ) { +inline void ofVec2f::set(const ofVec2f & vec) { x = vec.x; y = vec.y; } -inline ofVec2f::operator glm::vec2() const{ - return glm::vec2(x,y); +inline ofVec2f::operator glm::vec2() const { + return glm::vec2(x, y); } // Check similarity/equality. // // -inline bool ofVec2f::operator==( const ofVec2f& vec ) const { +inline bool ofVec2f::operator==(const ofVec2f & vec) const { return (x == vec.x) && (y == vec.y); } -inline bool ofVec2f::operator!=( const ofVec2f& vec ) const { +inline bool ofVec2f::operator!=(const ofVec2f & vec) const { return (x != vec.x) || (y != vec.y); } -inline bool ofVec2f::match( const ofVec2f& vec, float tolerance ) const { +inline bool ofVec2f::match(const ofVec2f & vec, float tolerance) const { return (fabs(x - vec.x) < tolerance) - && (fabs(y - vec.y) < tolerance); + && (fabs(y - vec.y) < tolerance); } // // Checks if vectors look in the same direction. // Tolerance is specified in degree. - -inline bool ofVec2f::isAligned( const ofVec2f& vec, float tolerance ) const { - return fabs( this->angle( vec ) ) < tolerance; + +inline bool ofVec2f::isAligned(const ofVec2f & vec, float tolerance) const { + return fabs(this->angle(vec)) < tolerance; } -inline bool ofVec2f::align( const ofVec2f& vec, float tolerance ) const { - return isAligned( vec, tolerance ); +inline bool ofVec2f::align(const ofVec2f & vec, float tolerance) const { + return isAligned(vec, tolerance); } -inline bool ofVec2f::isAlignedRad( const ofVec2f& vec, float tolerance ) const { - return fabs( this->angleRad( vec ) ) < tolerance; +inline bool ofVec2f::isAlignedRad(const ofVec2f & vec, float tolerance) const { + return fabs(this->angleRad(vec)) < tolerance; } -inline bool ofVec2f::alignRad( const ofVec2f& vec, float tolerance ) const { - return isAlignedRad( vec, tolerance ); +inline bool ofVec2f::alignRad(const ofVec2f & vec, float tolerance) const { + return isAlignedRad(vec, tolerance); } - // Overloading for any type to any type // // -inline ofVec2f ofVec2f::operator+( const ofVec2f& vec ) const { - return ofVec2f( x+vec.x, y+vec.y); +inline ofVec2f ofVec2f::operator+(const ofVec2f & vec) const { + return ofVec2f(x + vec.x, y + vec.y); } -inline ofVec2f& ofVec2f::operator+=( const ofVec2f& vec ) { +inline ofVec2f & ofVec2f::operator+=(const ofVec2f & vec) { x += vec.x; y += vec.y; return *this; } -inline ofVec2f ofVec2f::operator-( const ofVec2f& vec ) const { - return ofVec2f(x-vec.x, y-vec.y); +inline ofVec2f ofVec2f::operator-(const ofVec2f & vec) const { + return ofVec2f(x - vec.x, y - vec.y); } -inline ofVec2f& ofVec2f::operator-=( const ofVec2f& vec ) { +inline ofVec2f & ofVec2f::operator-=(const ofVec2f & vec) { x -= vec.x; y -= vec.y; return *this; } -inline ofVec2f ofVec2f::operator*( const ofVec2f& vec ) const { - return ofVec2f(x*vec.x, y*vec.y); +inline ofVec2f ofVec2f::operator*(const ofVec2f & vec) const { + return ofVec2f(x * vec.x, y * vec.y); } -inline ofVec2f& ofVec2f::operator*=( const ofVec2f& vec ) { - x*=vec.x; - y*=vec.y; +inline ofVec2f & ofVec2f::operator*=(const ofVec2f & vec) { + x *= vec.x; + y *= vec.y; return *this; } -inline ofVec2f ofVec2f::operator/( const ofVec2f& vec ) const { - return ofVec2f( vec.x!=0 ? x/vec.x : x , vec.y!=0 ? y/vec.y : y); +inline ofVec2f ofVec2f::operator/(const ofVec2f & vec) const { + return ofVec2f(vec.x != 0 ? x / vec.x : x, vec.y != 0 ? y / vec.y : y); } -inline ofVec2f& ofVec2f::operator/=( const ofVec2f& vec ) { - vec.x!=0 ? x/=vec.x : x; - vec.y!=0 ? y/=vec.y : y; +inline ofVec2f & ofVec2f::operator/=(const ofVec2f & vec) { + vec.x != 0 ? x /= vec.x : x; + vec.y != 0 ? y /= vec.y : y; return *this; } -inline std::ostream& operator<<(std::ostream& os, const ofVec2f& vec) { +inline std::ostream & operator<<(std::ostream & os, const ofVec2f & vec) { os << vec.x << ", " << vec.y; return os; } -inline std::istream& operator>>(std::istream& is, ofVec2f& vec) { +inline std::istream & operator>>(std::istream & is, ofVec2f & vec) { is >> vec.x; is.ignore(2); is >> vec.y; @@ -1130,21 +1130,21 @@ inline std::istream& operator>>(std::istream& is, ofVec2f& vec) { // y = f; //} -inline ofVec2f ofVec2f::operator+( const float f ) const { - return ofVec2f( x+f, y+f); +inline ofVec2f ofVec2f::operator+(const float f) const { + return ofVec2f(x + f, y + f); } -inline ofVec2f& ofVec2f::operator+=( const float f ) { +inline ofVec2f & ofVec2f::operator+=(const float f) { x += f; y += f; return *this; } -inline ofVec2f ofVec2f::operator-( const float f ) const { - return ofVec2f( x-f, y-f); +inline ofVec2f ofVec2f::operator-(const float f) const { + return ofVec2f(x - f, y - f); } -inline ofVec2f& ofVec2f::operator-=( const float f ) { +inline ofVec2f & ofVec2f::operator-=(const float f) { x -= f; y -= f; return *this; @@ -1154,184 +1154,173 @@ inline ofVec2f ofVec2f::operator-() const { return ofVec2f(-x, -y); } -inline ofVec2f ofVec2f::operator*( const float f ) const { - return ofVec2f(x*f, y*f); +inline ofVec2f ofVec2f::operator*(const float f) const { + return ofVec2f(x * f, y * f); } -inline ofVec2f& ofVec2f::operator*=( const float f ) { - x*=f; - y*=f; +inline ofVec2f & ofVec2f::operator*=(const float f) { + x *= f; + y *= f; return *this; } -inline ofVec2f ofVec2f::operator/( const float f ) const { - if(f == 0) return ofVec2f(x, y); - - return ofVec2f(x/f, y/f); +inline ofVec2f ofVec2f::operator/(const float f) const { + if (f == 0) return ofVec2f(x, y); + + return ofVec2f(x / f, y / f); } -inline ofVec2f& ofVec2f::operator/=( const float f ) { - if(f == 0) return *this; - - x/=f; - y/=f; +inline ofVec2f & ofVec2f::operator/=(const float f) { + if (f == 0) return *this; + + x /= f; + y /= f; return *this; } -inline ofVec2f ofVec2f::rescaled( const float length ) const { +inline ofVec2f ofVec2f::rescaled(const float length) const { return getScaled(length); } -inline ofVec2f ofVec2f::getScaled( const float length ) const { - float l = (float)sqrt(x*x + y*y); - if( l > 0 ) - return ofVec2f( (x/l)*length, (y/l)*length ); +inline ofVec2f ofVec2f::getScaled(const float length) const { + float l = (float)sqrt(x * x + y * y); + if (l > 0) + return ofVec2f((x / l) * length, (y / l) * length); else return ofVec2f(); } -inline ofVec2f& ofVec2f::rescale( const float length ){ +inline ofVec2f & ofVec2f::rescale(const float length) { return scale(length); } -inline ofVec2f& ofVec2f::scale( const float length ) { - float l = (float)sqrt(x*x + y*y); +inline ofVec2f & ofVec2f::scale(const float length) { + float l = (float)sqrt(x * x + y * y); if (l > 0) { - x = (x/l)*length; - y = (y/l)*length; + x = (x / l) * length; + y = (y / l) * length; } return *this; } - - // Rotation // // -inline ofVec2f ofVec2f::rotated( float angle ) const { +inline ofVec2f ofVec2f::rotated(float angle) const { return getRotated(angle); } -inline ofVec2f ofVec2f::getRotated( float angle ) const { +inline ofVec2f ofVec2f::getRotated(float angle) const { float a = (float)(ofDegToRad(angle)); - return ofVec2f( x*cos(a) - y*sin(a), - x*sin(a) + y*cos(a) ); + return ofVec2f(x * cos(a) - y * sin(a), + x * sin(a) + y * cos(a)); } -inline ofVec2f ofVec2f::getRotatedRad( float angle ) const { +inline ofVec2f ofVec2f::getRotatedRad(float angle) const { float a = angle; - return ofVec2f( x*cos(a) - y*sin(a), - x*sin(a) + y*cos(a) ); + return ofVec2f(x * cos(a) - y * sin(a), + x * sin(a) + y * cos(a)); } -inline ofVec2f& ofVec2f::rotate( float angle ) { +inline ofVec2f & ofVec2f::rotate(float angle) { float a = (float)(ofDegToRad(angle)); - float xrot = x*cos(a) - y*sin(a); - y = x*sin(a) + y*cos(a); + float xrot = x * cos(a) - y * sin(a); + y = x * sin(a) + y * cos(a); x = xrot; return *this; } -inline ofVec2f& ofVec2f::rotateRad( float angle ) { +inline ofVec2f & ofVec2f::rotateRad(float angle) { float a = angle; - float xrot = x*cos(a) - y*sin(a); - y = x*sin(a) + y*cos(a); + float xrot = x * cos(a) - y * sin(a); + y = x * sin(a) + y * cos(a); x = xrot; return *this; } - - // Rotate point by angle (deg) around pivot point. // // // This method is deprecated in 006 please use getRotated instead -inline ofVec2f ofVec2f::rotated( float angle, const ofVec2f& pivot ) const { +inline ofVec2f ofVec2f::rotated(float angle, const ofVec2f & pivot) const { return getRotated(angle, pivot); } -inline ofVec2f ofVec2f::getRotated( float angle, const ofVec2f& pivot ) const { +inline ofVec2f ofVec2f::getRotated(float angle, const ofVec2f & pivot) const { float a = (float)(ofDegToRad(angle)); - return ofVec2f( ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x, - ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y ); + return ofVec2f(((x - pivot.x) * cos(a) - (y - pivot.y) * sin(a)) + pivot.x, + ((x - pivot.x) * sin(a) + (y - pivot.y) * cos(a)) + pivot.y); } -inline ofVec2f& ofVec2f::rotate( float angle, const ofVec2f& pivot ) { +inline ofVec2f & ofVec2f::rotate(float angle, const ofVec2f & pivot) { float a = (float)(ofDegToRad(angle)); - float xrot = ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x; - y = ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y; + float xrot = ((x - pivot.x) * cos(a) - (y - pivot.y) * sin(a)) + pivot.x; + y = ((x - pivot.x) * sin(a) + (y - pivot.y) * cos(a)) + pivot.y; x = xrot; return *this; } -inline ofVec2f ofVec2f::getRotatedRad( float angle, const ofVec2f& pivot ) const { +inline ofVec2f ofVec2f::getRotatedRad(float angle, const ofVec2f & pivot) const { float a = angle; - return ofVec2f( ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x, - ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y ); + return ofVec2f(((x - pivot.x) * cos(a) - (y - pivot.y) * sin(a)) + pivot.x, + ((x - pivot.x) * sin(a) + (y - pivot.y) * cos(a)) + pivot.y); } -inline ofVec2f& ofVec2f::rotateRad( float angle, const ofVec2f& pivot ) { +inline ofVec2f & ofVec2f::rotateRad(float angle, const ofVec2f & pivot) { float a = angle; - float xrot = ((x-pivot.x)*cos(a) - (y-pivot.y)*sin(a)) + pivot.x; - y = ((x-pivot.x)*sin(a) + (y-pivot.y)*cos(a)) + pivot.y; + float xrot = ((x - pivot.x) * cos(a) - (y - pivot.y) * sin(a)) + pivot.x; + y = ((x - pivot.x) * sin(a) + (y - pivot.y) * cos(a)) + pivot.y; x = xrot; return *this; } - - // Map point to coordinate system defined by origin, vx, and vy. // // // This method is deprecated in 006 please use getMapped instead -inline ofVec2f ofVec2f::mapped( const ofVec2f& origin, - const ofVec2f& vx, - const ofVec2f& vy ) const{ +inline ofVec2f ofVec2f::mapped(const ofVec2f & origin, + const ofVec2f & vx, + const ofVec2f & vy) const { return getMapped(origin, vx, vy); } -inline ofVec2f ofVec2f::getMapped( const ofVec2f& origin, - const ofVec2f& vx, - const ofVec2f& vy ) const -{ - return ofVec2f( origin.x + x*vx.x + y*vy.x, - origin.y + x*vx.y + y*vy.y ); +inline ofVec2f ofVec2f::getMapped(const ofVec2f & origin, + const ofVec2f & vx, + const ofVec2f & vy) const { + return ofVec2f(origin.x + x * vx.x + y * vy.x, + origin.y + x * vx.y + y * vy.y); } -inline ofVec2f& ofVec2f::map( const ofVec2f& origin, - const ofVec2f& vx, const ofVec2f& vy ) -{ - float xmap = origin.x + x*vx.x + y*vy.x; - y = origin.y + x*vx.y + y*vy.y; +inline ofVec2f & ofVec2f::map(const ofVec2f & origin, + const ofVec2f & vx, const ofVec2f & vy) { + float xmap = origin.x + x * vx.x + y * vy.x; + y = origin.y + x * vx.y + y * vy.y; x = xmap; return *this; } - // Distance between two points. // // -inline float ofVec2f::distance( const ofVec2f& pnt) const { - float vx = x-pnt.x; - float vy = y-pnt.y; - return (float)sqrt(vx*vx + vy*vy); +inline float ofVec2f::distance(const ofVec2f & pnt) const { + float vx = x - pnt.x; + float vy = y - pnt.y; + return (float)sqrt(vx * vx + vy * vy); } //this method is deprecated in 006 please use squareDistance -inline float ofVec2f::distanceSquared( const ofVec2f& pnt ) const { +inline float ofVec2f::distanceSquared(const ofVec2f & pnt) const { return squareDistance(pnt); } -inline float ofVec2f::squareDistance( const ofVec2f& pnt ) const { - float vx = x-pnt.x; - float vy = y-pnt.y; - return vx*vx + vy*vy; +inline float ofVec2f::squareDistance(const ofVec2f & pnt) const { + float vx = x - pnt.x; + float vy = y - pnt.y; + return vx * vx + vy * vy; } - - // Linear interpolation. // // @@ -1341,46 +1330,42 @@ inline float ofVec2f::squareDistance( const ofVec2f& pnt ) const { // // this method is deprecated in 006 please use getInterpolated -inline ofVec2f ofVec2f::interpolated( const ofVec2f& pnt, float p ) const{ +inline ofVec2f ofVec2f::interpolated(const ofVec2f & pnt, float p) const { return getInterpolated(pnt, p); } -inline ofVec2f ofVec2f::getInterpolated( const ofVec2f& pnt, float p ) const { - return ofVec2f( x*(1-p) + pnt.x*p, y*(1-p) + pnt.y*p ); +inline ofVec2f ofVec2f::getInterpolated(const ofVec2f & pnt, float p) const { + return ofVec2f(x * (1 - p) + pnt.x * p, y * (1 - p) + pnt.y * p); } -inline ofVec2f& ofVec2f::interpolate( const ofVec2f& pnt, float p ) { - x = x*(1-p) + pnt.x*p; - y = y*(1-p) + pnt.y*p; +inline ofVec2f & ofVec2f::interpolate(const ofVec2f & pnt, float p) { + x = x * (1 - p) + pnt.x * p; + y = y * (1 - p) + pnt.y * p; return *this; } // this method is deprecated in 006 please use getMiddle -inline ofVec2f ofVec2f::middled( const ofVec2f& pnt ) const{ +inline ofVec2f ofVec2f::middled(const ofVec2f & pnt) const { return getMiddle(pnt); } -inline ofVec2f ofVec2f::getMiddle( const ofVec2f& pnt ) const { - return ofVec2f( (x+pnt.x)/2.0f, (y+pnt.y)/2.0f ); +inline ofVec2f ofVec2f::getMiddle(const ofVec2f & pnt) const { + return ofVec2f((x + pnt.x) / 2.0f, (y + pnt.y) / 2.0f); } -inline ofVec2f& ofVec2f::middle( const ofVec2f& pnt ) { - x = (x+pnt.x)/2.0f; - y = (y+pnt.y)/2.0f; +inline ofVec2f & ofVec2f::middle(const ofVec2f & pnt) { + x = (x + pnt.x) / 2.0f; + y = (y + pnt.y) / 2.0f; return *this; } - - - - -inline ofVec2f& ofVec2f::average( const ofVec2f* points, std::size_t num ) { +inline ofVec2f & ofVec2f::average(const ofVec2f * points, std::size_t num) { if (0 == num) { return *this; } x = 0.f; y = 0.f; - for( std::size_t i=0; i 0 ) { - return ofVec2f( x/length, y/length ); + float length = (float)sqrt(x * x + y * y); + if (length > 0) { + return ofVec2f(x / length, y / length); } else { return ofVec2f(); } } -inline ofVec2f& ofVec2f::normalize() { - float length = (float)sqrt(x*x + y*y); - if( length > 0 ) { +inline ofVec2f & ofVec2f::normalize() { + float length = (float)sqrt(x * x + y * y); + if (length > 0) { x /= length; y /= length; } return *this; } - - // Limit length. // // -inline ofVec2f ofVec2f::limited(float max) const{ +inline ofVec2f ofVec2f::limited(float max) const { return getLimited(max); } inline ofVec2f ofVec2f::getLimited(float max) const { - ofVec2f limited; - float lengthSquared = (x*x + y*y); - if( lengthSquared > max*max && lengthSquared > 0 ) { - float ratio = max/(float)sqrt(lengthSquared); - limited.set( x*ratio, y*ratio); - } else { - limited.set(x,y); - } - return limited; + ofVec2f limited; + float lengthSquared = (x * x + y * y); + if (lengthSquared > max * max && lengthSquared > 0) { + float ratio = max / (float)sqrt(lengthSquared); + limited.set(x * ratio, y * ratio); + } else { + limited.set(x, y); + } + return limited; } -inline ofVec2f& ofVec2f::limit(float max) { - float lengthSquared = (x*x + y*y); - if( lengthSquared > max*max && lengthSquared > 0 ) { - float ratio = max/(float)sqrt(lengthSquared); - x *= ratio; - y *= ratio; - } - return *this; +inline ofVec2f & ofVec2f::limit(float max) { + float lengthSquared = (x * x + y * y); + if (lengthSquared > max * max && lengthSquared > 0) { + float ratio = max / (float)sqrt(lengthSquared); + x *= ratio; + y *= ratio; + } + return *this; } - - // Perpendicular normalized vector. // // @@ -1457,73 +1436,63 @@ inline ofVec2f ofVec2f::perpendiculared() const { } inline ofVec2f ofVec2f::getPerpendicular() const { - float length = (float)sqrt( x*x + y*y ); - if( length > 0 ) - return ofVec2f( -(y/length), x/length ); + float length = (float)sqrt(x * x + y * y); + if (length > 0) + return ofVec2f(-(y / length), x / length); else return ofVec2f(); } -inline ofVec2f& ofVec2f::perpendicular() { - float length = (float)sqrt( x*x + y*y ); - if( length > 0 ) { +inline ofVec2f & ofVec2f::perpendicular() { + float length = (float)sqrt(x * x + y * y); + if (length > 0) { float _x = x; - x = -(y/length); - y = _x/length; + x = -(y / length); + y = _x / length; } return *this; } - // Length // // inline float ofVec2f::length() const { - return (float)sqrt( x*x + y*y ); + return (float)sqrt(x * x + y * y); } inline float ofVec2f::lengthSquared() const { - return (float)(x*x + y*y); + return (float)(x * x + y * y); } - -inline float ofVec2f::angle( const ofVec2f& vec ) const { - return ofRadToDeg(atan2( x*vec.y-y*vec.x, x*vec.x + y*vec.y )); +inline float ofVec2f::angle(const ofVec2f & vec) const { + return ofRadToDeg(atan2(x * vec.y - y * vec.x, x * vec.x + y * vec.y)); } -inline float ofVec2f::angleRad( const ofVec2f& vec ) const { - return atan2( x*vec.y-y*vec.x, x*vec.x + y*vec.y ); +inline float ofVec2f::angleRad(const ofVec2f & vec) const { + return atan2(x * vec.y - y * vec.x, x * vec.x + y * vec.y); } - -inline float ofVec2f::dot( const ofVec2f& vec ) const { - return x*vec.x + y*vec.y; +inline float ofVec2f::dot(const ofVec2f & vec) const { + return x * vec.x + y * vec.y; } - - - - - - // Non-Member operators // // -inline ofVec2f operator+( float f, const ofVec2f& vec ) { - return ofVec2f( f+vec.x, f+vec.y); +inline ofVec2f operator+(float f, const ofVec2f & vec) { + return ofVec2f(f + vec.x, f + vec.y); } -inline ofVec2f operator-( float f, const ofVec2f& vec ) { - return ofVec2f( f-vec.x, f-vec.y); +inline ofVec2f operator-(float f, const ofVec2f & vec) { + return ofVec2f(f - vec.x, f - vec.y); } -inline ofVec2f operator*( float f, const ofVec2f& vec ) { - return ofVec2f( f*vec.x, f*vec.y); +inline ofVec2f operator*(float f, const ofVec2f & vec) { + return ofVec2f(f * vec.x, f * vec.y); } -inline ofVec2f operator/( float f, const ofVec2f& vec ) { - return ofVec2f( f/vec.x, f/vec.y); +inline ofVec2f operator/(float f, const ofVec2f & vec) { + return ofVec2f(f / vec.x, f / vec.y); } - /// \endcond diff --git a/libs/openFrameworks/math/ofVec3f.h b/libs/openFrameworks/math/ofVec3f.h index 524f62157c0..50c9cd6ec96 100644 --- a/libs/openFrameworks/math/ofVec3f.h +++ b/libs/openFrameworks/math/ofVec3f.h @@ -1,75 +1,72 @@ #pragma once +#include "glm/vec3.hpp" #include "ofVec2f.h" #include "ofVec4f.h" -#include "ofMathConstants.h" -#include "ofConstants.h" -#include "glm/vec3.hpp" -#include #include /// \brief ofVec3f is a class for storing a three dimensional vector. -/// +/// /// Moving through space requires knowledge of where things are and where they are /// going. Vector Maths is the class of mathematics that gives us control over /// these things in space, allowing for elegant and intuitive descriptions of /// complex structures and movement. Vectors are at the heart of animations, /// particle systems, and 2D and 3D graphics. -/// +/// /// Vectors in mathematics in general are entities with magnitude (also called /// length) and direction. A vector whose magnitude is 1 (ie a vector that is /// *normalized*) is called a *unit vector*. Unit vectors are very handy for /// storing directions as they can be easily scaled up (or down) to represent /// motion in a particular direction with a particular length. -/// +/// /// *You will also see the term 'vector' used to describe an array of objects in /// C++ (such as text strings). Don't let this confuse you, they are quite /// different: one of them is a mathematical term for a fixed-length list of /// numbers that you can do mathematical operations on, the other is a /// C++-specific term that means 'dynamically sizeable array'.* -/// +/// /// 'ofVec3f has three member variables, x, y, and z, which allow to conveniently /// 'store 3D properties of an object such as its position, velocity, or /// 'acceleration. -/// +/// /// ~~~~{.cpp} /// ofVec3f v1; // v1.x is 0, v1.y is 0, v1.z is 0 /// v1.set(10, 50, 80); // now v1.x is 10, v1.y is 50, v1.z is 80 /// ~~~~ -/// +/// /// Using 'ofVec3f' greatly simplifies arithmetic operations in three dimensions. /// For example if you have two vectors 'v1' and 'v2', both of which represent a /// 3D change in position, you can find the total change of position of both of /// them just by doing an addition 'v1 + v2': -/// +/// /// ~~~~{.cpp} -/// ofVec3f v1(5, 2, 1); -/// // so now v1 represents walking 5 steps forward then 2 steps +/// ofVec3f v1(5, 2, 1); +/// // so now v1 represents walking 5 steps forward then 2 steps /// // sideways then 1 step upwards /// ofVec3f v2; -/// v2.set(1, 1, 1); -/// // so now v2 represents walking 1 step forward then 1 step +/// v2.set(1, 1, 1); +/// // so now v2 represents walking 1 step forward then 1 step /// // sideways then 1 step upwards -/// +/// /// // what happens if you do v1 followed by v2? /// // to find out just add v1 and v2 together: -/// ofVec3f result = v1 + v2; +/// ofVec3f result = v1 + v2; /// // result is (6, 3, 1), or 6 steps forward then 3 steps sideways /// // then 2 steps upwards /// ~~~~ -/// +/// /// You can scale an 'ofVec3f' by multiplying it with a float: -/// +/// /// ~~~~{.cpp} /// // walk 5 steps forward then 2 steps sideways then 1 step upwards -/// ofVec3f v1(5, 2, 1); +/// ofVec3f v1(5, 2, 1); /// // what happens if we do v1 three times? -/// ofVec3f result = v1 * 3; // result is (15, 6, 3), or +/// ofVec3f result = v1 * 3; // result is (15, 6, 3), or /// // 15 steps forward, 6 steps sideways and 3 steps upwards /// ~~~~ -/// +/// /// This also works for subtraction and division. -/// +/// /// As you can see this really makes dealing with vectors as easy as dealing with /// single 'float's or 'int's, and can reduce the number of lines of code you have /// to write by half, at the same time making your code much easier to read and @@ -78,57 +75,57 @@ /// \sa ofVec4f for 4D vectors class ofVec3f { public: - /// \cond INTERNAL + /// \cond INTERNAL static const int DIM = 3; /// \endcond - + /// \brief Stores the `X` component of this vector. float x; - + /// \brief Stores the `Y` component of this vector. float y; - + /// \brief Stores the `Z` component of this vector. float z; - + //--------------------- /// \name Construct a 3D vector /// \{ - + /// \brief Construct a 3D vector. Defaults to (0,0,0). - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1; + /// ofVec3f v1; /// // default: v1.x is 0, v1.y is 0, v1.z is 0 /// - /// ofVec3f v2 = ofVec3f(40, 20, 10); + /// ofVec3f v2 = ofVec3f(40, 20, 10); /// // v2.x is 40, v2.y is 20, v2.z is 10 /// - /// ofVec3f v3(0.1, 0.3, -1.5); + /// ofVec3f v3(0.1, 0.3, -1.5); /// // v3.x is 0.1, v3.y is 0.3, v3.z is -1.5 /// ~~~~ ofVec3f(); /// \brief Construt a 3D vector with `x`, `y` and `z` specified - ofVec3f( float x, float y, float z=0 ); - + ofVec3f(float x, float y, float z = 0); + /// \brief Construct a 3D vector with `x`, `y` and `z` set to `scalar` - explicit ofVec3f( float scalar ); - - ofVec3f( const ofVec2f& vec ); + explicit ofVec3f(float scalar); + + ofVec3f(const ofVec2f & vec); - /// \brief Construct a new 3D vector from a 4D vector by + /// \brief Construct a new 3D vector from a 4D vector by /// throwing away the 'w' component. - /// + /// /// ~~~~{.cpp} /// ofVec3f mom = ofVec4f(40, 20, 10, 100); /// ofVec3f v(mom); // v is (40, 20, 10) /// ~~~~ - ofVec3f( const ofVec4f& vec ); + ofVec3f(const ofVec4f & vec); - ofVec3f( const glm::vec2 & vec ); - ofVec3f( const glm::vec3 & vec ); - ofVec3f( const glm::vec4 & vec ); + ofVec3f(const glm::vec2 & vec); + ofVec3f(const glm::vec3 & vec); + ofVec3f(const glm::vec4 & vec); operator glm::vec3() const; /// \} @@ -137,10 +134,9 @@ class ofVec3f { /// \name Access components /// \{ - /// \brief Returns a pointer to the memory position of the first element of the vector /// ('x'); the other elements ('y' and 'z') immediately follow it in memory. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1 = ofVec3f(40, 20, 10); /// float * v1Ptr = v1.getPtr(); @@ -148,137 +144,121 @@ class ofVec3f { /// float y = *(v1Ptr+1); // y is 20 /// float z = *(v1Ptr+2); // z is 10 /// ~~~~ - /// + /// /// This is very useful when using arrays of 'ofVec3f's to store geometry /// information, as it allows the vector to be treated as a simple C array of /// 'float's that can be passed verbatim to OpenGL. - /// + /// float * getPtr() { - return (float*)&x; + return (float *)&x; } const float * getPtr() const { return (const float *)&x; } - /// \brief Allows to access the individual components of an 'ofVec3f' as though it is an /// array - /// + /// /// ~~~~{.cpp} /// ofVec3f v1 = ofVec3f(40, 20, 10); /// float x = v1[0]; // x is 40 /// float y = v1[1]; // y is 20 /// float z = v1[2]; // z is 10 /// ~~~~ - /// + /// /// This function can be handy if you want to do the same operation to all 'x', /// 'y' and 'z' components, as it means you can just make a 'for' loop that /// repeats 3 times. - float& operator[]( int n ){ + float & operator[](int n) { return getPtr()[n]; } - - float operator[]( int n ) const { + + float operator[](int n) const { return getPtr()[n]; } - - + /// \brief Set 'x', 'y' and 'z' components of this vector with just one function call. /// 'z' is optional, it defaults to 0. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1; /// v1.set(40, 20, 70); /// ~~~~ - void set( float x, float y, float z = 0 ); - + void set(float x, float y, float z = 0); /// \brief Setting the values by using other 3 dimension vector ofVec3f. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1; /// ofVec3f v2; /// v1.set(40, 20, 70); /// v2.set(v1); /// ~~~~ - void set( const ofVec3f& vec ); - void set( float _scalar ); + void set(const ofVec3f & vec); + void set(float _scalar); /// \} - //--------------------- - /// \name Comparison + //--------------------- + /// \name Comparison /// \{ - /// \brief Check for equality between two ofVec3f - /// + /// \brief Check for equality between two ofVec3f + /// /// Returns 'true' if each component is the same as the corresponding component in /// 'vec', ie if 'x == vec.x' and 'y == vec.y' and 'z == vec.z'; otherwise returns /// 'false'. But you should probably be using ['match'](#match) instead. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1(40, 20, 10); - /// ofVec3f v2(50, 30, 10); - /// ofVec3f v3(40, 20, 10); + /// ofVec3f v1(40, 20, 10); + /// ofVec3f v2(50, 30, 10); + /// ofVec3f v3(40, 20, 10); /// // ( v1 == v2 ) is false /// // ( v1 == v3 ) is true /// ~~~~ - bool operator==( const ofVec3f& vec ) const; - + bool operator==(const ofVec3f & vec) const; + /// \brief Returns 'true' if any component is different to its corresponding component in /// 'vec', ie if 'x != vec.x' or 'y != vec.y' or 'z != vec.z'; otherwise returns /// 'false'. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1(40, 20, 10); - /// ofVec3f v2(50, 20, 40); - /// ofVec3f v3(40, 20, 10); + /// ofVec3f v1(40, 20, 10); + /// ofVec3f v2(50, 20, 40); + /// ofVec3f v3(40, 20, 10); /// // ( v1 != v2 ) is true /// // ( v1 != v3 ) is false /// ~~~~ - bool operator!=( const ofVec3f& vec ) const; + bool operator!=(const ofVec3f & vec) const; /// \brief Let you check if two vectors are similar given a tolerance threshold - /// 'tolerance' (default = 0.0001). - /// + /// 'tolerance' (default = 0.0001). + /// /// ~~~~{.cpp} /// ofVec3f v1 = ofVec3f(40, 20, 70); /// ofVec3f v2 = ofVec3f(40.01, 19.999, 70.05); /// // v1.match(v2, 0.1) is true /// // v1.match(v2, 0.01) is false (because (70.5-70) > 0.01) /// ~~~~ - /// - bool match( const ofVec3f& vec, float tolerance = 0.0001f ) const; - /** - * Checks if vectors look in the same direction. - */ - bool isAligned( const ofVec3f& vec, float tolerance = 0.0001f ) const; - bool isAlignedRad( const ofVec3f& vec, float tolerance = 0.0001f ) const; - - /// \brief Returns 'true' if this vector is pointing in the same direction as - /// 'vec', with an angle error threshold 'tolerance' in degrees (default - /// 0.0001 degrees). - /// - /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 70); - /// ofVec3f v2 = ofVec3f(4, 2, 7); - /// // v1.align(v2, 0.0) is true - /// ~~~~ - bool align( const ofVec3f& vec, float tolerance = 0.0001f ) const; - - /// \brief Returns 'true' if this vector is pointing in the same direction - /// as 'vec', with an angle error threshold 'tolerance' in radians - /// (default 0.0001). - /// - /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 70); - /// ofVec3f v2 = ofVec3f(4, 2, 7); - /// // v1.align(v2, 0.0) is true - /// ~~~~ - bool alignRad( const ofVec3f& vec, float tolerance = 0.0001f ) const; - - - /// \} + /// + bool match(const ofVec3f & vec, float tolerance = 0.0001f) const; + + /// \brief Determine if two vectors are aligned + /// \param vec The vector to compare alignment with + /// \param tolerance an angle tolerance/threshold (specified in degrees) for deciding if the vectors are sufficiently aligned. + /// \returns true if both vectors are aligned (pointing in the same direction). + bool isAligned(const ofVec3f & vec, float tolerance = 0.0001f) const; + + /// \brief Determine if two vectors are aligned with tolerance in radians + /// \param vec The vector to compare alignment with + /// \param tolerance an angle tolerance/threshold (specified in radians) for deciding if the vectors are sufficiently aligned. + /// \sa isAligned() + bool isAlignedRad(const ofVec3f & vec, float tolerance = 0.0001f) const; + + [[deprecated("use isAligned")]] bool align(const ofVec3f & vec, float tolerance = 0.0001f) const; + [[deprecated("use isAlignedRad")]] bool alignRad(const ofVec3f & vec, float tolerance = 0.0001f) const; + + /// \} //--------------------- /// \name Operators @@ -286,202 +266,198 @@ class ofVec3f { /// Super easy vector addition. Returns a new vector /// ('x'+'vec.x','y'+'vec.y','z'+'vec.z'). - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(25, 50, 10); /// ofVec3f v3 = v1 + v2; // v3 is (65, 70, 20) /// ~~~~ - ofVec3f operator+( const ofVec3f& pnt ) const; + ofVec3f operator+(const ofVec3f & pnt) const; /// Returns a new vector with a float value 'f' added to 'x', 'y' and 'z' /// members. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// ofVec3f v2 = v1 + 10; // (12, 15, 11) /// ~~~~ - ofVec3f operator+( const float f ) const; - + ofVec3f operator+(const float f) const; + /// Super easy addition assignment. Adds 'vec.x' to 'x', adds 'vec.y' to 'y' and /// adds 'vec.z' to 'z'. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(25, 50, 10); /// v1 += v2; // v1 is (65, 70, 20) /// ~~~~ - ofVec3f& operator+=( const ofVec3f& pnt ); - + ofVec3f & operator+=(const ofVec3f & pnt); + /// Adds a float value 'f' to 'x', 'y' and 'z' members. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// v1 += 10; // (12, 15, 11) /// ~~~~ - ofVec3f& operator+=( const float f ); - + ofVec3f & operator+=(const float f); + /// Super easy vector subtraction. Returns a new vector - /// ('x'-'vec.x','y'-'vec.y','z'-'vec.z'). - /// + /// ('x'-'vec.x','y'-'vec.y','z'-'vec.z'). + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(25, 50, 10); /// ofVec3f v3 = v1 - v2; // v3 is (15, -30, 0) /// ~~~~ - ofVec3f operator-( const ofVec3f& vec ) const; - - + ofVec3f operator-(const ofVec3f & vec) const; /// Returns a new vector with a float value 'f' subtracted from 'x', 'y' and 'z' /// members. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// ofVec3f v2 = v1 - 10; // (-8, -5, -9) /// ~~~~ - ofVec3f operator-( const float f ) const; + ofVec3f operator-(const float f) const; /// Returns a new 'ofVec3f' that is the inverted version (mirrored in X, Y and Z) /// of this vector. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// ofVec3f v2 = -v1; // (-2, -5, -1) /// ~~~~ - /// - ofVec3f operator-() const; + /// + ofVec3f operator-() const; /// Super easy subtraction assignment. Subtracts 'vec.x' from 'x', subtracts /// 'vec.y' from 'y' and subtracts 'vec.z' from 'z'. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(25, 50, 10); /// v1 -= v2; // v1 is (15, -30, 0) - /// ~~~~ - ofVec3f& operator-=( const ofVec3f& vec ); + /// ~~~~ + ofVec3f & operator-=(const ofVec3f & vec); /// Subtract a float value 'f' from 'x', 'y', and 'z' members. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// v1 -= 10; // (-8, -5, -9) /// ~~~~ - ofVec3f& operator-=( const float f ); + ofVec3f & operator-=(const float f); /// Returns a new vector ('x'*'vec.x','y'*'vec.y','z'*'vec.z'). - /// + /// /// ~~~~{.cpp} /// ofVec3f v1 = ofVec3f(40, 20, 10); inline /// ofVec3f v2 = ofVec3f(2, 4, 10); /// ofVec3f v3 = v1 * v2; // (80, 80, 100) /// ~~~~ - /// + /// /// Useful for scaling a 3D point by a non-uniform scale. - /// - ofVec3f operator*( const ofVec3f& vec ) const; + /// + ofVec3f operator*(const ofVec3f & vec) const; /// Return a new 'ofVec3f' that is this vector scaled by multiplying 'x', 'y', 'z' /// members by 'f'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// ofVec3f v2 = v1 * 4; // (8, 20, 4) /// ~~~~ - ofVec3f operator*( const float f ) const; - + ofVec3f operator*(const float f) const; + /// Multiplies 'x' by 'vec.x', and multiplies 'y' by 'vec.y', and multiplies 'z' /// by 'vec.z'. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(2, 4, 10); /// v1 *= v2; // v1 is now (80, 80, 100) /// ~~~~ - /// + /// /// Useful for scaling a 3D point by a non-uniform scale. - ofVec3f& operator*=( const ofVec3f& vec ); + ofVec3f & operator*=(const ofVec3f & vec); /// Scale this vector by multiplying 'x', 'y' and 'z' members by 'f'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// v1 *= 4; // (8, 20, 4) /// ~~~~ - ofVec3f& operator*=( const float f ); - + ofVec3f & operator*=(const float f); + /// Returns a new vector ('x'/'vec.x','y'/'vec.y','z'/'vec.z'). - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(2, 4, 10); /// ofVec3f v3 = v1 / v2; // (20, 5, 1) /// ~~~~ - /// + /// /// Useful for scaling a 3D point by a non-uniform scale. - ofVec3f operator/( const ofVec3f& vec ) const; - + ofVec3f operator/(const ofVec3f & vec) const; + /// Return a new 'ofVec3f' that is this vector scaled by dividing 'x', 'y' /// and 'z' members by 'f'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// ofVec3f v2 = v1 / 4; // (0.5, 1.25, 0.25) /// ~~~~ - ofVec3f operator/( const float f ) const; - + ofVec3f operator/(const float f) const; + /// Divides 'x' by 'vec.x', divides 'y' by 'vec.y', and divides 'z' by 'vec.z'. - /// + /// /// ~~~~{.cpp} - /// ofVec3f v1 = ofVec3f(40, 20, 10); + /// ofVec3f v1 = ofVec3f(40, 20, 10); /// ofVec3f v2 = ofVec3f(2, 4, 10); /// v1 *= v2; // v1 is now (20, 5, 1) /// ~~~~ - /// + /// /// Useful for scaling a 3D point by a non-uniform scale. - ofVec3f& operator/=( const ofVec3f& vec ); + ofVec3f & operator/=(const ofVec3f & vec); /// Scale this vector by dividing 'x', 'y' and 'z' members by 'f'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(2, 5, 1); /// v1 /= 4; // (0.5, 1.25, 0.25) /// ~~~~ - ofVec3f& operator/=( const float f ); - - /// \cond INTERNAL - friend std::ostream& operator<<(std::ostream& os, const ofVec3f& vec); - friend std::istream& operator>>(std::istream& is, ofVec3f& vec); + ofVec3f & operator/=(const float f); + + /// \cond INTERNAL + friend std::ostream & operator<<(std::ostream & os, const ofVec3f & vec); + friend std::istream & operator>>(std::istream & is, ofVec3f & vec); /// \endcond - /// \} - + /// \} + //--------------------- /// \name Simple manipulations /// \{ /// \brief Return a new 'ofVec3f' that is the result of scaling this vector up or down so that it has - /// the requested length. - /// + /// the requested length. + /// /// ~~~~{.cpp} /// ofVec3f v1(3, 4); // length is 5 /// ofVec3f v2 = v1.getScaled(15); // v2 is (9, 12), which has length of 15 /// ~~~~ - /// - ofVec3f getScaled( const float length ) const; - + /// + ofVec3f getScaled(const float length) const; /// \brief Scales this vector up or down so that it has the requested length. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(3, 4); // length is 5 /// v1.scale(15); // v1 is now (9, 12), which has length of 15 /// ~~~~ - ofVec3f& scale( const float length ); - - + ofVec3f & scale(const float length); + /// \brief Returns a new vector that is the result of rotating this vector /// by 'angle' degrees about the given axis. /// @@ -491,7 +467,7 @@ class ofVec3f { /// ofVec3f v3 = v1.getRotated(45, ofVec3f(0, 1, 0)); // v3 is (0.707, 0, -0.707) /// ~~~~ /// - ofVec3f getRotated( float angle, const ofVec3f& axis ) const; + ofVec3f getRotated(float angle, const ofVec3f & axis) const; /// \brief Returns a new vector that is the result of performing an Euler /// rotation of this vector by 'ax' degrees about the x axis, 'ay' degrees @@ -505,13 +481,12 @@ class ofVec3f { /// /// Watch out for gimbal lock when specifying multiple rotations in the same call. /// - ofVec3f getRotated(float ax, float ay, float az) const; + ofVec3f getRotated(float ax, float ay, float az) const; /// \brief Returns a new vector that is the result of rotating this vector by /// 'angle' degrees about the axis specified by 'axis', using 'pivot' as the /// origin of rotation. - ofVec3f getRotated( float angle, const ofVec3f& pivot, const ofVec3f& axis ) const; - + ofVec3f getRotated(float angle, const ofVec3f & pivot, const ofVec3f & axis) const; /// \brief Returns a new vector that is the result of rotating this vector by /// 'angle' radians about the given axis. @@ -521,7 +496,7 @@ class ofVec3f { /// ofVec3f v2 = v1.getRotated(PI / 4, ofVec3f(0, 0, 1)); // v2 is (0.707, 0.707, 0) /// ofVec3f v3 = v1.getRotated(PI / 4, ofVec3f(0, 1, 0)); // v3 is (0.707, 0, -0.707) /// ~~~~ - ofVec3f getRotatedRad( float angle, const ofVec3f& axis ) const; + ofVec3f getRotatedRad(float angle, const ofVec3f & axis) const; /// \brief Returns a new vector that is the result of performing an Euler /// rotation of this vector by 'ax' radians about the x axis, 'ay' radians @@ -535,12 +510,12 @@ class ofVec3f { /// /// Watch out for gimbal lock when specifying multiple rotations in the same call. /// - ofVec3f getRotatedRad(float ax, float ay, float az) const; + ofVec3f getRotatedRad(float ax, float ay, float az) const; /// \brief Returns a new vector that is the result of rotating this vector by /// 'angle' radians about the axis specified by 'axis', using 'pivot' as the /// origin of rotation. - ofVec3f getRotatedRad( float angle, const ofVec3f& pivot, const ofVec3f& axis ) const; + ofVec3f getRotatedRad(float angle, const ofVec3f & pivot, const ofVec3f & axis) const; /// \brief Rotates this vector by 'angle' degrees around the given axis. /// @@ -550,7 +525,7 @@ class ofVec3f { /// v1.rotate(45, ofVec3f(0, 0, 1)); // v1 is now (0.707, 0.707, 0) /// v2.rotate(45, ofVec3f(0, 1, 0)); // v2 is now (0.707, 0, -0.707) /// ~~~~ - ofVec3f& rotate( float angle, const ofVec3f& axis ); + ofVec3f & rotate(float angle, const ofVec3f & axis); /// \brief Performs an Euler rotation of this vector by 'ax' degrees about the /// x axis, 'ay' degrees about the y axis, and 'az' degrees about the z axis. @@ -564,12 +539,11 @@ class ofVec3f { /// /// Watch out for gimbal lock when specifying multiple rotations in the same call. /// - ofVec3f& rotate(float ax, float ay, float az); + ofVec3f & rotate(float ax, float ay, float az); /// \brief Rotates this vector by 'angle' degrees about the axis specified by 'axis', /// using 'pivot' as the origin of rotation. - ofVec3f& rotate( float angle, const ofVec3f& pivot, const ofVec3f& axis ); - + ofVec3f & rotate(float angle, const ofVec3f & pivot, const ofVec3f & axis); /// \brief Rotates this vector by 'angle' radians about the given axis. /// @@ -579,7 +553,7 @@ class ofVec3f { /// v1.rotateRad(PI / 4, ofVec3f(0, 0, 1)); // v1 is now (0.707, 0.707, 0) /// v2.rotateRad(PI / 4, ofVec3f(0, 1, 0)); // v2 is now (0.707, 0, -0.707) /// ~~~~ - ofVec3f& rotateRad( float angle, const ofVec3f& axis ); + ofVec3f & rotateRad(float angle, const ofVec3f & axis); /// \brief Performs an Euler rotation of this vector by 'ax' radians about /// the x axis, 'ay' radians about the y axis, and 'az' radians about the z axis. @@ -592,30 +566,27 @@ class ofVec3f { /// ~~~~~ /// /// Watch out for gimbal lock when specifying multiple rotations in the same call. - ofVec3f& rotateRad(float ax, float ay, float az); + ofVec3f & rotateRad(float ax, float ay, float az); /// \brief Rotates this vector by 'angle' radians around the axis specified by 'axis', /// using 'pivot' as the origin of rotation. - ofVec3f& rotateRad( float angle, const ofVec3f& pivot, const ofVec3f& axis ); - + ofVec3f & rotateRad(float angle, const ofVec3f & pivot, const ofVec3f & axis); - - /// \brief Return a new 'ofVec3f' calculated by copying this vector and then mapping from /// its default coordinate system -- origin (0,0,0), X direction (1,0,0), Y /// direction (0,1,0), Z direction (0,0,1) -- to a new coordinate system defined /// with origin at 'origin', X direction 'vx', and Y direction 'vy', and Z /// direction 'vz'. - /// + /// /// *In most cases you want 'vx', 'vy', and 'vz' to be perpendicular and of unit /// length; if they are not perpendicular you will have shearing as part of the /// mapping, and if they are not of unit length you will have scaling as part of /// the mapping.* - /// - ofVec3f getMapped( const ofVec3f& origin, - const ofVec3f& vx, - const ofVec3f& vy, - const ofVec3f& vz ) const; + /// + ofVec3f getMapped(const ofVec3f & origin, + const ofVec3f & vx, + const ofVec3f & vy, + const ofVec3f & vz) const; /// \brief Map this vector from its default coordinate system -- origin (0,0,0), X /// direction (1,0,0), Y direction (0,1,0), Z direction (0,0,1) -- to a new @@ -626,58 +597,53 @@ class ofVec3f { /// unit length; if they are not perpendicular you will have shearing as part /// of the mapping, and if they are not of unit length you will have scaling /// as part of the mapping.* - /// - ofVec3f& map( const ofVec3f& origin, - const ofVec3f& vx, - const ofVec3f& vy, - const ofVec3f& vz ); - - + /// + ofVec3f & map(const ofVec3f & origin, + const ofVec3f & vx, + const ofVec3f & vy, + const ofVec3f & vz); + + /// \} - /// \} - - //--------------------- /// \name Distance /// \{ - /// \brief Treats both this vector and 'pnt' as points in 3D space, and - /// calculates and returns the distance between them. - /// + /// calculates and returns the distance between them. + /// /// ~~~~{.cpp} /// ofVec3f p1(3, 4, 2); /// ofVec3f p2(6, 8, 5); /// float distance = p1.distance( p2 ); // distance is 5.8310 /// ~~~~ - /// + /// /// 'distance' involves a square root calculation, which is one of the /// slowest things you can do in programming. If you don't need an exact /// number but rather just a rough idea of distance (for example when /// finding the shortest distance of a bunch of points to a reference /// point, where it doesn't matter exactly what the distances are, you /// just want the shortest), you can use squareDistance() instead. - float distance( const ofVec3f& pnt) const; - + float distance(const ofVec3f & pnt) const; + /// \brief Treats both this vector and 'pnt' as points in 3D space, and calculates and /// returns the squared distance between them. - /// + /// /// ~~~~{.cpp} /// ofVec3f p1(3, 4, 2); /// ofVec3f p2(6, 8, 5); /// float distance = p1.distance( p2 ); // distance is 5.8310 /// ~~~~ - /// + /// /// Use as a much faster alternative to distance() if you don't need /// to know an exact number but rather just a rough idea of distance (for example /// when finding the shortest distance of a bunch of points to a reference point, /// where it doesn't matter exactly what the distances are, you just want the /// shortest). It avoids the square root calculation that is ordinarily required /// to calculate a length. - /// - float squareDistance( const ofVec3f& pnt ) const; - - + /// + float squareDistance(const ofVec3f & pnt) const; + /// \} //--------------------- @@ -689,24 +655,24 @@ class ofVec3f { /// controls the amount to move towards 'pnt'. 'p' is normally between 0 /// and 1 and where 0 means stay the original position and 1 means move /// all the way to 'pnt', but you can also have 'p' greater than 1 - /// overshoot 'pnt', or less than 0 to move backwards away from 'pnt'. - /// + /// overshoot 'pnt', or less than 0 to move backwards away from 'pnt'. + /// /// ~~~~{.cpp} /// ofVec3f v1(0, 5, 0); /// ofVec3f v2(10, 10, 20); /// ofVec3f v3 = v1.getInterpolated(p2, 0.5); // v3 is (5, 7.5, 10) /// ofVec3f v4 = v1.getInterpolated(p2, 0.8); // v4 is (8, 9, 16) /// ~~~~ - /// - ofVec3f getInterpolated( const ofVec3f& pnt, float p ) const; + /// + ofVec3f getInterpolated(const ofVec3f & pnt, float p) const; /// \brief Perform a linear interpolation of this vector's position towards /// 'pnt'. 'p' controls the amount to move towards 'pnt'. 'p' is normally /// between 0 and 1 and where 0 means stay the original position and 1 /// means move all the way to 'pnt', but you can also have 'p' greater /// than 1 overshoot 'pnt', or less than 0 to move backwards away from - /// 'pnt'. - /// + /// 'pnt'. + /// /// ~~~~{.cpp} /// ofVec3f v1( 0, 5, 0 ); /// ofVec3f v2( 10, 10, 20 ); @@ -716,19 +682,19 @@ class ofVec3f { /// v1.interpolate( v2, 0.5 ); // v1 is now (8.75, 9.375, 17.5) /// v1.interpolate( v2, 0.5 ); // v1 is now (9.375, 9.6875, 18.75) /// ~~~~ - ofVec3f& interpolate( const ofVec3f& pnt, float p ); - + ofVec3f & interpolate(const ofVec3f & pnt, float p); + /// \brief Calculate and return the midpoint between this vector and 'pnt'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(5, 0, 0); /// ofVec3f v2(10, 10, 20); /// ofVec3f mid = v1.getMiddle(v2); // mid gets (7.5, 5, 10) /// ~~~~ - ofVec3f getMiddle( const ofVec3f& pnt ) const; + ofVec3f getMiddle(const ofVec3f & pnt) const; /// Set this vector to the midpoint between itself and 'pnt'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1( 0, 5, 0 ); /// ofVec3f v2( 10, 10, 20); @@ -738,12 +704,12 @@ class ofVec3f { /// v1.middle( v2 ); // v1 is now (8.75, 9.375, 17.5) /// v1.middle( v2 ); // v1 is now (9.375, 9.6875, 18.75) /// ~~~~ - ofVec3f& middle( const ofVec3f& pnt ); - + ofVec3f & middle(const ofVec3f & pnt); + /// \brief Sets this vector to be the average (*centre of gravity* or /// *centroid*) of a given array of 'ofVec3f's. 'points' is the array of - /// 'ofVec3f's and 'num' specifies the number of 'ofVec3f's in the array. - /// + /// 'ofVec3f's and 'num' specifies the number of 'ofVec3f's in the array. + /// /// ~~~~{.cpp} /// int numPoints = 10; /// ofVec3f points[numPoints]; @@ -751,135 +717,131 @@ class ofVec3f { /// points[i].set( ofRandom(0,100), ofRandom(0,100), ofRandom(0,100) ); /// } /// ofVec3f centroid; - /// centroid.average( points, numPoints ); + /// centroid.average( points, numPoints ); /// // centroid now is the centre of gravity/average of all the random points /// ~~~~ - ofVec3f& average( const ofVec3f* points, int num ); - - /// \} + ofVec3f & average(const ofVec3f * points, int num); - //--------------------- + /// \} + + //--------------------- /// \name Limit /// \{ - - /// \brief Return a normalized copy of this vector. - /// + + /// \brief Return a normalized copy of this vector. + /// /// *Normalization* means to scale the vector so that its length /// (magnitude) is exactly 1, at which stage all that is left is the /// direction. A normalized vector is usually called a *unit vector*, and - /// can be used to represent a pure direction (heading). - /// + /// can be used to represent a pure direction (heading). + /// /// ~~~~{.cpp} /// ofVec3f v1(5, 0, 0); /// ofVec3f v1Normalized = v1.getNormalized(); // (1, 0, 0) /// ofVec3f v2(5, 0, 5); /// ofVec3f v2Normalized = v2.getNormalized(); // (√2, 0, √2) /// ~~~~ - ofVec3f getNormalized() const; - + ofVec3f getNormalized() const; + /// \brief Normalize the vector. - /// + /// /// *Normalizing* means to scale the vector so that its length (magnitude) /// is exactly 1, at which stage all that is left is the direction. A /// normalized vector is usually called a *unit vector*, and can be used - /// to represent a pure direction (heading). - /// + /// to represent a pure direction (heading). + /// /// ~~~~{.cpp} /// ofVec3f v1(5, 0, 0); /// v1.normalize(); // v2 is now (1, 0, 0) /// ofVec3f v2(5, 0, 5); /// v2.normalize(); // v2 is now (√2, 0, √2) /// ~~~~ - /// - ofVec3f& normalize(); - - + /// + ofVec3f & normalize(); + /// \brief Return a copy of this vector with its length (magnitude) restricted to a /// maximum of 'max' units by scaling down if necessary. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(5, 0, 1); // length is about 5.1 /// ofVec3f v2(2, 0, 1); // length is about 2.2 - /// ofVec3f v1Limited = v1.getLimited(3); + /// ofVec3f v1Limited = v1.getLimited(3); /// // v1Limited is (2.9417, 0, 0.58835) which has length of 3 in the same direction as v1 /// ofVec3f v2Limited = v2.getLimited(3); /// // v2Limited is (2, 0, 1) (same as v2) /// ~~~~ - ofVec3f getLimited(float max) const; + ofVec3f getLimited(float max) const; /// \brief Restrict the length (magnitude) of this vector to a maximum of 'max' - /// units by scaling down if necessary. - /// + /// units by scaling down if necessary. + /// /// ~~~~{.cpp} /// ofVec3f v1(5, 0, 1); // length is about 5.1 /// ofVec3f v2(2, 0, 1); // length is about 2.2 - /// v1.limit(3); + /// v1.limit(3); /// // v1 is now (2.9417, 0, 0.58835) which has length of 3 in the same direction as at initialization /// v2.limit(3); /// // v2 is unchanged /// ~~~~ - ofVec3f& limit(float max); + ofVec3f & limit(float max); - /// \} //--------------------- /// \name Measurement /// \{ - /// Return the length (magnitude) of this vector. - /// + /// /// ~~~~{.cpp} /// ofVec3f v(3, 4, 1); /// float len = v.length(); // len is 5.0990 /// ~~~~ - /// + /// /// `length' involves a square root calculation, which is one of the /// slowest things you can do in programming. If you don't need an exact /// number but rather just a rough idea of a length (for example when /// finding the shortest distance of a bunch of points to a reference /// point, where it doesn't matter exactly what the lengths are, you just /// want the shortest), you can use lengthSquared() instead. - /// - float length() const; + /// + float length() const; - /// \brief Return the squared length (squared magnitude) of this vector. - /// + /// \brief Return the squared length (squared magnitude) of this vector. + /// /// ~~~~{.cpp} /// ofVec3f v(3, 4, 1); /// float len = v.length(); // len is 5.0990 /// ~~~~ - /// + /// /// Use as a much faster alternative to length() if you don't need /// to know an accurate length but rather just a rough idea of a length (for /// example when finding the shortest distance of a bunch of points to a /// reference point, where it doesn't matter exactly what the lengths are, you /// just want the shortest). It avoids the square root calculation that is /// ordinarily required to calculate a length. - float lengthSquared() const; + float lengthSquared() const; /// \brief Calculate and return the coplanar angle in degrees between this vector /// and 'vec'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(1,0,0); /// ofVec3f v2(0,1,0); /// float angle = v1.angle(v2); // angle is 90 - /// ~~~~ - float angle( const ofVec3f& vec ) const; - - /// \brief Calculate and return the coplanar angle in radians between this + /// ~~~~ + float angle(const ofVec3f & vec) const; + + /// \brief Calculate and return the coplanar angle in radians between this /// vector and 'vec'. - /// + /// /// ~~~~{.cpp} /// ofVec3f v1(1,0,0); /// ofVec3f v2(0,1,0); /// float angle = v1.angle(v2); // angle is 90 /// ~~~~ - /// - float angleRad( const ofVec3f& vec ) const; - + /// + float angleRad(const ofVec3f & vec) const; /// \} @@ -887,11 +849,10 @@ class ofVec3f { /// \name Perpendicular /// \{ - /// \brief Construct a plane using this vector and 'vec' (by finding the plane that both /// lectors lie on), and return the vector that is perpendicular to that plane /// (the normal to that plane). - /// + /// /// ~~~~{.cpp} /// ofSetLogLevel(OF_LOG_NOTICE); /// ofVec3f v1(1,0,0); @@ -900,32 +861,29 @@ class ofVec3f { /// ofLog(OF_LOG_NOTICE, "%1.1f, %1.1f, %1.1f\n", p.x, p.y, p.z); /// // prints "0.0, 0.0, 1.0" /// ~~~~ - /// + /// /// This method is usually used to calculate a normal vector to a surface, which /// can then be used to calculate lighting, collisions, and other 3D effects. - /// - ofVec3f getPerpendicular( const ofVec3f& vec ) const; - + /// + ofVec3f getPerpendicular(const ofVec3f & vec) const; /// \brief Construct a plane using this vector and 'vec' (by finding the plane that both /// lie on), and set our 'x', 'y' and 'z' to be the vector that is perpendicular /// to the constructed plane (the normal to the plane). - /// + /// /// ~~~~{.cpp} /// ofSetLogLevel(OF_LOG_NOTICE); /// ofVec3f v1(1,0,0); - /// ofVec3f v2(0,1,0); - /// v1.perpendicular(v2); + /// ofVec3f v2(0,1,0); + /// v1.perpendicular(v2); /// ofLog(OF_LOG_NOTICE, "%1.1f, %1.1f, %1.1f\n", v1.x, v1.y, v1.z); /// // prints "0.0, 0.0, 1.0' /// ~~~~ - /// + /// /// This method is usually used to calculate a normal vector to a surface, which /// can then be used to calculate lighting, collisions, and other 3D effects. - /// - ofVec3f& perpendicular( const ofVec3f& vec ); - - + /// + ofVec3f & perpendicular(const ofVec3f & vec); /// \brief Returns the cross product (vector product) of this vector and 'vec'. This is a /// binary operation on two vectors in three-dimensional space, which results in a @@ -934,11 +892,11 @@ class ofVec3f { /// the cross symbol X that is often used to designate this operation; the /// alternative name *vector product* emphasizes the vector (rather than scalar) /// nature of the result. - /// + /// /// ![CROSS](math/crossproduct.png) /// Image courtesy of Wikipedia - ofVec3f getCrossed( const ofVec3f& vec ) const; - + ofVec3f getCrossed(const ofVec3f & vec) const; + /// Set this vector to the cross product (vector product) of itself and /// 'vec'. This is a binary operation on two vectors in three-dimensional /// space, which results in a vector that is perpendicular to both of the @@ -947,11 +905,8 @@ class ofVec3f { /// used to designate this operation; the alternative name *vector /// product* emphasizes the vector (rather than scalar) nature of the /// result. - ofVec3f& cross( const ofVec3f& vec ); + ofVec3f & cross(const ofVec3f & vec); - - - /// \brief Returns the dot product of this vector with 'vec'. /// /// The *dot product* of two vectors, also known as the *scalar product*, is @@ -981,15 +936,13 @@ class ofVec3f { /// ofVec3f b3(0, -1, 0); // magnitude 1, 180 degree angle to a3 /// dot = a3.dot(b3); // dot is 1 * 1 * cos(180) = -1.0 /// ~~~~ - /// - float dot( const ofVec3f& vec ) const; - - /// \} + /// + float dot(const ofVec3f & vec) const; + /// \} - - //----------------------------------------------- - // this methods are deprecated in 006 please use: + //----------------------------------------------- + // this methods are deprecated in 006 please use: /// \cond INTERNAL [[deprecated("Use member method getScaled()")]] @@ -1044,110 +997,170 @@ class ofVec3f { /// \endcond -}; + // scale + OF_DEPRECATED_MSG("Use member method scale() instead.", ofVec3f & rescale(const float length)); + // getRotated + OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec3f rotated(float angle, const ofVec3f & axis) const); -/// \cond INTERNAL + // getRotated should this be const??? + OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec3f rotated(float ax, float ay, float az)); + + // getNormalized + OF_DEPRECATED_MSG("Use member method getNormalized() instead.", ofVec3f normalized() const); + + // getLimited + OF_DEPRECATED_MSG("Use member method getLimited() instead.", ofVec3f limited(float max) const); + + // getCrossed + OF_DEPRECATED_MSG("Use member method getCrossed() instead.", ofVec3f crossed(const ofVec3f & vec) const); + + // getPerpendicular + OF_DEPRECATED_MSG("Use member method getPerpendicular() instead.", ofVec3f perpendiculared(const ofVec3f & vec) const); + + // use getMapped + OF_DEPRECATED_MSG("Use member method getMapped() instead.", ofVec3f mapped(const ofVec3f & origin, const ofVec3f & vx, const ofVec3f & vy, const ofVec3f & vz) const); + + // use squareDistance + OF_DEPRECATED_MSG("Use member method squareDistance() instead.", float distanceSquared(const ofVec3f & pnt) const); + + // use getInterpolated + OF_DEPRECATED_MSG("Use member method getInterpolated() instead.", ofVec3f interpolated(const ofVec3f & pnt, float p) const); + // use getMiddle + OF_DEPRECATED_MSG("Use member method getMiddle() instead.", ofVec3f middled(const ofVec3f & pnt) const); + + // use getRotated + OF_DEPRECATED_MSG("Use member method getRotated() instead.", ofVec3f rotated(float angle, const ofVec3f & pivot, const ofVec3f & axis) const); + + // return all zero vector + static ofVec3f zero() { return ofVec3f(0, 0, 0); } + + // return all one vector + static ofVec3f one() { return ofVec3f(1, 1, 1); } + + /// \endcond +}; + +/// \cond INTERNAL // Non-Member operators // // -ofVec3f operator+( float f, const ofVec3f& vec ); -ofVec3f operator-( float f, const ofVec3f& vec ); -ofVec3f operator*( float f, const ofVec3f& vec ); -ofVec3f operator/( float f, const ofVec3f& vec ); - +ofVec3f operator+(float f, const ofVec3f & vec); +ofVec3f operator-(float f, const ofVec3f & vec); +ofVec3f operator*(float f, const ofVec3f & vec); +ofVec3f operator/(float f, const ofVec3f & vec); ///////////////// // Implementation ///////////////// - -inline ofVec3f::ofVec3f( const ofVec2f& vec ):x(vec.x), y(vec.y), z(0) {} -inline ofVec3f::ofVec3f( const ofVec4f& vec ):x(vec.x), y(vec.y), z(vec.z) {} -inline ofVec3f::ofVec3f(): x(0), y(0), z(0) {} -inline ofVec3f::ofVec3f( float _all ): x(_all), y(_all), z(_all) {} -inline ofVec3f::ofVec3f( float _x, float _y, float _z ):x(_x), y(_y), z(_z) {} - -inline ofVec3f::ofVec3f( const glm::vec2 & vec ):x(vec.x), y(vec.y), z(0.f){} -inline ofVec3f::ofVec3f( const glm::vec3 & vec ):x(vec.x), y(vec.y), z(vec.z){} -inline ofVec3f::ofVec3f( const glm::vec4 & vec ):x(vec.x), y(vec.y), z(vec.z){} - -inline ofVec3f::operator glm::vec3() const{ - return glm::vec3(x,y,z); +inline ofVec3f::ofVec3f(const ofVec2f & vec) + : x(vec.x) + , y(vec.y) + , z(0) { } +inline ofVec3f::ofVec3f(const ofVec4f & vec) + : x(vec.x) + , y(vec.y) + , z(vec.z) { } +inline ofVec3f::ofVec3f() + : x(0) + , y(0) + , z(0) { } +inline ofVec3f::ofVec3f(float _all) + : x(_all) + , y(_all) + , z(_all) { } +inline ofVec3f::ofVec3f(float _x, float _y, float _z) + : x(_x) + , y(_y) + , z(_z) { } + +inline ofVec3f::ofVec3f(const glm::vec2 & vec) + : x(vec.x) + , y(vec.y) + , z(0.f) { } +inline ofVec3f::ofVec3f(const glm::vec3 & vec) + : x(vec.x) + , y(vec.y) + , z(vec.z) { } +inline ofVec3f::ofVec3f(const glm::vec4 & vec) + : x(vec.x) + , y(vec.y) + , z(vec.z) { } + +inline ofVec3f::operator glm::vec3() const { + return glm::vec3(x, y, z); } - // Getters and Setters. // // -inline void ofVec3f::set( float _scalar ) { +inline void ofVec3f::set(float _scalar) { x = _scalar; y = _scalar; z = _scalar; } -inline void ofVec3f::set( float _x, float _y, float _z ) { +inline void ofVec3f::set(float _x, float _y, float _z) { x = _x; y = _y; z = _z; } -inline void ofVec3f::set( const ofVec3f& vec ) { +inline void ofVec3f::set(const ofVec3f & vec) { x = vec.x; y = vec.y; z = vec.z; } - // Check similarity/equality. // // -inline bool ofVec3f::operator==( const ofVec3f& vec ) const { +inline bool ofVec3f::operator==(const ofVec3f & vec) const { return (x == vec.x) && (y == vec.y) && (z == vec.z); } -inline bool ofVec3f::operator!=( const ofVec3f& vec ) const { +inline bool ofVec3f::operator!=(const ofVec3f & vec) const { return (x != vec.x) || (y != vec.y) || (z != vec.z); } -inline bool ofVec3f::match( const ofVec3f& vec, float tolerance ) const{ +inline bool ofVec3f::match(const ofVec3f & vec, float tolerance) const { return (fabs(x - vec.x) < tolerance) - && (fabs(y - vec.y) < tolerance) - && (fabs(z - vec.z) < tolerance); + && (fabs(y - vec.y) < tolerance) + && (fabs(z - vec.z) < tolerance); } /** * Checks if vectors look in the same direction. */ -inline bool ofVec3f::isAligned( const ofVec3f& vec, float tolerance ) const { - float angle = this->angle( vec ); - return angle < tolerance; +inline bool ofVec3f::isAligned(const ofVec3f & vec, float tolerance) const { + float angle = this->angle(vec); + return angle < tolerance; } -inline bool ofVec3f::align( const ofVec3f& vec, float tolerance ) const { - return isAligned( vec, tolerance ); +inline bool ofVec3f::align(const ofVec3f & vec, float tolerance) const { + return isAligned(vec, tolerance); } -inline bool ofVec3f::isAlignedRad( const ofVec3f& vec, float tolerance ) const { - float angle = this->angleRad( vec ); - return angle < tolerance; +inline bool ofVec3f::isAlignedRad(const ofVec3f & vec, float tolerance) const { + float angle = this->angleRad(vec); + return angle < tolerance; } -inline bool ofVec3f::alignRad( const ofVec3f& vec, float tolerance ) const { - return isAlignedRad( vec, tolerance ); +inline bool ofVec3f::alignRad(const ofVec3f & vec, float tolerance) const { + return isAlignedRad(vec, tolerance); } - // Operator overloading for ofVec3f // // -inline std::ostream& operator<<(std::ostream& os, const ofVec3f& vec) { +inline std::ostream & operator<<(std::ostream & os, const ofVec3f & vec) { os << vec.x << ", " << vec.y << ", " << vec.z; return os; } -inline std::istream& operator>>(std::istream& is, ofVec3f& vec) { +inline std::istream & operator>>(std::istream & is, ofVec3f & vec) { is >> vec.x; is.ignore(2); is >> vec.y; @@ -1156,55 +1169,54 @@ inline std::istream& operator>>(std::istream& is, ofVec3f& vec) { return is; } -inline ofVec3f ofVec3f::operator+( const ofVec3f& pnt ) const { - return ofVec3f( x+pnt.x, y+pnt.y, z+pnt.z ); +inline ofVec3f ofVec3f::operator+(const ofVec3f & pnt) const { + return ofVec3f(x + pnt.x, y + pnt.y, z + pnt.z); } -inline ofVec3f& ofVec3f::operator+=( const ofVec3f& pnt ) { - x+=pnt.x; - y+=pnt.y; - z+=pnt.z; +inline ofVec3f & ofVec3f::operator+=(const ofVec3f & pnt) { + x += pnt.x; + y += pnt.y; + z += pnt.z; return *this; } -inline ofVec3f ofVec3f::operator-( const ofVec3f& vec ) const { - return ofVec3f( x-vec.x, y-vec.y, z-vec.z ); +inline ofVec3f ofVec3f::operator-(const ofVec3f & vec) const { + return ofVec3f(x - vec.x, y - vec.y, z - vec.z); } -inline ofVec3f& ofVec3f::operator-=( const ofVec3f& vec ) { +inline ofVec3f & ofVec3f::operator-=(const ofVec3f & vec) { x -= vec.x; y -= vec.y; z -= vec.z; return *this; } -inline ofVec3f ofVec3f::operator*( const ofVec3f& vec ) const { - return ofVec3f( x*vec.x, y*vec.y, z*vec.z ); +inline ofVec3f ofVec3f::operator*(const ofVec3f & vec) const { + return ofVec3f(x * vec.x, y * vec.y, z * vec.z); } -inline ofVec3f& ofVec3f::operator*=( const ofVec3f& vec ) { - x*=vec.x; - y*=vec.y; - z*=vec.z; +inline ofVec3f & ofVec3f::operator*=(const ofVec3f & vec) { + x *= vec.x; + y *= vec.y; + z *= vec.z; return *this; } -inline ofVec3f ofVec3f::operator/( const ofVec3f& vec ) const { - return ofVec3f( vec.x!=0 ? x/vec.x : x , vec.y!=0 ? y/vec.y : y, vec.z!=0 ? z/vec.z : z ); +inline ofVec3f ofVec3f::operator/(const ofVec3f & vec) const { + return ofVec3f(vec.x != 0 ? x / vec.x : x, vec.y != 0 ? y / vec.y : y, vec.z != 0 ? z / vec.z : z); } -inline ofVec3f& ofVec3f::operator/=( const ofVec3f& vec ) { - vec.x!=0 ? x/=vec.x : x; - vec.y!=0 ? y/=vec.y : y; - vec.z!=0 ? z/=vec.z : z; +inline ofVec3f & ofVec3f::operator/=(const ofVec3f & vec) { + vec.x != 0 ? x /= vec.x : x; + vec.y != 0 ? y /= vec.y : y; + vec.z != 0 ? z /= vec.z : z; return *this; } inline ofVec3f ofVec3f::operator-() const { - return ofVec3f( -x, -y, -z ); + return ofVec3f(-x, -y, -z); } - //operator overloading for float // // @@ -1214,169 +1226,169 @@ inline ofVec3f ofVec3f::operator-() const { // z = f; //} -inline ofVec3f ofVec3f::operator+( const float f ) const { - return ofVec3f( x+f, y+f, z+f); +inline ofVec3f ofVec3f::operator+(const float f) const { + return ofVec3f(x + f, y + f, z + f); } -inline ofVec3f& ofVec3f::operator+=( const float f ) { +inline ofVec3f & ofVec3f::operator+=(const float f) { x += f; y += f; z += f; return *this; } -inline ofVec3f ofVec3f::operator-( const float f ) const { - return ofVec3f( x-f, y-f, z-f); +inline ofVec3f ofVec3f::operator-(const float f) const { + return ofVec3f(x - f, y - f, z - f); } -inline ofVec3f& ofVec3f::operator-=( const float f ) { +inline ofVec3f & ofVec3f::operator-=(const float f) { x -= f; y -= f; z -= f; return *this; } -inline ofVec3f ofVec3f::operator*( const float f ) const { - return ofVec3f( x*f, y*f, z*f ); +inline ofVec3f ofVec3f::operator*(const float f) const { + return ofVec3f(x * f, y * f, z * f); } -inline ofVec3f& ofVec3f::operator*=( const float f ) { - x*=f; - y*=f; - z*=f; +inline ofVec3f & ofVec3f::operator*=(const float f) { + x *= f; + y *= f; + z *= f; return *this; } -inline ofVec3f ofVec3f::operator/( const float f ) const { - if(f == 0) return ofVec3f( x, y, z); - - return ofVec3f( x/f, y/f, z/f ); +inline ofVec3f ofVec3f::operator/(const float f) const { + if (f == 0) return ofVec3f(x, y, z); + + return ofVec3f(x / f, y / f, z / f); } -inline ofVec3f& ofVec3f::operator/=( const float f ) { - if(f == 0) return *this; - - x/=f; - y/=f; - z/=f; +inline ofVec3f & ofVec3f::operator/=(const float f) { + if (f == 0) return *this; + + x /= f; + y /= f; + z /= f; return *this; } - //Scale // // -inline ofVec3f ofVec3f::rescaled( const float length ) const { +inline ofVec3f ofVec3f::rescaled(const float length) const { return getScaled(length); } -inline ofVec3f ofVec3f::getScaled( const float length ) const { - float l = (float)sqrt(x*x + y*y + z*z); - if( l > 0 ) - return ofVec3f( (x/l)*length, (y/l)*length, (z/l)*length ); +inline ofVec3f ofVec3f::getScaled(const float length) const { + float l = (float)sqrt(x * x + y * y + z * z); + if (l > 0) + return ofVec3f((x / l) * length, (y / l) * length, (z / l) * length); else return ofVec3f(); } -inline ofVec3f& ofVec3f::rescale( const float length ) { +inline ofVec3f & ofVec3f::rescale(const float length) { return scale(length); } -inline ofVec3f& ofVec3f::scale( const float length ) { - float l = (float)sqrt(x*x + y*y + z*z); +inline ofVec3f & ofVec3f::scale(const float length) { + float l = (float)sqrt(x * x + y * y + z * z); if (l > 0) { - x = (x/l)*length; - y = (y/l)*length; - z = (z/l)*length; + x = (x / l) * length; + y = (y / l) * length; + z = (z / l) * length; } return *this; } - - // Rotation // // -inline ofVec3f ofVec3f::rotated( float angle, const ofVec3f& axis ) const { +inline ofVec3f ofVec3f::rotated(float angle, const ofVec3f & axis) const { return getRotated(angle, axis); } -inline ofVec3f ofVec3f::getRotated( float angle, const ofVec3f& axis ) const { +inline ofVec3f ofVec3f::getRotated(float angle, const ofVec3f & axis) const { ofVec3f ax = axis.getNormalized(); float a = (float)(ofDegToRad(angle)); - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - return ofVec3f( x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina), - x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina), - x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa) ); -} - -inline ofVec3f ofVec3f::getRotatedRad( float angle, const ofVec3f& axis ) const { + + return ofVec3f(x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina), + x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina), + x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa)); +} + +inline ofVec3f ofVec3f::getRotatedRad(float angle, const ofVec3f & axis) const { ofVec3f ax = axis.getNormalized(); float a = angle; - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - return ofVec3f( x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina), - x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina), - x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa) ); -} - -inline ofVec3f& ofVec3f::rotate( float angle, const ofVec3f& axis ) { + + return ofVec3f(x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina), + x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina), + x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa)); +} + +inline ofVec3f & ofVec3f::rotate(float angle, const ofVec3f & axis) { ofVec3f ax = axis.getNormalized(); float a = (float)(ofDegToRad(angle)); - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float nx = x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina); - float ny = x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina); - float nz = x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa); - x = nx; y = ny; z = nz; + + float nx = x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina); + float ny = x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina); + float nz = x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa); + x = nx; + y = ny; + z = nz; return *this; } - -inline ofVec3f& ofVec3f::rotateRad(float angle, const ofVec3f& axis ) { +inline ofVec3f & ofVec3f::rotateRad(float angle, const ofVec3f & axis) { ofVec3f ax = axis.getNormalized(); float a = angle; - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float nx = x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina); - float ny = x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina); - float nz = x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa); - x = nx; y = ny; z = nz; + + float nx = x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina); + float ny = x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina); + float nz = x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa); + x = nx; + y = ny; + z = nz; return *this; } // const??? inline ofVec3f ofVec3f::rotated(float ax, float ay, float az) { - return getRotated(ax,ay,az); + return getRotated(ax, ay, az); } inline ofVec3f ofVec3f::getRotated(float ax, float ay, float az) const { @@ -1386,12 +1398,12 @@ inline ofVec3f ofVec3f::getRotated(float ax, float ay, float az) const { float d = (float)sin(ofDegToRad(ay)); float e = (float)cos(ofDegToRad(az)); float f = (float)sin(ofDegToRad(az)); - + float nx = c * e * x - c * f * y + d * z; float ny = (a * f + b * d * e) * x + (a * e - b * d * f) * y - b * c * z; float nz = (b * f - a * d * e) * x + (a * d * f + b * e) * y + a * c * z; - - return ofVec3f( nx, ny, nz ); + + return ofVec3f(nx, ny, nz); } inline ofVec3f ofVec3f::getRotatedRad(float ax, float ay, float az) const { @@ -1401,239 +1413,223 @@ inline ofVec3f ofVec3f::getRotatedRad(float ax, float ay, float az) const { float d = sin(ay); float e = cos(az); float f = sin(az); - + float nx = c * e * x - c * f * y + d * z; float ny = (a * f + b * d * e) * x + (a * e - b * d * f) * y - b * c * z; float nz = (b * f - a * d * e) * x + (a * d * f + b * e) * y + a * c * z; - - return ofVec3f( nx, ny, nz ); -} + return ofVec3f(nx, ny, nz); +} -inline ofVec3f& ofVec3f::rotate(float ax, float ay, float az) { +inline ofVec3f & ofVec3f::rotate(float ax, float ay, float az) { float a = (float)cos(ofDegToRad(ax)); float b = (float)sin(ofDegToRad(ax)); float c = (float)cos(ofDegToRad(ay)); float d = (float)sin(ofDegToRad(ay)); float e = (float)cos(ofDegToRad(az)); float f = (float)sin(ofDegToRad(az)); - + float nx = c * e * x - c * f * y + d * z; float ny = (a * f + b * d * e) * x + (a * e - b * d * f) * y - b * c * z; float nz = (b * f - a * d * e) * x + (a * d * f + b * e) * y + a * c * z; - - x = nx; y = ny; z = nz; + + x = nx; + y = ny; + z = nz; return *this; } - -inline ofVec3f& ofVec3f::rotateRad(float ax, float ay, float az) { +inline ofVec3f & ofVec3f::rotateRad(float ax, float ay, float az) { float a = cos(ax); float b = sin(ax); float c = cos(ay); float d = sin(ay); float e = cos(az); float f = sin(az); - + float nx = c * e * x - c * f * y + d * z; float ny = (a * f + b * d * e) * x + (a * e - b * d * f) * y - b * c * z; float nz = (b * f - a * d * e) * x + (a * d * f + b * e) * y + a * c * z; - - x = nx; y = ny; z = nz; + + x = nx; + y = ny; + z = nz; return *this; } - // Rotate point by angle (deg) around line defined by pivot and axis. // // -inline ofVec3f ofVec3f::rotated( float angle, - const ofVec3f& pivot, - const ofVec3f& axis ) const{ +inline ofVec3f ofVec3f::rotated(float angle, + const ofVec3f & pivot, + const ofVec3f & axis) const { return getRotated(angle, pivot, axis); } -inline ofVec3f ofVec3f::getRotated( float angle, - const ofVec3f& pivot, - const ofVec3f& axis ) const -{ +inline ofVec3f ofVec3f::getRotated(float angle, + const ofVec3f & pivot, + const ofVec3f & axis) const { ofVec3f ax = axis.getNormalized(); float tx = x - pivot.x; float ty = y - pivot.y; float tz = z - pivot.z; - + float a = ofDegToRad(angle); - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float xrot = tx*(ax.x*ax.x*cosb + cosa) - + ty*(ax.x*ax.y*cosb - ax.z*sina) - + tz*(ax.x*ax.z*cosb + ax.y*sina); - float yrot = tx*(ax.y*ax.x*cosb + ax.z*sina) - + ty*(ax.y*ax.y*cosb + cosa) - + tz*(ax.y*ax.z*cosb - ax.x*sina); - float zrot = tx*(ax.z*ax.x*cosb - ax.y*sina) - + ty*(ax.z*ax.y*cosb + ax.x*sina) - + tz*(ax.z*ax.z*cosb + cosa); - - - return ofVec3f( xrot+pivot.x, yrot+pivot.y, zrot+pivot.z ); -} + float xrot = tx * (ax.x * ax.x * cosb + cosa) + + ty * (ax.x * ax.y * cosb - ax.z * sina) + + tz * (ax.x * ax.z * cosb + ax.y * sina); + float yrot = tx * (ax.y * ax.x * cosb + ax.z * sina) + + ty * (ax.y * ax.y * cosb + cosa) + + tz * (ax.y * ax.z * cosb - ax.x * sina); + float zrot = tx * (ax.z * ax.x * cosb - ax.y * sina) + + ty * (ax.z * ax.y * cosb + ax.x * sina) + + tz * (ax.z * ax.z * cosb + cosa); + + return ofVec3f(xrot + pivot.x, yrot + pivot.y, zrot + pivot.z); +} -inline ofVec3f ofVec3f::getRotatedRad( float angle, - const ofVec3f& pivot, - const ofVec3f& axis ) const -{ +inline ofVec3f ofVec3f::getRotatedRad(float angle, + const ofVec3f & pivot, + const ofVec3f & axis) const { ofVec3f ax = axis.getNormalized(); float tx = x - pivot.x; float ty = y - pivot.y; float tz = z - pivot.z; - + float a = angle; - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float xrot = tx*(ax.x*ax.x*cosb + cosa) - + ty*(ax.x*ax.y*cosb - ax.z*sina) - + tz*(ax.x*ax.z*cosb + ax.y*sina); - float yrot = tx*(ax.y*ax.x*cosb + ax.z*sina) - + ty*(ax.y*ax.y*cosb + cosa) - + tz*(ax.y*ax.z*cosb - ax.x*sina); - float zrot = tx*(ax.z*ax.x*cosb - ax.y*sina) - + ty*(ax.z*ax.y*cosb + ax.x*sina) - + tz*(ax.z*ax.z*cosb + cosa); - - - return ofVec3f( xrot+pivot.x, yrot+pivot.y, zrot+pivot.z ); -} + float xrot = tx * (ax.x * ax.x * cosb + cosa) + + ty * (ax.x * ax.y * cosb - ax.z * sina) + + tz * (ax.x * ax.z * cosb + ax.y * sina); + float yrot = tx * (ax.y * ax.x * cosb + ax.z * sina) + + ty * (ax.y * ax.y * cosb + cosa) + + tz * (ax.y * ax.z * cosb - ax.x * sina); + float zrot = tx * (ax.z * ax.x * cosb - ax.y * sina) + + ty * (ax.z * ax.y * cosb + ax.x * sina) + + tz * (ax.z * ax.z * cosb + cosa); -inline ofVec3f& ofVec3f::rotate( float angle, - const ofVec3f& pivot, - const ofVec3f& axis ) -{ + return ofVec3f(xrot + pivot.x, yrot + pivot.y, zrot + pivot.z); +} + +inline ofVec3f & ofVec3f::rotate(float angle, + const ofVec3f & pivot, + const ofVec3f & axis) { ofVec3f ax = axis.getNormalized(); x -= pivot.x; y -= pivot.y; z -= pivot.z; - + float a = ofDegToRad(angle); - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float xrot = x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina); - float yrot = x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina); - float zrot = x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa); - + + float xrot = x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina); + float yrot = x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina); + float zrot = x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa); + x = xrot + pivot.x; y = yrot + pivot.y; z = zrot + pivot.z; - + return *this; } - -inline ofVec3f& ofVec3f::rotateRad( float angle, - const ofVec3f& pivot, - const ofVec3f& axis ) -{ +inline ofVec3f & ofVec3f::rotateRad(float angle, + const ofVec3f & pivot, + const ofVec3f & axis) { ofVec3f ax = axis.getNormalized(); x -= pivot.x; y -= pivot.y; z -= pivot.z; - + float a = angle; - float sina = sin( a ); - float cosa = cos( a ); + float sina = sin(a); + float cosa = cos(a); float cosb = 1.0f - cosa; - - float xrot = x*(ax.x*ax.x*cosb + cosa) - + y*(ax.x*ax.y*cosb - ax.z*sina) - + z*(ax.x*ax.z*cosb + ax.y*sina); - float yrot = x*(ax.y*ax.x*cosb + ax.z*sina) - + y*(ax.y*ax.y*cosb + cosa) - + z*(ax.y*ax.z*cosb - ax.x*sina); - float zrot = x*(ax.z*ax.x*cosb - ax.y*sina) - + y*(ax.z*ax.y*cosb + ax.x*sina) - + z*(ax.z*ax.z*cosb + cosa); - + + float xrot = x * (ax.x * ax.x * cosb + cosa) + + y * (ax.x * ax.y * cosb - ax.z * sina) + + z * (ax.x * ax.z * cosb + ax.y * sina); + float yrot = x * (ax.y * ax.x * cosb + ax.z * sina) + + y * (ax.y * ax.y * cosb + cosa) + + z * (ax.y * ax.z * cosb - ax.x * sina); + float zrot = x * (ax.z * ax.x * cosb - ax.y * sina) + + y * (ax.z * ax.y * cosb + ax.x * sina) + + z * (ax.z * ax.z * cosb + cosa); + x = xrot + pivot.x; y = yrot + pivot.y; z = zrot + pivot.z; - + return *this; } - - - // Map point to coordinate system defined by origin, vx, vy, and vz. // // -inline ofVec3f ofVec3f::mapped( const ofVec3f& origin, - const ofVec3f& vx, - const ofVec3f& vy, - const ofVec3f& vz ) const{ +inline ofVec3f ofVec3f::mapped(const ofVec3f & origin, + const ofVec3f & vx, + const ofVec3f & vy, + const ofVec3f & vz) const { return getMapped(origin, vx, vy, vz); } -inline ofVec3f ofVec3f::getMapped( const ofVec3f& origin, - const ofVec3f& vx, - const ofVec3f& vy, - const ofVec3f& vz ) const -{ - return ofVec3f( origin.x + x*vx.x + y*vy.x + z*vz.x, - origin.y + x*vx.y + y*vy.y + z*vz.y, - origin.z + x*vx.z + y*vy.z + z*vz.z ); -} - -inline ofVec3f& ofVec3f::map( const ofVec3f& origin, - const ofVec3f& vx, - const ofVec3f& vy, - const ofVec3f& vz ) -{ - float xmap = origin.x + x*vx.x + y*vy.x + z*vz.x; - float ymap = origin.y + x*vx.y + y*vy.y + z*vz.y; - z = origin.z + x*vx.z + y*vy.z + z*vz.z; +inline ofVec3f ofVec3f::getMapped(const ofVec3f & origin, + const ofVec3f & vx, + const ofVec3f & vy, + const ofVec3f & vz) const { + return ofVec3f(origin.x + x * vx.x + y * vy.x + z * vz.x, + origin.y + x * vx.y + y * vy.y + z * vz.y, + origin.z + x * vx.z + y * vy.z + z * vz.z); +} + +inline ofVec3f & ofVec3f::map(const ofVec3f & origin, + const ofVec3f & vx, + const ofVec3f & vy, + const ofVec3f & vz) { + float xmap = origin.x + x * vx.x + y * vy.x + z * vz.x; + float ymap = origin.y + x * vx.y + y * vy.y + z * vz.y; + z = origin.z + x * vx.z + y * vy.z + z * vz.z; x = xmap; y = ymap; return *this; } - // Distance between two points. // // -inline float ofVec3f::distance( const ofVec3f& pnt) const { - float vx = x-pnt.x; - float vy = y-pnt.y; - float vz = z-pnt.z; - return (float)sqrt(vx*vx + vy*vy + vz*vz); +inline float ofVec3f::distance(const ofVec3f & pnt) const { + float vx = x - pnt.x; + float vy = y - pnt.y; + float vz = z - pnt.z; + return (float)sqrt(vx * vx + vy * vy + vz * vz); } -inline float ofVec3f::distanceSquared( const ofVec3f& pnt ) const{ +inline float ofVec3f::distanceSquared(const ofVec3f & pnt) const { return squareDistance(pnt); } -inline float ofVec3f::squareDistance( const ofVec3f& pnt ) const { - float vx = x-pnt.x; - float vy = y-pnt.y; - float vz = z-pnt.z; - return vx*vx + vy*vy + vz*vz; +inline float ofVec3f::squareDistance(const ofVec3f & pnt) const { + float vx = x - pnt.x; + float vy = y - pnt.y; + float vz = z - pnt.z; + return vx * vx + vy * vy + vz * vz; } - - // Linear interpolation. // // @@ -1642,49 +1638,47 @@ inline float ofVec3f::squareDistance( const ofVec3f& pnt ) const { * midpoint, and p==1.0 results in pnt being returned. */ -inline ofVec3f ofVec3f::interpolated( const ofVec3f& pnt, float p ) const { - return getInterpolated(pnt,p); +inline ofVec3f ofVec3f::interpolated(const ofVec3f & pnt, float p) const { + return getInterpolated(pnt, p); } -inline ofVec3f ofVec3f::getInterpolated( const ofVec3f& pnt, float p ) const { - return ofVec3f( x*(1-p) + pnt.x*p, - y*(1-p) + pnt.y*p, - z*(1-p) + pnt.z*p ); +inline ofVec3f ofVec3f::getInterpolated(const ofVec3f & pnt, float p) const { + return ofVec3f(x * (1 - p) + pnt.x * p, + y * (1 - p) + pnt.y * p, + z * (1 - p) + pnt.z * p); } -inline ofVec3f& ofVec3f::interpolate( const ofVec3f& pnt, float p ) { - x = x*(1-p) + pnt.x*p; - y = y*(1-p) + pnt.y*p; - z = z*(1-p) + pnt.z*p; +inline ofVec3f & ofVec3f::interpolate(const ofVec3f & pnt, float p) { + x = x * (1 - p) + pnt.x * p; + y = y * (1 - p) + pnt.y * p; + z = z * (1 - p) + pnt.z * p; return *this; } - -inline ofVec3f ofVec3f::middled( const ofVec3f& pnt ) const { +inline ofVec3f ofVec3f::middled(const ofVec3f & pnt) const { return getMiddle(pnt); } -inline ofVec3f ofVec3f::getMiddle( const ofVec3f& pnt ) const { - return ofVec3f( (x+pnt.x)/2.0f, (y+pnt.y)/2.0f, (z+pnt.z)/2.0f ); +inline ofVec3f ofVec3f::getMiddle(const ofVec3f & pnt) const { + return ofVec3f((x + pnt.x) / 2.0f, (y + pnt.y) / 2.0f, (z + pnt.z) / 2.0f); } -inline ofVec3f& ofVec3f::middle( const ofVec3f& pnt ) { - x = (x+pnt.x)/2.0f; - y = (y+pnt.y)/2.0f; - z = (z+pnt.z)/2.0f; +inline ofVec3f & ofVec3f::middle(const ofVec3f & pnt) { + x = (x + pnt.x) / 2.0f; + y = (y + pnt.y) / 2.0f; + z = (z + pnt.z) / 2.0f; return *this; } - // Average (centroid) among points. // Addition is sometimes useful for calculating averages too. // // -inline ofVec3f& ofVec3f::average( const ofVec3f* points, int num ) { +inline ofVec3f & ofVec3f::average(const ofVec3f * points, int num) { x = 0.f; y = 0.f; z = 0.f; - for( int i=0; i 0 ) { - return ofVec3f( x/length, y/length, z/length ); + float length = (float)sqrt(x * x + y * y + z * z); + if (length > 0) { + return ofVec3f(x / length, y / length, z / length); } else { return ofVec3f(); } } -inline ofVec3f& ofVec3f::normalize() { - float length = (float)sqrt(x*x + y*y + z*z); - if( length > 0 ) { +inline ofVec3f & ofVec3f::normalize() { + float length = (float)sqrt(x * x + y * y + z * z); + if (length > 0) { x /= length; y /= length; z /= length; @@ -1723,8 +1715,6 @@ inline ofVec3f& ofVec3f::normalize() { return *this; } - - // Limit length. // // @@ -1734,45 +1724,44 @@ inline ofVec3f ofVec3f::limited(float max) const { } inline ofVec3f ofVec3f::getLimited(float max) const { - ofVec3f limited; - float lengthSquared = (x*x + y*y + z*z); - if( lengthSquared > max*max && lengthSquared > 0 ) { - float ratio = max/(float)sqrt(lengthSquared); - limited.set( x*ratio, y*ratio, z*ratio); - } else { - limited.set(x,y,z); - } - return limited; + ofVec3f limited; + float lengthSquared = (x * x + y * y + z * z); + if (lengthSquared > max * max && lengthSquared > 0) { + float ratio = max / (float)sqrt(lengthSquared); + limited.set(x * ratio, y * ratio, z * ratio); + } else { + limited.set(x, y, z); + } + return limited; } -inline ofVec3f& ofVec3f::limit(float max) { - float lengthSquared = (x*x + y*y + z*z); - if( lengthSquared > max*max && lengthSquared > 0 ) { - float ratio = max/(float)sqrt(lengthSquared); - x *= ratio; - y *= ratio; - z *= ratio; - } - return *this; +inline ofVec3f & ofVec3f::limit(float max) { + float lengthSquared = (x * x + y * y + z * z); + if (lengthSquared > max * max && lengthSquared > 0) { + float ratio = max / (float)sqrt(lengthSquared); + x *= ratio; + y *= ratio; + z *= ratio; + } + return *this; } - // Perpendicular vector. // // -inline ofVec3f ofVec3f::crossed( const ofVec3f& vec ) const { +inline ofVec3f ofVec3f::crossed(const ofVec3f & vec) const { return getCrossed(vec); } -inline ofVec3f ofVec3f::getCrossed( const ofVec3f& vec ) const { - return ofVec3f( y*vec.z - z*vec.y, - z*vec.x - x*vec.z, - x*vec.y - y*vec.x ); +inline ofVec3f ofVec3f::getCrossed(const ofVec3f & vec) const { + return ofVec3f(y * vec.z - z * vec.y, + z * vec.x - x * vec.z, + x * vec.y - y * vec.x); } -inline ofVec3f& ofVec3f::cross( const ofVec3f& vec ) { - float _x = y*vec.z - z*vec.y; - float _y = z*vec.x - x*vec.z; - z = x*vec.y - y*vec.x; +inline ofVec3f & ofVec3f::cross(const ofVec3f & vec) { + float _x = y * vec.z - z * vec.y; + float _y = z * vec.x - x * vec.z; + z = x * vec.y - y * vec.x; x = _x; y = _y; return *this; @@ -1781,108 +1770,95 @@ inline ofVec3f& ofVec3f::cross( const ofVec3f& vec ) { /** * Normalized perpendicular. */ -inline ofVec3f ofVec3f::perpendiculared( const ofVec3f& vec ) const { +inline ofVec3f ofVec3f::perpendiculared(const ofVec3f & vec) const { return getPerpendicular(vec); } -inline ofVec3f ofVec3f::getPerpendicular( const ofVec3f& vec ) const { - float crossX = y*vec.z - z*vec.y; - float crossY = z*vec.x - x*vec.z; - float crossZ = x*vec.y - y*vec.x; - - float length = (float)sqrt(crossX*crossX + - crossY*crossY + - crossZ*crossZ); - - if( length > 0 ) - return ofVec3f( crossX/length, crossY/length, crossZ/length ); +inline ofVec3f ofVec3f::getPerpendicular(const ofVec3f & vec) const { + float crossX = y * vec.z - z * vec.y; + float crossY = z * vec.x - x * vec.z; + float crossZ = x * vec.y - y * vec.x; + + float length = (float)sqrt(crossX * crossX + crossY * crossY + crossZ * crossZ); + + if (length > 0) + return ofVec3f(crossX / length, crossY / length, crossZ / length); else return ofVec3f(); } -inline ofVec3f& ofVec3f::perpendicular( const ofVec3f& vec ) { - float crossX = y*vec.z - z*vec.y; - float crossY = z*vec.x - x*vec.z; - float crossZ = x*vec.y - y*vec.x; - - float length = (float)sqrt(crossX*crossX + - crossY*crossY + - crossZ*crossZ); - - if( length > 0 ) { - x = crossX/length; - y = crossY/length; - z = crossZ/length; +inline ofVec3f & ofVec3f::perpendicular(const ofVec3f & vec) { + float crossX = y * vec.z - z * vec.y; + float crossY = z * vec.x - x * vec.z; + float crossZ = x * vec.y - y * vec.x; + + float length = (float)sqrt(crossX * crossX + crossY * crossY + crossZ * crossZ); + + if (length > 0) { + x = crossX / length; + y = crossY / length; + z = crossZ / length; } else { x = 0.f; y = 0.f; z = 0.f; } - + return *this; } - // Length // // inline float ofVec3f::length() const { - return (float)sqrt( x*x + y*y + z*z ); + return (float)sqrt(x * x + y * y + z * z); } inline float ofVec3f::lengthSquared() const { - return (float)(x*x + y*y + z*z); + return (float)(x * x + y * y + z * z); } - - /** * Angle (deg) between two vectors. * This is an unsigned relative angle from 0 to 180. * http://www.euclideanspace.com/maths/algebra/vectors/angleBetween/index.htm */ -inline float ofVec3f::angle( const ofVec3f& vec ) const { +inline float ofVec3f::angle(const ofVec3f & vec) const { ofVec3f n1 = this->getNormalized(); ofVec3f n2 = vec.getNormalized(); - return ofRadToDeg(acos( n1.dot(n2) )); + return ofRadToDeg(acos(n1.dot(n2))); } -inline float ofVec3f::angleRad( const ofVec3f& vec ) const { +inline float ofVec3f::angleRad(const ofVec3f & vec) const { ofVec3f n1 = this->getNormalized(); ofVec3f n2 = vec.getNormalized(); - return (float)acos( n1.dot(n2) ); + return (float)acos(n1.dot(n2)); } - - /** * Dot Product. */ -inline float ofVec3f::dot( const ofVec3f& vec ) const { - return x*vec.x + y*vec.y + z*vec.z; +inline float ofVec3f::dot(const ofVec3f & vec) const { + return x * vec.x + y * vec.y + z * vec.z; } - - - - // Non-Member operators // // -inline ofVec3f operator+( float f, const ofVec3f& vec ) { - return ofVec3f( f+vec.x, f+vec.y, f+vec.z ); +inline ofVec3f operator+(float f, const ofVec3f & vec) { + return ofVec3f(f + vec.x, f + vec.y, f + vec.z); } -inline ofVec3f operator-( float f, const ofVec3f& vec ) { - return ofVec3f( f-vec.x, f-vec.y, f-vec.z ); +inline ofVec3f operator-(float f, const ofVec3f & vec) { + return ofVec3f(f - vec.x, f - vec.y, f - vec.z); } -inline ofVec3f operator*( float f, const ofVec3f& vec ) { - return ofVec3f( f*vec.x, f*vec.y, f*vec.z ); +inline ofVec3f operator*(float f, const ofVec3f & vec) { + return ofVec3f(f * vec.x, f * vec.y, f * vec.z); } -inline ofVec3f operator/( float f, const ofVec3f& vec ) { - return ofVec3f( f/vec.x, f/vec.y, f/vec.z); +inline ofVec3f operator/(float f, const ofVec3f & vec) { + return ofVec3f(f / vec.x, f / vec.y, f / vec.z); } /// \endcond diff --git a/libs/openFrameworks/video/ofVideoPlayer.h b/libs/openFrameworks/video/ofVideoPlayer.h index 655d816ef6c..7cc987ec1e0 100644 --- a/libs/openFrameworks/video/ofVideoPlayer.h +++ b/libs/openFrameworks/video/ofVideoPlayer.h @@ -20,28 +20,30 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// If no video file is loaded this returns an empty string. /// /// \returns A path to the loaded video or an empty string if not loaded. - std::string getMoviePath() const; + std::string getMoviePath() const; - bool setPixelFormat(ofPixelFormat pixelFormat); - ofPixelFormat getPixelFormat() const; + bool setPixelFormat(ofPixelFormat pixelFormat); + ofPixelFormat getPixelFormat() const; /// \brief Closes the movie file and releases its resources. /// /// This is an alias for close(). /// /// \sa close() + [[deprecated("use close()")]] void closeMovie(); /// \brief Closes the movie file releases its resources. /// /// This is an alias for closeMovie(). /// /// \sa closeMovie() - void close(); + void close(); /// \brief Update the video player's internal state to continue playback. /// /// If normal video playback is desired, this method is usually called /// once per animation frame inside of ofApp::update(). + void update(); void play(); void stop(); @@ -85,35 +87,38 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// /// \sa ofTexture::bind() /// \sa http://www.opengl.org/sdk/docs/man4/html/glBindTexture.xhtml - void bind() const; + void bind() const; + /// \brief Unbinds the video texture from the current rendering context. /// /// For advanced users who need to manually manage texture drawing /// without calling draw(). Only binds the texture if one exists. /// /// \sa ofTexture::unbind() - void unbind() const; +<<<<<< deprecations + void unbind() const; + + void setAnchorPercent(float xPct, float yPct); + void setAnchorPoint(float x, float y); + void resetAnchor(); - void setAnchorPercent(float xPct, float yPct); - void setAnchorPoint(float x, float y); - void resetAnchor(); + void setPaused(bool bPause); - void setPaused(bool bPause); + int getCurrentFrame() const; + int getTotalNumFrames() const; - int getCurrentFrame() const; - int getTotalNumFrames() const; + void firstFrame(); + void nextFrame(); + void previousFrame(); - void firstFrame(); - void nextFrame(); - void previousFrame(); + float getHeight() const; + float getWidth() const; - float getHeight() const; - float getWidth() const; + bool isPaused() const; + bool isLoaded() const; + bool isPlaying() const; + bool isInitialized() const; - bool isPaused() const; - bool isLoaded() const; - bool isPlaying() const; - bool isInitialized() const; /// \brief Set the internal video player implementation. /// @@ -123,7 +128,8 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// /// \param newPlayer Shared pointer to the new video player that extends /// from ofBaseVideoPlayer. - void setPlayer(std::shared_ptr newPlayer); + void setPlayer(std::shared_ptr newPlayer); + /// \brief Get a pointer to the internal video player implementation. /// /// This returns a pointer to the ofBaseVideoPlayer interface. For @@ -132,7 +138,8 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// templated getPlayer() method. /// /// \returns A pointer to the internal video player implementation. - std::shared_ptr getPlayer(); + std::shared_ptr getPlayer(); + /// \brief Get a const pointer to the internal video player implementation. /// /// This returns a pointer to the ofBaseVideoPlayer interface. For @@ -141,7 +148,7 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// or the templated getPlayer() method. /// /// \returns A const pointer to the internal video player implementation. - const std::shared_ptr getPlayer() const; + const std::shared_ptr getPlayer() const; /// \brief Get a pointer to the internal video player implementation. /// @@ -150,8 +157,8 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// /// \returns A pointer to the internal video player implementation or /// nullptr if the cast fails. - template - std::shared_ptr getPlayer(){ + template + std::shared_ptr getPlayer() { return std::dynamic_pointer_cast(getPlayer()); } @@ -162,8 +169,8 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// /// \returns A const pointer to the internal video player implementation /// or nullptr if the cast fails. - template - const std::shared_ptr getPlayer() const{ + template + const std::shared_ptr getPlayer() const { return std::dynamic_pointer_cast(getPlayer()); } @@ -171,7 +178,8 @@ class ofVideoPlayer : public ofBaseVideoDraws { /// \brief Initialize the default player implementations. void initDefaultPlayer(); /// \brief A pointer to the internal video player implementation. - std::shared_ptr player; + std::shared_ptr player; + /// \brief A collection of texture planes used by the video player. std::vector tex; /// \brief A pointer to the internal player's texture if available.