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 #if !defined(NDEBUG) || !defined(CPPPARSER)
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 PUBLISHED:
103  MAKE_PROPERTY(active, get_active, set_active);
104  MAKE_PROPERTY(mass, get_mass, set_mass);
105  MAKE_PROPERTY(position, get_position, set_position);
106  MAKE_PROPERTY(last_position, get_last_position, set_last_position);
107  MAKE_PROPERTY(velocity, get_velocity, set_velocity);
108  MAKE_PROPERTY(implicit_velocity, get_implicit_velocity);
109  MAKE_PROPERTY(terminal_velocity, get_terminal_velocity, set_terminal_velocity);
110  MAKE_PROPERTY(oriented, get_oriented, set_oriented);
111  MAKE_PROPERTY(orientation, get_orientation, set_orientation);
112  MAKE_PROPERTY(rotation, get_rotation, set_rotation);
113 
114 private:
115  // physical
116  LPoint3 _position; // aka _center_of_mass
117  LPoint3 _last_position;
118  LVector3 _velocity; // aka _linear_velocity
119 
120  // angular
121  LOrientation _orientation;
122  LRotation _rotation; // aka _angular_velocity
123 
124  PN_stdfloat _terminal_velocity;
125  PN_stdfloat _mass;
126 
127  bool _process_me;
128  bool _oriented;
129 
130  std::string _name;
131 
132 public:
133  static TypeHandle get_class_type() {
134  return _type_handle;
135  }
136  static void init_type() {
137  TypedReferenceCount::init_type();
138  register_type(_type_handle, "PhysicsObject",
139  TypedReferenceCount::get_class_type());
140  }
141  virtual TypeHandle get_type() const {
142  return get_class_type();
143  }
144  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
145 
146 private:
147  static TypeHandle _type_handle;
148 };
149 
150 #include "physicsObject.I"
151 
152 #endif // __PHYSICS_OBJECT_H__
This is a convenience class to specialize ConfigVariable as a floating- point type.
A body on which physics will be applied.
Definition: physicsObject.h:27
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
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
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.