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  INLINE int get_num_angular_forces() const;
68  INLINE PT(AngularForce) get_angular_force(int index) const;
69  MAKE_SEQ(get_angular_forces, get_num_angular_forces, get_angular_force);
70 
71  INLINE void set_viscosity(PN_stdfloat viscosity);
72  INLINE PN_stdfloat get_viscosity() const;
73 
74  const PhysicsObjectCollection get_objects() const;
75 
76  virtual void output(std::ostream &out = std::cout) const;
77  virtual void write_physics_objects(
78  std::ostream &out = std::cout, int indent=0) const;
79  virtual void write_linear_forces(
80  std::ostream &out = std::cout, int indent=0) const;
81  virtual void write_angular_forces(
82  std::ostream &out = std::cout, int indent=0) const;
83  virtual void write(std::ostream &out = std::cout, int indent=0) const;
84 
85 public:
86  INLINE const PhysicsObject::Vector &get_object_vector() const;
87  INLINE const LinearForceVector &get_linear_forces() const;
88  INLINE const AngularForceVector &get_angular_forces() const;
89 
90  friend class PhysicsManager;
91  friend class PhysicalNode;
92 
93 protected:
94  PN_stdfloat _viscosity;
95  // containers
96  PhysicsObject::Vector _physics_objects;
97  LinearForceVector _linear_forces;
98  AngularForceVector _angular_forces;
99 
100  // this pointer exists to make life easy. If a physical exists with only
101  // one element (i.e. NOT a particle system or set-physical), then this
102  // pointer points at the only PhysicsObject. The object is still of course
103  // contained in the _physics_objects vector, but this is kind of a quicker
104  // way there.
105  PhysicsObject *_phys_body;
106 
107 private:
108  PhysicsManager *_physics_manager;
109  PhysicalNode *_physical_node;
110 
111 public:
112  static TypeHandle get_class_type() {
113  return _type_handle;
114  }
115  static void init_type() {
116  TypedReferenceCount::init_type();
117  register_type(_type_handle, "Physical",
118  TypedReferenceCount::get_class_type());
119  }
120  virtual TypeHandle get_type() const {
121  return get_class_type();
122  }
123  virtual TypeHandle force_init_type() {init_type(); return get_class_type();}
124 
125 private:
126  static TypeHandle _type_handle;
127 };
128 
129 #include "physical.I"
130 
131 #endif // __PHYSICAL_H__
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition: indent.cxx:20
nodePath.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysicsObjectCollection
This is a set of zero or more PhysicsObjects.
Definition: physicsObjectCollection.h:25
pvector
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
Physical
Defines a set of physically modeled attributes.
Definition: physical.h:37
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physical.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
register_type
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
angularForce.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypedReferenceCount
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
Definition: typedReferenceCount.h:31
PhysicsManager
Physics don't get much higher-level than this.
Definition: physicsManager.h:36
plist.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
TypeHandle
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
LinearForce
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:23
physicsObjectCollection.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physicsObject.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
NodePath
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:159
PhysicsObject
A body on which physics will be applied.
Definition: physicsObject.h:27
AngularForce
pure virtual parent of all quat-based forces.
Definition: angularForce.h:22
linearForce.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
typedReferenceCount.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PhysicalNode
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:28