Panda3D
physicsObject.h
1 // Filename: physicsObject.h
2 // Created by: charles (13Jun00)
3 //
4 ////////////////////////////////////////////////////////////////////
5 //
6 // PANDA 3D SOFTWARE
7 // Copyright (c) Carnegie Mellon University. All rights reserved.
8 //
9 // All use of this software is subject to the terms of the revised BSD
10 // license. You should have received a copy of this license along
11 // with this source code in a file named "LICENSE."
12 //
13 ////////////////////////////////////////////////////////////////////
14 
15 #ifndef PHYSICS_OBJECT_H
16 #define PHYSICS_OBJECT_H
17 
18 #include "pandabase.h"
19 #include "typedReferenceCount.h"
20 #include "luse.h"
21 #include "configVariableDouble.h"
22 
23 ////////////////////////////////////////////////////////////////////
24 // Class : PhysicsObject
25 // Description : A body on which physics will be applied. If you're
26 // looking to add physical motion to your class, do
27 // NOT derive from this. Derive from Physical instead.
28 ////////////////////////////////////////////////////////////////////
29 class EXPCL_PANDAPHYSICS PhysicsObject : public TypedReferenceCount {
30 public:
32 
33 PUBLISHED:
34  PhysicsObject();
35  PhysicsObject(const PhysicsObject &copy);
36  virtual ~PhysicsObject();
37  const PhysicsObject &operator =(const PhysicsObject &other);
38 
39  static ConfigVariableDouble _default_terminal_velocity;
40 
41  INLINE void set_active(bool flag);
42  INLINE bool get_active() const;
43 
44  INLINE void set_mass(PN_stdfloat);
45  INLINE PN_stdfloat get_mass() const;
46 
47  //INLINE void set_center_of_mass(const LPoint3 &pos); use set_position.
48  INLINE void set_position(const LPoint3 &pos);
49  INLINE void set_position(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
50  INLINE LPoint3 get_position() const;
51 
52  INLINE void reset_position(const LPoint3 &pos);
53 
54  INLINE void set_last_position(const LPoint3 &pos);
55  INLINE LPoint3 get_last_position() const;
56 
57  INLINE void set_velocity(const LVector3 &vel);
58  INLINE void set_velocity(PN_stdfloat x, PN_stdfloat y, PN_stdfloat z);
59  INLINE LVector3 get_velocity() const;
60  INLINE LVector3 get_implicit_velocity() const;
61 
62  // Global instantanious forces
63  INLINE void add_torque(const LRotation &torque);
64  INLINE void add_impulse(const LVector3 &impulse);
65  virtual void add_impact(
66  const LPoint3 &offset_from_center_of_mass, const LVector3 &impulse);
67 
68  // Local instantanious forces
69  INLINE void add_local_torque(const LRotation &torque);
70  INLINE void add_local_impulse(const LVector3 &impulse);
71  virtual void add_local_impact(
72  const LPoint3 &offset_from_center_of_mass, const LVector3 &impulse);
73 
74  INLINE void set_terminal_velocity(PN_stdfloat tv);
75  INLINE PN_stdfloat get_terminal_velocity() const;
76 
77  INLINE void set_oriented(bool flag);
78  INLINE bool get_oriented() const;
79 
80  INLINE void set_orientation(const LOrientation &orientation);
81  INLINE LOrientation get_orientation() const;
82 
83  INLINE void reset_orientation(const LOrientation &orientation);
84 
85  INLINE void set_rotation(const LRotation &rotation);
86  INLINE LRotation get_rotation() const;
87 
88  virtual LMatrix4 get_inertial_tensor() const;
89  virtual LMatrix4 get_lcs() const;
90  virtual PhysicsObject *make_copy() const;
91 
92  #ifndef NDEBUG
93  void set_name(const string &name) {
94  _name = name;
95  }
96  const string& get_name() {
97  return _name;
98  }
99  #endif
100 
101  virtual void output(ostream &out) const;
102  virtual void write(ostream &out, unsigned int indent=0) const;
103 
104 private:
105  // physical
106  LPoint3 _position; // aka _center_of_mass
107  LPoint3 _last_position;
108  LVector3 _velocity; // aka _linear_velocity
109 
110  // angular
111  LOrientation _orientation;
112  LRotation _rotation; // aka _angular_velocity
113 
114  PN_stdfloat _terminal_velocity;
115  PN_stdfloat _mass;
116 
117  bool _process_me;
118  bool _oriented;
119 
120  #ifndef NDEBUG
121  string _name;
122  #endif
123 
124 public:
125  static TypeHandle get_class_type() {
126  return _type_handle;
127  }
128  static void init_type() {
129  TypedReferenceCount::init_type();
130  register_type(_type_handle, "PhysicsObject",
131  TypedReferenceCount::get_class_type());
132  }
133  virtual TypeHandle get_type() const {
134  return get_class_type();
135  }
136  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
137 
138 private:
139  static TypeHandle _type_handle;
140 };
141 
142 #include "physicsObject.I"
143 
144 #endif // __PHYSICS_OBJECT_H__
This is a unit quaternion representing a rotation.
Definition: lrotation.h:92
A body on which physics will be applied.
Definition: physicsObject.h:29
This is a unit quaternion representing an orientation.
Definition: lorientation.h:92
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
Definition: lvector3.h:100
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
Definition: lpoint3.h:99
This is a convenience class to specialize ConfigVariable as a floating-point type.
This is a 4-by-4 transform matrix.
Definition: lmatrix.h:451
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:85