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