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-02 12:23:48 +0000
committerStijn Buys <ingar@osirion.org>2008-03-02 12:23:48 +0000
commit81787e9004377016236865e95b95707ed6cf1d0b (patch)
treeb8a7bd0d51f97848ad98ec8c8f5e424de910df32 /src/math
parent1d45d8ecb4633f07a0ff163255dbedc3c3a72ac8 (diff)
initial (buggy) support for .map models
Diffstat (limited to 'src/math')
-rw-r--r--src/math/Makefile.am4
-rw-r--r--src/math/mathlib.h3
-rw-r--r--src/math/plane3f.cc32
-rw-r--r--src/math/plane3f.h50
-rw-r--r--src/math/vector3f.cc19
-rw-r--r--src/math/vector3f.h2
6 files changed, 96 insertions, 14 deletions
diff --git a/src/math/Makefile.am b/src/math/Makefile.am
index c1f1f88..a622ba7 100644
--- a/src/math/Makefile.am
+++ b/src/math/Makefile.am
@@ -1,9 +1,9 @@
METASOURCES = AUTO
-libmath_la_SOURCES = color.cc functions.cc vector3f.cc
+libmath_la_SOURCES = color.cc functions.cc plane3f.cc vector3f.cc
libmath_la_LDFLAGS = -avoid-version -no-undefined -lm
noinst_LTLIBRARIES = libmath.la
-noinst_HEADERS = color.h functions.h mathlib.h vector3f.h
+noinst_HEADERS = color.h functions.h mathlib.h plane3f.h vector3f.h
INCLUDES = -I$(top_srcdir)/src
diff --git a/src/math/mathlib.h b/src/math/mathlib.h
index ca5b7f4..b76c562 100644
--- a/src/math/mathlib.h
+++ b/src/math/mathlib.h
@@ -1,5 +1,5 @@
/*
- math/math.h
+ math/mathlib.h
This file is part of the Osirion project and is distributed under
the terms of the GNU General Public License version 2
*/
@@ -13,6 +13,7 @@
namespace math {}
#include "math/vector3f.h"
+#include "math/plane3f.h"
#include "math/color.h"
#include "math/functions.h"
diff --git a/src/math/plane3f.cc b/src/math/plane3f.cc
new file mode 100644
index 0000000..232bc98
--- /dev/null
+++ b/src/math/plane3f.cc
@@ -0,0 +1,32 @@
+/*
+ math/plane3f.cc
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#include "math/plane3f.h"
+#include <string>
+
+namespace math
+{
+
+Plane3f::Plane3f(Vector3f const & point0, Vector3f const &point1, Vector3f const &point2)
+{
+ plane_point[0] = point0;
+ plane_point[1] = point1;
+ plane_point[2] = point2;
+
+ plane_normal = crossproduct((plane_point[1] - plane_point[0]) , (plane_point[2] - plane_point[0]) );
+ pd = -1 * (plane_normal.x * plane_point[0].x + plane_normal.y * plane_point[0].y + plane_normal.z * plane_point[0].z);
+}
+
+Plane3f::Plane3f(Plane3f const & other)
+{
+ for (size_t i=0; i < 3; i++)
+ this->plane_point[i] = other.plane_point[i];
+
+ plane_normal = crossproduct((plane_point[1] - plane_point[0]) , (plane_point[2] - plane_point[0]) );
+ pd = -1 * (plane_normal.x * plane_point[0].x + plane_normal.y * plane_point[0].y + plane_normal.z * plane_point[0].z);
+}
+
+}
diff --git a/src/math/plane3f.h b/src/math/plane3f.h
new file mode 100644
index 0000000..ddaef16
--- /dev/null
+++ b/src/math/plane3f.h
@@ -0,0 +1,50 @@
+/*
+ math/plane3f.h
+ This file is part of the Osirion project and is distributed under
+ the terms of the GNU General Public License version 2
+*/
+
+#ifndef __INCLUDED_MATH_PLANE3F_H__
+#define __INCLUDED_MATH_PLANE3F_H__
+
+#include "math/vector3f.h"
+
+namespace math
+{
+
+/** @brief A class representing a plane in 3d space
+ * all points p(x, y, z) on the plane satisfy the general equation
+ * x*a() + y*b() + z*c() + d() = 0
+ */
+class Plane3f
+{
+public:
+ /// a plane defined by 3 points in space
+ Plane3f(Vector3f const & point0, Vector3f const &point1, Vector3f const &point2);
+ /// copy constructor
+ Plane3f(Plane3f const & other);
+
+ /// normal of the plane, not normalized to lenght 1
+ inline Vector3f const & normal() const { return plane_normal; }
+ /// the points defining the plane.
+ /// @param i 0 <= i < 3
+ inline Vector3f const & point(size_t i) const { return plane_point[i]; }
+
+ /// first parameter of the general equation
+ inline float a() const { return plane_normal[0]; }
+ /// second parameter of the general equation
+ inline float b() const { return plane_normal[1]; }
+ /// third param of the general equation
+ inline float c() const { return plane_normal[2]; }
+ /// fourth parameter of the general equation
+ inline float d() const { return pd; }
+
+private:
+ Vector3f plane_point[3];
+ Vector3f plane_normal;
+ float pd;
+};
+
+}
+
+#endif // __INCLUDED_MATH_PLANE3F_H__
diff --git a/src/math/vector3f.cc b/src/math/vector3f.cc
index ddf46af..371ada1 100644
--- a/src/math/vector3f.cc
+++ b/src/math/vector3f.cc
@@ -141,15 +141,6 @@ 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];
@@ -163,6 +154,15 @@ std::istream &operator>>(std::istream & is, Vector3f & vector)
return is;
}
+const Vector3f crossproduct(Vector3f const & first, Vector3f const& 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));
+}
+
float dotproduct(const Vector3f& first, const Vector3f& second)
{
float r = 0;
@@ -170,5 +170,4 @@ float dotproduct(const Vector3f& first, const Vector3f& second)
r += first[i] * second[i];
return (r);
}
-
} // namespace math
diff --git a/src/math/vector3f.h b/src/math/vector3f.h
index d338f50..c2ebc6a 100644
--- a/src/math/vector3f.h
+++ b/src/math/vector3f.h
@@ -143,7 +143,7 @@ std::istream &operator>>(std::istream & is, Vector3f & vector);
Vector3f operator*(float scalar, const Vector3f& vector);
/// vector cross product
-const Vector3f crossproduct(Vector3f const& first, Vector3f const second);
+const Vector3f crossproduct(Vector3f const & first, Vector3f const & second);
/// vetor dot product
float dotproduct(const Vector3f& first, const Vector3f& second);