summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
authorThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-02-09 22:31:26 +0100
committerThorbjørn Lindeijer <thorbjorn@lindeijer.nl>2010-02-09 22:31:26 +0100
commitbade85c7890c2255dba41b084132ef892bf365fa (patch)
tree55b5b317e3450d8ac505c317a4a53f2f724f63b2 /src
parentb7f93f0b2ec91e04d3ed9035c9e21015b8b57cdd (diff)
downloadmana-client-bade85c7890c2255dba41b084132ef892bf365fa.tar.gz
mana-client-bade85c7890c2255dba41b084132ef892bf365fa.tar.bz2
mana-client-bade85c7890c2255dba41b084132ef892bf365fa.tar.xz
mana-client-bade85c7890c2255dba41b084132ef892bf365fa.zip
Got rid of non-sensical Vector operator overloads
Just because something is the kind of calculation that seems to be required does not mean it makes sense in general. Let's try to keep things understandable.
Diffstat (limited to 'src')
-rw-r--r--src/being.cpp6
-rw-r--r--src/graphics.h2
-rw-r--r--src/vector.h33
3 files changed, 13 insertions, 28 deletions
diff --git a/src/being.cpp b/src/being.cpp
index 4b972e3d..1c66f673 100644
--- a/src/being.cpp
+++ b/src/being.cpp
@@ -532,13 +532,15 @@ void Being::logic()
const float nominalLength = dir.length();
// When we've not reached our destination, move to it.
- if (nominalLength > 1.0f && mWalkSpeed > 0.0f)
+ if (nominalLength > 1.0f && !mWalkSpeed.isNull())
{
// The deplacement of a point along a vector is calculated
// using the Unit Vector (â) multiplied by the point speed.
// â = a / ||a|| (||a|| is the a length.)
// Then, diff = (dir/||dir||) * speed.
- Vector diff = dir.normalized() * mWalkSpeed;
+ const Vector normalizedDir = dir.normalized();
+ Vector diff(normalizedDir.x * mWalkSpeed.x,
+ normalizedDir.y * mWalkSpeed.y);
// Test if we don't miss the destination by a move too far:
if (diff.length() > nominalLength)
diff --git a/src/graphics.h b/src/graphics.h
index 8bacfb9c..591b4166 100644
--- a/src/graphics.h
+++ b/src/graphics.h
@@ -193,7 +193,7 @@ class Graphics : public gcn::SDLGraphics
*/
virtual SDL_Surface *getScreenshot();
- gcn::Font *getFont() { return mFont; }
+ gcn::Font *getFont() const { return mFont; }
protected:
SDL_Surface *mScreen;
diff --git a/src/vector.h b/src/vector.h
index 0122435f..780dc30d 100644
--- a/src/vector.h
+++ b/src/vector.h
@@ -61,23 +61,22 @@ class Vector
{}
/**
- * Scale vector operator.
+ * Returns true if all coordinates are set to 0, otherwise returns
+ * false.
*/
- Vector operator*(float c) const
+ bool isNull() const
{
- return Vector(x * c,
- y * c,
- z * c);
+ return x == 0.0f && y == 0.0f && z == 0.0f;
}
/**
* Scale vector operator.
*/
- Vector operator*(const Vector &v) const
+ Vector operator*(float c) const
{
- return Vector(x * v.x,
- y * v.y,
- z * v.z);
+ return Vector(x * c,
+ y * c,
+ z * c);
}
/**
@@ -155,22 +154,6 @@ class Vector
}
/**
- * In-place > test vector operator.
- */
- bool operator>(const Vector &v)
- {
- return (x > v.x || y > v.y || z > v.z);
- }
-
- /**
- * In-place > test vector operator against a float.
- */
- bool operator>(float c)
- {
- return (x > c || y > c || z > c);
- }
-
- /**
* Returns the length of this vector. This method does a relatively
* slow square root.
*/