]> git.tdb.fi Git - libs/math.git/blobdiff - source/geometry/ray.h
Beginnings of a geometry library
[libs/math.git] / source / geometry / ray.h
diff --git a/source/geometry/ray.h b/source/geometry/ray.h
new file mode 100644 (file)
index 0000000..4825cfe
--- /dev/null
@@ -0,0 +1,39 @@
+#ifndef MSP_GEOMETRY_RAY_H_
+#define MSP_GEOMETRY_RAY_H_
+
+#include <msp/linal/vector.h>
+
+namespace Msp {
+namespace Geometry {
+
+template<typename T, unsigned D>
+class Ray
+{
+private:
+       LinAl::Vector<T, D> start;
+       LinAl::Vector<T, D> direction;
+
+public:
+       Ray();
+       Ray(const LinAl::Vector<T, D> &, const LinAl::Vector<T, D> &);
+
+       const LinAl::Vector<T, D> &get_start() const { return start; }
+       const LinAl::Vector<T, D> &get_direction() const { return direction; }
+};
+
+template<typename T, unsigned D>
+Ray<T, D>::Ray()
+{
+       direction[0] = 1;
+}
+
+template<typename T, unsigned D>
+Ray<T, D>::Ray(const LinAl::Vector<T, D> &s, const LinAl::Vector<T, D> &d):
+       start(s),
+       direction(normalize(d))
+{ }
+
+} // namespace Geometry
+} // namespace Msp
+
+#endif