]> git.tdb.fi Git - r2c2.git/blobdiff - source/libr2c2/track.cpp
Use raycasting instead of OpenGL selection mode to pick tracks
[r2c2.git] / source / libr2c2 / track.cpp
index 0d4052ea999a83b6394bb79f7d03f9216604fc39..b2d3e63af703031446d86e5fe5986b1f7e8664fd 100644 (file)
@@ -1,7 +1,7 @@
 /* $Id$
 
 This file is part of R²C²
-Copyright © 2006-2010  Mikkosoft Productions, Mikko Rasa
+Copyright © 2006-2011  Mikkosoft Productions, Mikko Rasa
 Distributed under the GPL
 */
 
@@ -333,6 +333,19 @@ TrackPoint Track::get_point(unsigned epi, float d) const
        return get_point(epi, active_path, d);
 }
 
+bool Track::collide_ray(const Vector &start, const Vector &ray)
+{
+       Vector local_start(start.x-pos.x, start.y-pos.y, start.z-pos.z);
+       float c = cos(rot);
+       float s = sin(rot);
+       local_start = Vector(c*local_start.x+s*local_start.y, c*local_start.y-s*local_start.x, local_start.z);
+       Vector local_ray(c*ray.x+s*ray.y, c*ray.y-s*ray.x, ray.z);
+
+       float width = layout.get_catalogue().get_ballast_profile().get_width();
+
+       return type.collide_ray(local_start, local_ray, width);
+}
+
 void Track::save(list<DataFile::Statement> &st) const
 {
        st.push_back((DataFile::Statement("position"), pos.x, pos.y, pos.z));