Segment.cpp

Go to the documentation of this file.
00001 
00005 /* Copyright © 2009, 2010 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 #include "Segment.h"
00012 #include "stream_loader.h"
00013 
00014 namespace Track
00015 {
00016 
00017 Segment::Segment(std::istream & source)
00018     // load the texture for the graphics
00019     : texture(source)
00020     // load the meshes
00021     , graphics_mesh(source)
00022     , ai_floor_mesh(source)
00023     , physics_wall_mesh(source)
00024     , physics_floor_mesh(source)
00025     , name(string_from_stream(source))
00026 {
00027     DEBUG_MESSAGE("Track::Segment::Segment(std::istream &) body beginning");
00028     // load SegmenetConnections
00029     fill_vector_from_stream(connections, source);
00030     DEBUG_MESSAGE("Loaded Track::Segment");
00031     
00032     // Decide if the segment will behave acceptably when used for edges.
00033     m_edges_allowed = false;
00034     if (connections.size() == 2)
00035     {
00036         if (connections[0]->get_cross_section_id() == connections[1]->get_cross_section_id())
00037         {
00038             // If the length of the mesh is near the distance between the
00039             // connections, the segment should be ok on an edge.
00040             // Otherwise it is probably a corner piece.
00041             btScalar distance2 = connections[0]->get_transform().getOrigin().
00042                 distance2(connections[1]->get_transform().getOrigin());
00043             btScalar length2 = ai_floor_mesh.get_length();
00044             length2 *= length2;
00045             if (distance2 > length2 - 0.01 && distance2 < length2 + 0.01)
00046             {
00047                 m_edges_allowed = true;
00048             }
00049         }
00050     }
00051 }
00052 
00053 Segment::~Segment()
00054 {
00055 }
00056 
00057 const std::string & Segment::get_name() const
00058 {
00059     return name;
00060 }
00061 
00062 std::size_t Segment::get_number_of_connections() const
00063 {
00064     return connections.size();
00065 }
00066 
00067 const SegmentConnection & Segment::get_connection(std::size_t index) const
00068 {
00069     return *(connections[index]);
00070 }
00071 
00072 const TrackMesh<DrawableMesh> & Segment::get_graphics_mesh() const
00073 {
00074     return graphics_mesh;
00075 }
00076 
00077 const TrackMesh<> & Segment::get_ai_mesh() const
00078 {
00079     return ai_floor_mesh;
00080 }
00081 
00082 const TrackMesh<> & Segment::get_floor_mesh() const
00083 {
00084     return physics_floor_mesh;
00085 }
00086 
00087 const TrackMesh<> & Segment::get_wall_mesh() const
00088 {
00089     return physics_wall_mesh;
00090 }
00091 
00092 btScalar Segment::get_length() const
00093 {
00094     return physics_floor_mesh.get_length();
00095 }
00096 
00097 btScalar Segment::get_minimum_y() const
00098 {
00099     return physics_floor_mesh.get_minimum_y();
00100 }
00101 
00102 
00103 const Texture & Segment::get_texture() const
00104 {
00105     return texture;
00106 }
00107 
00108 bool Segment::edges_allowed() const
00109 {
00110     return m_edges_allowed;
00111 }
00112 
00113 }

Get Racer at SourceForge.net. Fast, secure and Free Open Source software downloads

Generated at Mon Sep 6 00:41:12 2010 by Doxygen version 1.4.7 for Racer version svn335.