All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
PathedVehicle.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "IVehicle.h"
6 #include "Types.h"
7 #include "VectorMathDecl.h"
8 #include "Navigation.h"
9 #include "Traffic.h"
10 #include "Random.h"
11 #include "Location.h"
12 #include "Camera.h"
13 #include <string>
14 #include <vector>
15 #include <algorithm>
16 
17 namespace Eegeo
18 {
19  namespace Traffic
20  {
21  static const float DEATH_FADE_OUT_SECONDS = .5f;
22 
23  static const float CLOSE_ENOUGH_TO_TARGET_DISTANCE = 4.0;
24  static const float CLOSE_ENOUGH_DISTANCE_SQR = CLOSE_ENOUGH_TO_TARGET_DISTANCE * CLOSE_ENOUGH_TO_TARGET_DISTANCE;
25  static const float CENTER_OF_LANE_OFFSET = 0.45f;
26  static const float TURNING_ANGLE = 1.0f;
27  static const float CAR_BOUNDS_RADIUS = 10.f;
28  static const float CAR_COLLISION_RADIUS = 8.f;
29  static const float HeightCheckInterval = 1.5f;
30 
31  class PathedVehicle : public IVehicle, protected Eegeo::NonCopyable
32  {
33  public:
35  const std::string& modelName,
36  const std::string& modelNamesuffix,
37  const int beginningRoadIndex,
38  const bool drivesOnRight,
39  const Config::TrafficSimulationRoadClassFilter& roadClassFilter,
40  const TrafficSimulationCellsModel* cellsModel,
41  Eegeo::Random* random,
42  float velocity,
43  float scale,
44  float closeEnoughDistSq=CLOSE_ENOUGH_DISTANCE_SQR,
45  float centerOfLaneOffset=CENTER_OF_LANE_OFFSET,
46  float turningAngle=TURNING_ANGLE);
47 
48  ~PathedVehicle() {};
49 
50  const Eegeo::dv3& GetWorldPosition() const { return m_worldPosition; }
51  const Eegeo::v3& GetForwardsVector() const { return m_forwards; }
52  const std::string& GetFullModelNodeName() const { return m_fullModelNodeName; }
53  TrafficSimulationCell* GetNextCell() { return m_nextCellToTravelTo; }
54  bool GetInitialised() { return m_initialised; }
55  void ClearNextCell() { m_nextCellToTravelTo = NULL; }
56  void Update(float elapsedSeconds, float speedMultiplier, const dv3& ecefInterestPoint);
57  void Initialise(const dv3& ecefInterestPoint);
58 
59  void UpdateVelocity(float velocity) { m_velocity = velocity; }
60  float GetDistanceToEndOfCurrentPath();
61  bool IsOnFinalRoadInPath(float& out_distanceToEnd);
62  bool GetVehicleOnDeadEnd();
63  float Alpha() { return std::max(1.0f - m_deathCeremonyTimePassedSeconds/DEATH_FADE_OUT_SECONDS, 0.f); }
64  bool VehicleMarkedToRemove() { return m_deathCeremonyTimePassedSeconds >= DEATH_FADE_OUT_SECONDS; }
65 
66  float GetBoundsRadius() const;
67  float GetScale() const;
68 
69  void FadeOutThenDestroyVehicle();
70  bool IsPlayingDeathCeremony() { return m_playingDeathCeremony; }
71 
72  float GetCollisionRadius() const;
73 
74  bool CanCollide() const;
75 
76  void SetModelNodeNameSuffix(const std::string &suffix);
77 
78  bool IsUnderground() const;
79  void SetIsUnderground(bool isUnderground);
80  bool NeedsUndergroundCheck();
81 
82  private:
83  float m_velocity;
84  float m_scale;
85  const float m_closeEnoughDistSq;
86  const float m_centerOfLaneOffset;
87  const float m_turningAngle;
88  bool m_expectPathToEndInDeadEnd;
89 
90  float m_deathCeremonyTimePassedSeconds;
91  bool m_dieAtEndOfPath;
92  bool m_playingDeathCeremony;
93 
94  Eegeo::v3 m_localPosition;
95  Eegeo::dv3 m_worldPosition;
96  Eegeo::v3 m_forwards;
97  bool m_directionIsForwards;
98  Eegeo::Random* const m_random;
99  const Config::TrafficSimulationRoadClassFilter& m_roadClassFilter;
100 
101  const TrafficSimulationCellsModel* m_cellsModel;
103  TrafficSimulationCell* m_nextCellToTravelTo;
104  std::vector<TrafficPathNode> m_pathNodes;
105  const std::string& m_modelName;
106  std::string m_fullModelNodeName;
107  bool m_drivesOnRight;
108 
109  bool m_onFirstPath;
110  bool m_initialised;
111 
112  int m_currentPathNodeIndex;
113  int m_finalRoadIndex;
114  int m_finalVertIndex;
115 
116  float m_heightCheckTimer;
117  bool m_isUnderground;
118 
119  std::vector<int> m_debugUsedRoadIndices;
120 
121  std::vector<Resources::Roads::Navigation::NavigationGraphRoad*> m_recentMemory;
122  size_t m_recentMemoryRingLatest;
123 
124  void CreateNewPath(const int initialRoadIndex, const dv3& ecefInterestPoint);
125  void ResetToStartOfPath();
126 
127  void CheckLeavingCell(Resources::Roads::Navigation::NavigationGraphRoad*& currentRoad,
128  int &currentPoint,
129  bool &currentDirectionIsForwards);
130 
131  bool MovePathGenToNextRoad(Resources::Roads::Navigation::NavigationGraphRoad*& currentRoad,
132  int &currentPoint,
133  bool &currentDirectionIsForwards,
134  bool atRoadEnd,
135  std::vector<int> &usedRoadIndices,
136  Eegeo::v3* pathFindCurrentForward,
137  const dv3& ecefInterestPoint);
138 
139  bool IsInCamera(const Camera::RenderCamera& renderCamera);
140  };
141  }
142 }