Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
authorStijn Buys <ingar@osirion.org>2008-03-16 22:36:04 +0000
committerStijn Buys <ingar@osirion.org>2008-03-16 22:36:04 +0000
commitcb52e5bd8da01ab2e7976fcd8bfc34e190265ed5 (patch)
tree3645b53d64ca6e6068537c18efc5c9bab7673e5b /src/math
parent7d7b9324f1f0db14648fb9fe32256d7942af77b9 (diff)
r_drawradius
Diffstat (limited to 'src/math')
-rw-r--r--src/math/vector3f.cc23
-rw-r--r--src/math/vector3f.h6
2 files changed, 26 insertions, 3 deletions
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index 3f1f4ac..a9e7e00 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -116,7 +116,7 @@ bool Vector3f::operator==(const Vector3f& other) const
float Vector3f::lengthsquared() const
{
- double r = 0;
+ float r = 0;
for (int i=0; i < 3; i++)
r += coord[i]*coord[i];
return ((float) r);
@@ -124,11 +124,11 @@ float Vector3f::lengthsquared() const
float Vector3f::length() const
{
- double r = 0;
+ float r = 0;
for (int i=0; i < 3; i++)
r += coord[i]*coord[i];
- return ((float) sqrt(r));
+ return (sqrtf(r));
}
void Vector3f::normalize()
@@ -171,4 +171,21 @@ float dotproduct(const Vector3f& first, const Vector3f& second)
return (r);
}
+float distance(const Vector3f& first, const Vector3f& second)
+{
+ float r = 0;
+ for (int i=0; i < 3; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+
+ return (sqrtf(r));
+}
+
+float distancesquared(const Vector3f& first, const Vector3f& second)
+{
+ float r = 0;
+ for (int i=0; i < 3; i++)
+ r += (first[i]-second[i])*(first[i]-second[i]);
+ return (r);
+}
+
} // namespace math
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index 5d1fa41..20e47f2 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -148,6 +148,12 @@ const Vector3f crossproduct(Vector3f const & first, Vector3f const & second);
/// vector dot product
float dotproduct(const Vector3f& first, const Vector3f& second);
+/// distance between two vectors
+float distance(const Vector3f& first, const Vector3f& second);
+
+/// distance between two vectors squared
+float distancesquared(const Vector3f& first, const Vector3f& second);
+
} // namespace math
#endif // __INCLUDED_MATH_VECTOR3F_H__