Panda3D
physical.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 physical.h
10  * @author charles
11  * @date 2000-06-14
12  */
13 
14 #ifndef PHYSICAL_H
15 #define PHYSICAL_H
16 
17 #include "pandabase.h"
18 #include "pointerTo.h"
19 #include "typedReferenceCount.h"
20 
21 #include "pvector.h"
22 #include "plist.h"
23 
24 #include "physicsObject.h"
26 #include "linearForce.h"
27 #include "angularForce.h"
28 #include "nodePath.h"
29 
30 class PhysicalNode;
31 class PhysicsManager;
32 
33 /**
34  * Defines a set of physically modeled attributes. If you want physics
35  * applied to your class, derive it from this.
36  */
37 class EXPCL_PANDA_PHYSICS Physical : public TypedReferenceCount {
38 public:
39  // typedef pvector<PT(PhysicsObject)> PhysicsObjectVector;
42 
43 PUBLISHED:
44  explicit Physical(int total_objects = 1, bool pre_alloc = false);
45  Physical(const Physical& copy);
46 
47  virtual ~Physical();
48 
49  // helpers
50  INLINE PhysicsManager *get_physics_manager() const;
51  INLINE PhysicalNode *get_physical_node() const;
52  INLINE NodePath get_physical_node_path() const;
53  INLINE PhysicsObject *get_phys_body() const;
54 
55  INLINE void clear_linear_forces();
56  INLINE void clear_angular_forces();
57  INLINE void clear_physics_objects();
58  INLINE void add_linear_force(LinearForce *f);
59  INLINE void add_angular_force(AngularForce *f);
60  INLINE void add_physics_object(PhysicsObject *po);
61  INLINE void remove_linear_force(LinearForce *f);
62  INLINE void remove_angular_force(AngularForce *f);
63 
64  INLINE int get_num_linear_forces() const;
65  INLINE PT(LinearForce) get_linear_force(int index) const;
66  MAKE_SEQ(get_linear_forces, get_num_linear_forces, get_linear_force);
67  MAKE_SEQ_PROPERTY(linear_forces, get_num_linear_forces, get_linear_force);
68  INLINE int get_num_angular_forces() const;
69  INLINE PT(AngularForce) get_angular_force(int index) const;
70  MAKE_SEQ(get_angular_forces, get_num_angular_forces, get_angular_force);
71  MAKE_SEQ_PROPERTY(angular_forces, get_num_angular_forces, get_angular_force);
72 
73  INLINE void set_viscosity(PN_stdfloat viscosity);
74  INLINE PN_stdfloat get_viscosity() const;
75  MAKE_PROPERTY(viscosity, get_viscosity);
76 
77  const PhysicsObjectCollection get_objects() const;
78  MAKE_PROPERTY(objects, get_objects);
79 
80  virtual void output(std::ostream &out = std::cout) const;
81  virtual void write_physics_objects(
82  std::ostream &out = std::cout, int indent=0) const;
83  virtual void write_linear_forces(
84  std::ostream &out = std::cout, int indent=0) const;
85  virtual void write_angular_forces(
86  std::ostream &out = std::cout, int indent=0) const;
87  virtual void write(std::ostream &out = std::cout, int indent=0) const;
88 
89 public:
90  INLINE const PhysicsObject::Vector &get_object_vector() const;
91  INLINE const LinearForceVector &get_linear_forces() const;
92  INLINE const AngularForceVector &get_angular_forces() const;
93 
94  friend class PhysicsManager;
95  friend class PhysicalNode;
96 
97 protected:
98  PN_stdfloat _viscosity;
99  // containers
100  PhysicsObject::Vector _physics_objects;
101  LinearForceVector _linear_forces;
102  AngularForceVector _angular_forces;
103 
104  // this pointer exists to make life easy. If a physical exists with only
105  // one element (i.e. NOT a particle system or set-physical), then this
106  // pointer points at the only PhysicsObject. The object is still of course
107  // contained in the _physics_objects vector, but this is kind of a quicker
108  // way there.
109  PhysicsObject *_phys_body;
110 
111 private:
112  PhysicsManager *_physics_manager;
113  PhysicalNode *_physical_node;
114 
115 public:
116  static TypeHandle get_class_type() {
117  return _type_handle;
118  }
119  static void init_type() {
120  TypedReferenceCount::init_type();
121  register_type(_type_handle, "Physical",
122  TypedReferenceCount::get_class_type());
123  }
124  virtual TypeHandle get_type() const {
125  return get_class_type();
126  }
127  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
128 
129 private:
130  static TypeHandle _type_handle;
131 };
132 
133 #include "physical.I"
134 
135 #endif // __PHYSICAL_H__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pure virtual parent of all quat-based forces.
Definition: angularForce.h:22
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:23
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:28
Defines a set of physically modeled attributes.
Definition: physical.h:37
Physics don't get much higher-level than this.
This is a set of zero or more PhysicsObjects.
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
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.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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.