pingus-cvs
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[Pingus-CVS] r3952 - in trunk/pingus: . src/math


From: jsalmon3
Subject: [Pingus-CVS] r3952 - in trunk/pingus: . src/math
Date: Tue, 16 Dec 2008 07:10:46 +0100

Author: jsalmon3
Date: 2008-12-16 07:10:38 +0100 (Tue, 16 Dec 2008)
New Revision: 3952

Modified:
   trunk/pingus/TODO
   trunk/pingus/src/math/vector2f.cpp
   trunk/pingus/src/math/vector2f.hpp
   trunk/pingus/src/math/vector3f.cpp
   trunk/pingus/src/math/vector3f.hpp
Log:
Made Vector classes inline



Modified: trunk/pingus/TODO
===================================================================
--- trunk/pingus/TODO   2008-12-15 05:09:01 UTC (rev 3951)
+++ trunk/pingus/TODO   2008-12-16 06:10:38 UTC (rev 3952)
@@ -73,8 +73,6 @@
 * ScreenManager::fade_over should be integrated into
   ScreenManager::update, so that the mainloop is never left
 
-* make all Vector classes inline
-
 * add alternative fullscreen, screenshot and print-fps shortcuts for the OLPC, 
which doesn't have Fxx keys
   Ctrl-f -> fullscreen, Ctrl-s screenshot, Ctrl->p printfps
 

Modified: trunk/pingus/src/math/vector2f.cpp
===================================================================
--- trunk/pingus/src/math/vector2f.cpp  2008-12-15 05:09:01 UTC (rev 3951)
+++ trunk/pingus/src/math/vector2f.cpp  2008-12-16 06:10:38 UTC (rev 3952)
@@ -17,35 +17,8 @@
 
 #include <config.h>
 #include <iostream>
-#include "math.hpp"
 #include "math/vector2f.hpp"
 
-void
-Vector2f::normalize()
-{
-  float mag = magnitude();
-  x /= mag;
-  y /= mag;
-}
-
-Vector2f Vector2f::unit() const
-{
-  return *this / magnitude();
-}
-
-float
-Vector2f::magnitude() const
-{
-  return Math::sqrt(x*x + y*y);
-}
-
-Vector2f
-Vector2f::rotate(float angle) const
-{
-  float len = magnitude();
-  return Vector2f(len * Math::cos(angle), len * Math::sin(angle));
-}
-
 std::ostream& operator<<(std::ostream& s, const Vector2f& v)
 {
   s << "Vector2f(" << v.x << ", " << v.y << ")";

Modified: trunk/pingus/src/math/vector2f.hpp
===================================================================
--- trunk/pingus/src/math/vector2f.hpp  2008-12-15 05:09:01 UTC (rev 3951)
+++ trunk/pingus/src/math/vector2f.hpp  2008-12-16 06:10:38 UTC (rev 3952)
@@ -20,6 +20,7 @@
 
 #include <iosfwd>
 #include "vector2i.hpp"
+#include "math.hpp"
 
 /** Simple two dimensional vector. */
 class Vector2f
@@ -111,7 +112,11 @@
 
   /** Takes angle in radian and returns a copy of the vector rotated
       by \a angle */
-  Vector2f rotate(float angle) const;
+  Vector2f rotate(float angle) const
+  {
+    float len = magnitude();
+    return Vector2f(len * Math::cos(angle), len * Math::sin(angle));
+  }
 
   /// Scalar product of 2 vectors
   float operator*(const Vector2f& other) const
@@ -119,11 +124,22 @@
     return x*other.x + y*other.y;
   }
 
-  float magnitude() const;
+  float magnitude() const
+  {
+    return Math::sqrt(x*x + y*y);
+  }
   float length() const { return magnitude(); }
 
-  Vector2f unit() const;
-  void normalize();
+  Vector2f unit() const
+  {
+    return *this / magnitude();
+  }
+  void normalize()
+  {
+    float mag = magnitude();
+    x /= mag;
+    y /= mag;
+  }
 
   // ... add the other operators as needed, I'm too lazy now ...
 

Modified: trunk/pingus/src/math/vector3f.cpp
===================================================================
--- trunk/pingus/src/math/vector3f.cpp  2008-12-15 05:09:01 UTC (rev 3951)
+++ trunk/pingus/src/math/vector3f.cpp  2008-12-16 06:10:38 UTC (rev 3952)
@@ -17,114 +17,14 @@
 #include <iostream>
 #include "math.hpp"
 #include "vector3f.hpp"
-#include "vector2f.hpp"
 
-Vector3f::Vector3f(float x_, float y_, float z_) : x(x_), y(y_), z(z_)
-{
-}
-
-Vector3f::Vector3f(const Vector3f& old) : x(old.x), y(old.y), z(old.z)
-{
-}
-
-Vector3f::Vector3f(const Vector2f& old) : x(old.x), y(old.y), z(0)
-{
-}
-
-Vector3f::Vector3f(const Vector2i& old) : x(float(old.x)), y(float(old.y)), 
z(0)
-{
-}
-
-Vector3f&
-Vector3f::operator= (const Vector3f& old)
-{
-  if (this != &old)
-    {
-      x = old.x;
-      y = old.y;
-      z = old.z;
-    }
-
-  return *this;
-}
-
 Vector3f
-Vector3f::operator- () const
-{
-  return Vector3f(-x, -y, -z);
-}
-
-Vector3f
-Vector3f::operator+ (const Vector3f& add) const
-{
-  return Vector3f(x + add.x, y + add.y, z + add.z);
-}
-
-Vector3f
-Vector3f::operator- (const Vector3f& sub) const
-{
-  return Vector3f(x - sub.x, y - sub.y, z - sub.z);
-}
-
-Vector3f
-Vector3f::operator* (float mul) const
-{
-  return Vector3f(mul * x, mul * y, mul * z);
-}
-
-Vector3f&
-Vector3f::operator+= (const Vector3f& add)
-{
-  x += add.x;
-  y += add.y;
-  z += add.z;
-  return *this;
-}
-
-Vector3f&
-Vector3f::operator-= (const Vector3f& sub)
-{
-  x -= sub.x;
-  y -= sub.y;
-  z -= sub.z;
-  return *this;
-}
-
-Vector3f&
-Vector3f::operator*= (float mul)
-{
-  x *= mul;
-  y *= mul;
-  z *= mul;
-  return *this;
-}
-
-void
-Vector3f::normalize ()
-{
-  float f = Math::sqrt(x * x + y * y + z * z);
-
-  if (f)
-    {
-      x /= f;
-      y /= f;
-      z /= f;
-    }
-}
-
-float
-Vector3f::length() const
-{
-  return Math::sqrt(x * x + y * y + z * z);
-}
-
-Vector3f
 Vector3f::rotate (float angle, const Vector3f& pos) const
 {
   const float s = Math::sin(angle);
   const float c = Math::cos(angle);
 
-  return Vector3f(  x * (pos.x * pos.x * (1-c) + c)
+  return Vector3f(x * (pos.x * pos.x * (1-c) + c)
                 + y * (pos.x * pos.y * (1-c) - pos.z *s)
                + z * (pos.x * pos.z * (1-c) + pos.y *s),
 
@@ -137,32 +37,6 @@
                + z * (pos.z * pos.z * (1-c) + c)
               );
 }
-
-float
-Vector3f::distance(const Vector3f& a, const Vector3f& b)
-{
-  float x = b.x - a.x;
-  float y = b.y - a.y;
-  float z = b.z - a.z;
-
-  return Math::abs(Math::sqrt((x * x) + (y * y) + (z * z)));
-}
-
-float
-Vector3f::distance2d(const Vector3f& a, const Vector3f& b)
-{
-  float x = b.x - a.x;
-  float y = b.y - a.y;
-
-  return Math::abs(Math::sqrt((x * x) + (y * y)));
-}
-
-Vector3f
-Vector3f::interpolate(const Vector3f& a, const Vector3f& b, float perc)
-{
-  Vector3f c = b - a;
-  return a + (c * perc);
-}
 
 std::ostream& operator<<(std::ostream& os, const Vector3f& v)
 {

Modified: trunk/pingus/src/math/vector3f.hpp
===================================================================
--- trunk/pingus/src/math/vector3f.hpp  2008-12-15 05:09:01 UTC (rev 3951)
+++ trunk/pingus/src/math/vector3f.hpp  2008-12-16 06:10:38 UTC (rev 3952)
@@ -18,9 +18,9 @@
 #define HEADER_PINGUS_MATH_VECTOR3F_HPP
 
 #include <iosfwd>
-
-class Vector2f;
-class Vector2i;
+#include "math.hpp"
+#include "vector2f.hpp"
+#include "vector2i.hpp"
 
 class Vector3f
 {
@@ -30,35 +30,105 @@
   float z;
 
 public:
-  explicit Vector3f (float x_=0, float y_=0, float z_=0);
+  explicit Vector3f (float x_=0, float y_=0, float z_=0) : x(x_), y(y_), z(z_) 
{}
 
-  Vector3f (const Vector3f& old);
-  Vector3f (const Vector2f& old);
-  Vector3f (const Vector2i& old);
-  Vector3f& operator= (const Vector3f& old);
+  Vector3f (const Vector3f& old) : x(old.x), y(old.y), z(old.z) {}
+  Vector3f (const Vector2f& old) : x(old.x), y(old.y), z(0) {}
+  Vector3f (const Vector2i& old) : x(float(old.x)), y(float(old.y)), z(0) {}
+  Vector3f& operator= (const Vector3f& old)
+  {
+    if (this != &old)
+      {
+        x = old.x;
+        y = old.y;
+        z = old.z;
+      }
 
-  Vector3f operator- () const;
+    return *this;
+  }
 
-  Vector3f operator+ (const Vector3f& add) const;
-  Vector3f operator- (const Vector3f& sub) const;
-  Vector3f operator* (       float  mul) const;
+  Vector3f operator- () const
+  {
+    return Vector3f(-x, -y, -z);
+  }
 
-  Vector3f& operator+= (const Vector3f& add);
-  Vector3f& operator-= (const Vector3f& sub);
-  Vector3f& operator*= (      float   mul);
+  Vector3f operator+ (const Vector3f& add) const
+  {
+    return Vector3f(x + add.x, y + add.y, z + add.z);
+  }
+  Vector3f operator- (const Vector3f& sub) const
+  {
+    return Vector3f(x - sub.x, y - sub.y, z - sub.z);
+  }
+  Vector3f operator* (float mul) const
+  {
+    return Vector3f(mul * x, mul * y, mul * z);
+  }
 
-  void normalize ();
+  Vector3f& operator+= (const Vector3f& add)
+  {
+    x += add.x;
+    y += add.y;
+    z += add.z;
+    return *this;
+  }
+  Vector3f& operator-= (const Vector3f& sub)
+  {
+    x -= sub.x;
+    y -= sub.y;
+    z -= sub.z;
+    return *this;
+  }
+  Vector3f& operator*= (float mul)
+  {
+    x *= mul;
+    y *= mul;
+    z *= mul;
+    return *this;
+  }
 
-  float length() const;
+  void normalize ()
+  {
+    float f = Math::sqrt(x * x + y * y + z * z);
 
+    if (f)
+      {
+        x /= f;
+        y /= f;
+        z /= f;
+      }
+  }
+
+  float length() const
+  {
+    return Math::sqrt(x * x + y * y + z * z);
+  }
+
   Vector3f rotate (float angle, const Vector3f& pos) const;
 
-  static float distance(const Vector3f& a, const Vector3f& b);
-  static float distance2d(const Vector3f& a, const Vector3f& b);
+  static float distance(const Vector3f& a, const Vector3f& b)
+  {
+    float x = b.x - a.x;
+    float y = b.y - a.y;
+    float z = b.z - a.z;
 
+    return Math::abs(Math::sqrt((x * x) + (y * y) + (z * z)));
+  }
+  static float distance2d(const Vector3f& a, const Vector3f& b)
+  {
+    float x = b.x - a.x;
+    float y = b.y - a.y;
+
+    return Math::abs(Math::sqrt((x * x) + (y * y)));
+  }
+
   /** Calculate a position between a and b, relative to the value of
       \a perc (perc == 0 -> a, perc == 1.0 -> b) */
-  static Vector3f interpolate(const Vector3f& a, const Vector3f& b, float 
perc);
+  static Vector3f interpolate(const Vector3f& a, const Vector3f& b, float perc)
+  {
+    Vector3f c = b - a;
+    return a + (c * perc);
+  }
 };
 
 std::ostream& operator<< (std::ostream& os, const Vector3f& v);





reply via email to

[Prev in Thread] Current Thread [Next in Thread]