summaryrefslogtreecommitdiffstats
path: root/src/math/vector.h
diff options
context:
space:
mode:
authorPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 22:53:06 +0200
committerPiotr Dziwinski <piotrdz@gmail.com>2012-09-19 22:53:06 +0200
commit7479f486b671acb2a6aea2c84a56b383aaba00ca (patch)
tree4043545a14234dfaa2d7d08d59c7ee9ee97f0de9 /src/math/vector.h
parent901f10b2bac18a2063cd21798f22b3917e8519b5 (diff)
parent57d33d79ea570773d84ad81d4a61f50e079979ef (diff)
downloadcolobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.tar.gz
colobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.tar.bz2
colobot-7479f486b671acb2a6aea2c84a56b383aaba00ca.zip
Forgotten fix in dev-graphics
Diffstat (limited to 'src/math/vector.h')
-rw-r--r--src/math/vector.h45
1 files changed, 30 insertions, 15 deletions
diff --git a/src/math/vector.h b/src/math/vector.h
index 4378e75..222d0cd 100644
--- a/src/math/vector.h
+++ b/src/math/vector.h
@@ -32,16 +32,17 @@
namespace Math
{
-/** \struct Vector math/vector.h
- \brief 3D (3x1) vector
-
- Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines.
- Contains the required methods for operating on vectors.
-
- All methods are made inline to maximize optimization.
-
- Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
-
+/**
+ * \struct Vector
+ * \brief 3D (3x1) vector
+ *
+ * Represents a universal 3x1 vector that can be used in OpenGL and DirectX engines.
+ * Contains the required methods for operating on vectors.
+ *
+ * All methods are made inline to maximize optimization.
+ *
+ * Unit tests for the structure and related functions are in module: math/test/vector_test.cpp.
+ *
*/
struct Vector
{
@@ -103,8 +104,10 @@ struct Vector
}
//! Calculates the cross product with another vector
- /** \a right right-hand side vector
- \returns the cross product*/
+ /**
+ * \param right right-hand side vector
+ * \returns the cross product
+ */
inline Vector CrossMultiply(const Vector &right) const
{
float px = y * right.z - z * right.y;
@@ -114,8 +117,10 @@ struct Vector
}
//! Calculates the dot product with another vector
- /** \a right right-hand side vector
- \returns the dot product */
+ /**
+ * \param right right-hand side vector
+ * \returns the dot product
+ */
inline float DotMultiply(const Vector &right) const
{
return x * right.x + y * right.y + z * right.z;
@@ -218,7 +223,7 @@ struct Vector
return s.str();
}
-}; // struct Point
+}; // struct Vector
//! Checks if two vectors are equal within given \a tolerance
inline bool VectorsEqual(const Math::Vector &a, const Math::Vector &b, float tolerance = TOLERANCE)
@@ -262,4 +267,14 @@ inline float Distance(const Math::Vector &a, const Math::Vector &b)
(a.z-b.z)*(a.z-b.z) );
}
+//! Clamps the vector \a vec to range between \a min and \a max
+inline Vector Clamp(const Vector &vec, const Vector &min, const Vector &max)
+{
+ Vector clamped;
+ clamped.x = Min(Max(min.x, vec.x), max.x);
+ clamped.y = Min(Max(min.y, vec.y), max.y);
+ clamped.z = Min(Max(min.z, vec.z), max.z);
+ return clamped;
+}
+
}; // namespace Math