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