]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/geometry.h
Instantly set turnout paths when loading state
[r2c2.git] / source / libr2c2 / geometry.h
index 48bbd49eeb98736b5274dbd50ec91d723649b8be..dc29212735fa806b8c9fb79668c20bb5a735a19c 100644 (file)
@@ -1,37 +1,40 @@
-/* $Id$
-
-This file is part of R²C²
-Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
-Distributed under the GPL
-*/
-
 #ifndef LIBR2C2_GEOMETRY_H_
 #define LIBR2C2_GEOMETRY_H_
 
 #include <cmath>
 #include <vector>
+#include <msp/geometry/affinetransformation.h>
+#include <msp/geometry/angle.h>
+#include <msp/geometry/ray.h>
+#include <msp/geometry/shape.h>
+#include <msp/linal/vector.h>
 
 namespace R2C2 {
 
-struct Point
-{
-       float x, y, z;
+typedef Msp::LinAl::Vector<float, 3> Vector;
 
-       Point(): x(0), y(0), z(0) { }
-       Point(float x_, float y_): x(x_), y(y_), z(0) { }
-       Point(float x_, float y_, float z_): x(x_), y(y_), z(z_) { }
-};
+inline float distance(const Vector &p, const Vector &q)
+{ return (p-q).norm(); }
 
-inline float distance(const Point &p, const Point &q)
-{ return sqrt((p.x-q.x)*(p.x-q.x) + (p.y-q.y)*(p.y-q.y) + (p.z-q.z)*(p.z-q.z)); }
+typedef Msp::Geometry::Angle<float> Angle;
 
-struct TrackPoint
-{
-       Point pos;
-       float dir;
-       float grade;
+typedef Msp::Geometry::AffineTransformation<float, 3> Transform;
 
-       TrackPoint(): dir(0), grade(0) { }
+inline Vector rotated_vector(const Vector &v, const Angle &a)
+{ return Transform::rotation(a, Vector(0, 0, 1)).transform(v); }
+
+inline Vector vector_at_angle(const Angle &a)
+{ return rotated_vector(Vector(1, 0, 0), a); }
+
+typedef Msp::Geometry::Shape<float, 3> Shape;
+typedef Msp::Geometry::Ray<float, 3> Ray;
+typedef Msp::Geometry::BoundingBox<float, 3> BoundingBox;
+
+struct OrientedPoint
+{
+       Vector position;
+       Angle rotation;
+       Angle tilt;
 };
 
 } // namespace R2C2