Project::OSiRiON - Git repositories
Project::OSiRiON
News . About . Screenshots . Downloads . Forum . Wiki . Tracker . Git
summaryrefslogtreecommitdiff
path: root/src/math
diff options
context:
space:
mode:
Diffstat (limited to 'src/math')
-rw-r--r--src/math/color.cc11
-rw-r--r--src/math/color.h2
-rw-r--r--src/math/vector3f.cc31
-rw-r--r--src/math/vector3f.h27
4 files changed, 48 insertions, 23 deletions
diff --git a/src/math/color.cc b/src/math/color.cc
index b0c3f65..9a07b7c 100644
--- a/src/math/color.cc
+++ b/src/math/color.cc
@@ -95,4 +95,15 @@ std::ostream &operator<<(std::ostream &os, const Color &c)
return os;
}
+std::istream &operator>>(std::istream & is, Color & color)
+{
+ float r, g, b, a;
+ is >> r;
+ is >> g;
+ is >> b;
+ is >> a;
+ color = Color(r,g,b,a);
+ return (is);
+}
+
} // namespace math
diff --git a/src/math/color.h b/src/math/color.h
index 33efcfc..078faaa 100644
--- a/src/math/color.h
+++ b/src/math/color.h
@@ -45,6 +45,8 @@ private:
std::ostream &operator<<(std::ostream &os, const Color &c);
+std::istream &operator>>(std::istream & is, Color & color);
+
Color operator*(const float scalar, const Color& color);
} // namespace math
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index 277795b..ddf46af 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -106,14 +106,6 @@ Vector3f Vector3f::operator+(const Vector3f& other) const
return (r);
}
-float Vector3f::operator*(const Vector3f& other) const
-{
- float r = 0;
- for (int i=0; i < 3; i++)
- r += coord[i] * other.coord[i];
- return (r);
-}
-
bool Vector3f::operator==(const Vector3f& other) const
{
for (int i=0; i < 3; i++)
@@ -144,7 +136,21 @@ void Vector3f::normalize()
(*this) /= this->length();
}
-std::ostream &operator<<(std::ostream & os, const Vector3f & vector)
+Vector3f operator*(float scalar, const Vector3f& vector)
+{
+ return vector * scalar;
+}
+
+Vector3f crossproduct(const Vector3f& first, const Vector3f& second)
+{
+ float x = first[1]*second[2] - first[2]*second[1];
+ float y = first[2]*second[0] - first[0]*second[2];
+ float z = first[0]*second[1] - first[1]*second[0];
+
+ return(Vector3f(x,y,z));
+}
+
+std::ostream &operator<<(std::ostream & os, Vector3f const & vector)
{
os << vector[0] << " " << vector[1] << " " << vector[2];
return os;
@@ -157,9 +163,12 @@ std::istream &operator>>(std::istream & is, Vector3f & vector)
return is;
}
-Vector3f operator*(float scalar, const Vector3f& vector)
+float dotproduct(const Vector3f& first, const Vector3f& second)
{
- return vector * scalar;
+ float r = 0;
+ for (int i=0; i < 3; i++)
+ r += first[i] * second[i];
+ return (r);
}
} // namespace math
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index cc318b0..d338f50 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -60,7 +60,7 @@ public:
/// perform an element-wise subtraction
Vector3f& operator-=(const Vector3f &other);
- /// perform ann element-wise addition
+ /// perform an element-wise addition
Vector3f& operator+=(const Vector3f &other);
/* -- Mathematical operators -- */
@@ -74,12 +74,9 @@ public:
/// return the element-wise difference between two vectors
Vector3f operator-(const Vector3f &other) const;
- /// return the element-wise sumn of two vectors
+ /// return the element-wise sum of two vectors
Vector3f operator+(const Vector3f &other) const;
- /// return the vector cross-product
- float operator*(const Vector3f &other) const;
-
/// comparison operator
bool operator==(const Vector3f &other) const;
@@ -99,10 +96,6 @@ public:
return coord[index];
}
- float &x;
- float &y;
- float &z;
-
/// Return the cartesian length of this vector
float length() const;
@@ -133,18 +126,28 @@ public:
/// WARNING: vector must not be (0, 0, 0)
static inline Vector3f normalized(const Vector3f& vector) { return (vector / vector.length()); }
+ float &x;
+ float &y;
+ float &z;
+
float coord[3];
};
/// Write a Vector3f to a std::ostream
-std::ostream &operator<<(std::ostream & os, const Vector3f & vector);
+std::ostream &operator<<(std::ostream & os, Vector3f const & vector);
/// Read a Vector3d from a std::istream
-std::istream &operator>>(std::istream & is, Vector3f& vector);
+std::istream &operator>>(std::istream & is, Vector3f & vector);
-/// scalar*Vector3f operators
+/// scalar * Vector3f operators
Vector3f operator*(float scalar, const Vector3f& vector);
+/// vector cross product
+const Vector3f crossproduct(Vector3f const& first, Vector3f const second);
+
+/// vetor dot product
+float dotproduct(const Vector3f& first, const Vector3f& second);
+
} // namespace Math
#endif // __INCLUDED_MATH_VECTOR3F_H__