Umasoft
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Groups Pages
CarEngine.h
1 //
2 // CarEngine.h
3 // header file for CarEngine.cpp
4 //
5 // Copyright (c) 2001-2011 Virtual Terrain Project
6 // Free for all uses, see license.txt for details.
7 //
8 
9 #ifndef CARENGINEH
10 #define CARENGINEH
11 
12 #include "vtdata/HeightField.h"
13 #include "Vehicles.h"
14 
15 enum CarEngineMode { NONE, JUST_DRIVE, FOLLOW_ROAD, FOLLOW_PATH };
16 
17 class CarEngine : public vtEngine
18 {
19 public:
20  CarEngine(Vehicle *vehicle, vtHeightField3d *hf);
21 
22  bool Valid();
23  void Eval();
24  void IgnoreElapsedTime();
25 
26  FPoint3 GetCurPos() { return m_vCurPos; }
27  void SetEarthPos(const DPoint2 &pos);
28  DPoint2 GetEarthPos();
29 
30  void SetSpeed(float fMeterPerSec);
31 
32  void SetRotation(float fRot);
33  float GetRotation() { return m_fCurRotation; }
34 
35  void SetSteeringAngle(float fRadians) { m_fSteeringAngle = fRadians; }
36  void SetFriction(float factor) { m_fFriction = factor; }
37 
38  void SetCameraFollow(bool bOn) { m_bCameraFollow = bOn; }
39  void SetCameraDistance(float fMeters) { m_bCameraDistance = fMeters; }
40 
41 protected:
42  void ApplyCurrentLocation(bool bAlignOnGround);
43 
44  float SetPitch(); //returns new height for car.
45 
46  //move car to the given vector
47  //change rotation about Y axis based on current and next position.
48  //height is average of tire points
49  void MoveCarTo(const FPoint3 &pos);
50 
51  //spin all wheels for distance traveled.
52  void SpinWheels(float radians);
53 
54  vtHeightField3d *m_pHeightField;
55 
56  //what mode the engine is operating at.
57  CarEngineMode m_eMode;
58 
59  FPoint3 m_vCurPos; // current position
60  float m_fCurRotation; // rotation around Y axis(Yaw)
61  float m_fCurPitch; // rotation around orientation axis (Pitch)
62  FPoint3 m_vAxis; // orientation axis, determined by where wheels are w/respect to ground
63 
64  float m_fSpeed; // speed in meters per second
65  float m_fTargetSpeed; // target speed
66  float m_fPrevTime; // last time that eval was run on.
67 
68  //tires
69  vtTransform *FrontLeft() { return m_pVehicle->m_pFrontLeft; }
70  vtTransform *FrontRight() { return m_pVehicle->m_pFrontRight; }
71  vtTransform *RearLeft() { return m_pVehicle->m_pRearLeft; }
72  vtTransform *RearRight() { return m_pVehicle->m_pRearRight; }
73 
74  float m_fSteeringAngle;
75  float m_fFriction;
76 
77  //a setup flag - first eval doesn't run right...
78  bool m_bFirstTime;
79 
80  bool m_bCameraFollow;
81  float m_bCameraDistance;
82 
83  Vehicle *m_pVehicle;
84 };
85 typedef osg::ref_ptr<CarEngine> CarEnginePtr;
86 
87 
88 #endif // CARENGINEH