00001 00005 /* Copyright © 2009 James Legg. 00006 This program is free software: you can redistribute it and/or modify 00007 it under the terms of the GNU General Public License as published by 00008 the Free Software Foundation, either version 3 of the License, or 00009 (at your option) any later version. 00010 */ 00011 #ifndef LIBTRACK_TRACKMESH_H_ 00012 #define LIBTRACK_TRACKMESH_H_ 00013 00014 #include "Mesh/MeshFaces.h" 00015 #include "PieceDistortion.h" 00016 #include "SegmentConnection.h" 00017 #include <Debug.h> 00018 00019 #include <vector> 00020 #include <istream> 00021 #include <limits> 00022 00023 #include <boost/shared_ptr.hpp> 00024 00025 namespace Track 00026 { 00027 00036 template <class T = MeshFaces> 00037 class TrackMesh 00038 { 00039 public: 00043 TrackMesh(std::istream & source); 00044 00045 virtual ~TrackMesh(); 00046 00050 btScalar get_maximum_bend() const; 00051 00054 btScalar get_length() const; 00055 00058 btScalar get_minimum_y() const; 00059 00063 T get_distorted_faces(PieceDistortion piece_distortion) const; 00064 00071 T get_distorted_faces(btTransform tranform) const; 00072 00075 const T & get_faces() const; 00076 protected: 00081 float maximum_bend; 00082 00084 float length; 00085 00087 btScalar minimum_y; 00088 00090 btScalar maximum_y; 00091 00093 T mesh; 00094 }; 00095 00096 template <class T> 00097 TrackMesh<T>::TrackMesh(std::istream & source) 00098 : minimum_y(std::numeric_limits<btScalar>::max()) 00099 , maximum_y(std::numeric_limits<btScalar>::min()) 00100 , mesh(source) 00101 { 00102 // Calculate the length. 00103 std::size_t number_of_vertices = mesh.get_num_vertices(); 00104 for (std::size_t vertex_index = 0; 00105 vertex_index < number_of_vertices; 00106 vertex_index++) 00107 { 00108 btScalar y = mesh.get_vertex_pos(vertex_index).getY(); 00109 if (minimum_y > y) minimum_y = y; 00110 if (maximum_y < y) maximum_y = y; 00111 } 00112 length = maximum_y - minimum_y; 00114 DEBUG_MESSAGE("Loaded Track::TrackMesh"); 00115 } 00116 00117 template <class T> 00118 TrackMesh<T>::~TrackMesh() 00119 { 00120 } 00121 00122 template <class T> 00123 btScalar TrackMesh<T>::get_maximum_bend() const 00124 { 00125 return maximum_bend; 00126 } 00127 00128 template <class T> 00129 btScalar TrackMesh<T>::get_length() const 00130 { 00131 return length; 00132 } 00133 00134 template <class T> 00135 btScalar TrackMesh<T>::get_minimum_y() const 00136 { 00137 return minimum_y; 00138 } 00139 00140 template <class T> 00141 T TrackMesh<T>::get_distorted_faces(PieceDistortion piece_distortion) const 00142 { 00143 T result; 00144 for (unsigned int vert_index = 0; 00145 vert_index < mesh.get_num_vertices(); 00146 vert_index++) 00147 { 00148 result.add_vertex(piece_distortion(mesh.get_vertex_pos(vert_index))); 00149 } 00150 // now copy the faces. 00151 result.copy_faces(mesh); 00152 return result; 00153 } 00154 00155 template <class T> 00156 const T & TrackMesh<T>::get_faces() const 00157 { 00158 return mesh; 00159 } 00160 00161 template <class T> 00162 T TrackMesh<T>::get_distorted_faces(btTransform transform) const 00163 { 00164 T result; 00165 for (unsigned int vert_index = 0; 00166 vert_index < mesh.get_num_vertices(); 00167 vert_index++) 00168 { 00169 result.add_vertex(transform(mesh.get_vertex_pos(vert_index))); 00170 } 00171 // now copy the faces. 00172 result.copy_faces(mesh); 00173 return result; 00174 } 00175 00176 } 00177 00178 #endif /*TRACKMESH_H_*/
Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.