Starshatter_Open
Open source Starshatter engine
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Macros
Physical.h
Go to the documentation of this file.
1 /* Project nGenEx
2  Destroyer Studios LLC
3  Copyright © 1997-2004. All Rights Reserved.
4 
5  SUBSYSTEM: nGenEx.lib
6  FILE: Physical.h
7  AUTHOR: John DiCamillo
8 
9 
10  OVERVIEW
11  ========
12  Abstract Physical Object
13 */
14 
15 #ifndef Physical_h
16 #define Physical_h
17 
18 #include "Types.h"
19 #include "Geometry.h"
20 #include "Camera.h"
21 
22 // +--------------------------------------------------------------------+
23 
24 class Director;
25 class Graphic;
26 class Light;
27 
28 // +--------------------------------------------------------------------+
29 
30 class Physical
31 {
32 public:
33  static const char* TYPENAME() { return "Physical"; }
34 
35  Physical();
36  Physical(const char* n, int t=0);
37  virtual ~Physical();
38 
39  int operator == (const Physical& p) const { return id == p.id; }
40 
41  // Integration Loop Control:
42  static void SetSubFrameLength(double seconds) { sub_frame = seconds; }
43  static double GetSubFrameLength() { return sub_frame; }
44 
45  // operations
46  virtual void ExecFrame(double seconds);
47  virtual void AeroFrame(double seconds);
48  virtual void ArcadeFrame(double seconds);
49 
50  virtual void AngularFrame(double seconds);
51  virtual void LinearFrame(double seconds);
52 
53  virtual void CalcFlightPath();
54 
55  virtual void MoveTo(const Point& new_loc);
56  virtual void TranslateBy(const Point& ref);
57  virtual void ApplyForce(const Point& force);
58  virtual void ApplyTorque(const Point& torque);
59  virtual void SetThrust(double t);
60  virtual void SetTransX(double t);
61  virtual void SetTransY(double t);
62  virtual void SetTransZ(double t);
63  virtual void SetHeading(double r, double p, double y);
64  virtual void LookAt(const Point& dst);
65  virtual void ApplyRoll(double roll_acc);
66  virtual void ApplyPitch(double pitch_acc);
67  virtual void ApplyYaw(double yaw_acc);
68 
69  virtual int CollidesWith(Physical& o);
70  static void ElasticCollision(Physical& a, Physical& b);
71  static void InelasticCollision(Physical& a, Physical& b);
72  static void SemiElasticCollision(Physical& a, Physical& b);
73  virtual void InflictDamage(double damage, int type = 0);
74 
75  // accessors:
76  int Identity() const { return id; }
77  int Type() const { return obj_type; }
78  const char* Name() const { return name; }
79 
80  Point Location() const { return cam.Pos(); }
81  Point Heading() const { return cam.vpn(); }
82  Point LiftLine() const { return cam.vup(); }
83  Point BeamLine() const { return cam.vrt(); }
84  Point Velocity() const { return velocity + arcade_velocity; }
86  const { return accel; }
87  double Thrust() const { return thrust; }
88  double TransX() const { return trans_x; }
89  double TransY() const { return trans_y; }
90  double TransZ() const { return trans_z; }
91  double Drag() const { return drag; }
92 
93  double Roll() const { return roll; }
94  double Pitch() const { return pitch; }
95  double Yaw() const { return yaw; }
96  Point Rotation() const { return Point(dp,dr,dy); }
97 
98  double Alpha() const { return alpha; }
99 
100  double FlightPathYawAngle() const { return flight_path_yaw; }
101  double FlightPathPitchAngle() const { return flight_path_pitch; }
102 
103  double Radius() const { return radius; }
104  double Mass() const { return mass; }
105  double Integrity() const { return integrity; }
106  double Life() const { return life; }
107 
108  double Shake() const { return shake; }
109  const Point& Vibration() const { return vibration; }
110 
111  const Camera& Cam() const { return cam; }
112  Graphic* Rep() const { return rep; }
113  Light* LightSrc() const { return light; }
114 
115  Director* GetDirector() const { return dir; }
116 
117  // mutators:
118  virtual void SetAngularRates(double r, double p, double y);
119  virtual void GetAngularRates(double& r, double& p, double& y);
120  virtual void SetAngularDrag(double r, double p, double y);
121  virtual void GetAngularDrag(double& r, double& p, double& y);
122  virtual void GetAngularThrust(double& r, double& p, double& y);
123  virtual void SetVelocity(const Point& v) { velocity = v; }
124  virtual void SetAbsoluteOrientation(double roll, double pitch, double yaw);
125  virtual void CloneCam(const Camera& cam);
126  virtual void SetDrag(double d) { drag = (float) d; }
127 
128  virtual void SetPrimary(const Point& loc, double mass);
129  virtual void SetGravity(double g);
130  virtual void SetBaseDensity(double d);
131 
132  virtual double GetBaseDensity() const { return Do; }
133  virtual double GetDensity() const;
134 
135  enum { NAMELEN = 48 };
136 
137 protected:
138  static int id_key;
139 
140  // identification:
141  int id;
142  int obj_type;
143  char name[NAMELEN];
144 
145  // position, velocity, and acceleration:
150  float thrust;
151  float trans_x;
152  float trans_y;
153  float trans_z;
154  float drag;
155 
156  // attitude and angular velocity:
157  float roll, pitch, yaw;
158  float dr, dp, dy;
161 
164 
165  // gravitation:
167  double primary_mass;
168 
169  // aerodynamics:
170  float g_accel; // acceleration due to gravity (constant)
171  float Do; // atmospheric density at sea level
172  float CL; // base coefficient of lift
173  float CD; // base coefficient of drag
174  float alpha; // current angle of attack (radians)
175  float stall; // stall angle of attack (radians)
176  bool lat_thrust; // lateral thrusters enabled in aero mode?
177  bool straight;
178 
179  // vibration:
180  float shake;
182 
183  // scale factors for ApplyXxx():
185 
186  // physical properties:
187  double life;
188  float radius;
189  float mass;
190  float integrity;
191 
192  // graphic representation:
195 
196  // AI or human controller:
197  Director* dir; // null implies an autonomous object
198 
199  static double sub_frame;
200 };
201 
202 // +--------------------------------------------------------------------+
203 
204 #endif Physical_h
205