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__
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A body on which physics will be applied.
Definition: physicsObject.h:27
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.
A base class for things which need to inherit from both TypedObject and from ReferenceCount.
This is a set of zero or more PhysicsObjects.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:23
This is our own Panda specialization on the default STL vector.
Definition: pvector.h:42
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:28
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
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
Physics don't get much higher-level than this.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
Defines a set of physically modeled attributes.
Definition: physical.h:37
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pure virtual parent of all quat-based forces.
Definition: angularForce.h:22
TypeHandle is the identifier used to differentiate C++ class types.
Definition: typeHandle.h:81
NodePath is the fundamental system for disambiguating instances, and also provides a higher-level int...
Definition: nodePath.h:161