All Classes Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Pages
TrainVehicle.h
1 // Copyright eeGeo Ltd (2012-2014), All Rights Reserved
2 
3 #pragma once
4 
5 #include "VectorMath.h"
6 #include "IVehicle.h"
7 #include "Types.h"
8 #include "PathedVehicle.h"
9 #include <string>
10 
11 #include <deque>
12 
13 namespace Eegeo
14 {
15  namespace Traffic
16  {
17  static const float TRAIN_CLOSE_ENOUGH_TO_TARGET_DISTANCE = 10.0;
18  static const float TRAIN_CLOSE_ENOUGH_DISTANCE_SQR = TRAIN_CLOSE_ENOUGH_TO_TARGET_DISTANCE * TRAIN_CLOSE_ENOUGH_TO_TARGET_DISTANCE;
19  static const float TRAIN_DISTANCE_FROM_DEAD_END_TO_STOP = 5.0f;
20  static const float TRAIN_CENTER_OF_LANE_OFFSET = 0.55f;
21  static const float TRAIN_TURNING_ANGLE = 1.5f;
22  static const float TRAIN_CARRIAGE_SEPARATION = 3.65f;
23  static const float TRAIN_BOUNDS_RADIUS = 15.f;
24 
26  {
27  Eegeo::dv3 position;
28  Eegeo::v3 dir;
29  float distance;
30 
32  : position(Eegeo::dv3::Zero())
33  , dir(Eegeo::v3::Zero())
34  , distance(0)
35  {
36  }
37  };
38 
39  class TrainVehicle : public IVehicle, protected Eegeo::NonCopyable
40  {
41  private:
42  static const float TRAIN_FADE_OUT_IN_SECONDS;
43 
44  float TrainLengthInM() const;
45  float SecondsToFullySpawn();
46 
47  std::deque<TrainPreviousPosition> m_previousPostions;
48 
49  float m_secondsSinceDespawning;
50  float m_secondsSinceSpawning;
51  bool m_playingDeathCeremony;
52  const float m_defaultVelocity;
53  float m_trainLength;
54 
55  PathedVehicle* m_pathedVehicle;
56 
57  public:
58  TrainVehicle(PathedVehicle* pathedVehicle, float velocity, float headVehicleLength);
59  ~TrainVehicle();
60  const Eegeo::dv3& GetWorldPosition() const { return m_pathedVehicle->GetWorldPosition(); }
61  const Eegeo::v3& GetForwardsVector() const { return m_pathedVehicle->GetForwardsVector(); }
62 
63  const std::string& GetFullModelNodeName() const { return m_pathedVehicle->GetFullModelNodeName(); }
64  TrafficSimulationCell* GetNextCell() { return m_pathedVehicle->GetNextCell(); }
65 
66  bool GetInitialised() { return m_pathedVehicle->GetInitialised(); }
67  void ClearNextCell() { m_pathedVehicle->ClearNextCell(); }
68  void Update(float elapsedSeconds, float speedMultiplier, const dv3& ecefInterestPoint);
69  void Initialise(const dv3& ecefInterestPoint) { m_pathedVehicle->Initialise(ecefInterestPoint); }
70 
71  TrainPreviousPosition GetPreviousCarriagePosition(float carriageDistanceFromHead) const;
72 
73  void AddCarriage(TrainCarriage* carriage, float carriageLength);
74  float Alpha();
75  bool VehicleMarkedToRemove();
76  void FadeOutThenDestroyVehicle();
77  bool IsPlayingDeathCeremony();
78 
79  bool CanCollide() const;
80 
81  float GetCollisionRadius() const;
82  float GetBoundsRadius() const;
83  float GetScale() const;
84 
85  void SetModelNodeNameSuffix(const std::string &suffix) { m_pathedVehicle->SetModelNodeNameSuffix(suffix);}
86 
87  bool IsUnderground() const;
88  bool NeedsUndergroundCheck();
89  void SetIsUnderground(bool isUnderground);
90  };
91  }
92 }