Panda3D
 All Classes Functions Variables Enumerations
physicsManager.I
1 // Filename: physicsManager.I
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 ////////////////////////////////////////////////////////////////////
16 // Function : attach_physical
17 // Access : Public
18 // Description : Registers a Physical class with the manager
19 ////////////////////////////////////////////////////////////////////
20 INLINE void PhysicsManager::
22  nassertv(p && p->_physics_manager == NULL);
23  p->_physics_manager = this;
24  PhysicalsVector::iterator found;
25  found = find(_physicals.begin(), _physicals.end(), p);
26  if (found == _physicals.end()) {
27  _physicals.push_back(p);
28  }
29 }
30 
31 ////////////////////////////////////////////////////////////////////
32 // Function : attach_linear_force
33 // Access : Public
34 // Description : Adds a global linear force to the physics manager
35 ////////////////////////////////////////////////////////////////////
36 INLINE void PhysicsManager::
38  nassertv(f);
39  LinearForceVector::iterator found;
40  PT(LinearForce) ptlf = f;
41  found = find(_linear_forces.begin(), _linear_forces.end(), ptlf);
42  if (found == _linear_forces.end()) {
43  _linear_forces.push_back(f);
44  }
45 }
46 
47 ////////////////////////////////////////////////////////////////////
48 // Function : attach_physicalnode
49 // Access : Public
50 // Description : Please call attach_physical_node instead.
51 ////////////////////////////////////////////////////////////////////
52 INLINE void PhysicsManager::
54  cerr<<"attach_physicalnode (aka attachPhysicalnode) has been"
55  <<"replaced with attach_physical_node (aka attachPhysicalNode)."
56  <<" Please change the spelling of the function in your code."
57  <<endl;
59 }
60 
61 ////////////////////////////////////////////////////////////////////
62 // Function : attach_physical_node
63 // Access : Public
64 // Description : Registers a physicalnode with the manager
65 ////////////////////////////////////////////////////////////////////
66 INLINE void PhysicsManager::
68  nassertv(p);
69  for (int i = 0; i < p->get_num_physicals(); ++i) {
70  attach_physical(p->get_physical(i));
71  }
72 }
73 
74 ////////////////////////////////////////////////////////////////////
75 // Function : clear_linear_forces
76 // Access : Public
77 // Description : Resets the physics manager force vector
78 ////////////////////////////////////////////////////////////////////
79 INLINE void PhysicsManager::
81  _linear_forces.erase(_linear_forces.begin(), _linear_forces.end());
82 }
83 
84 ////////////////////////////////////////////////////////////////////
85 // Function : attach_angular_force
86 // Access : Public
87 // Description : Adds a global angular force to the physics manager
88 ////////////////////////////////////////////////////////////////////
89 INLINE void PhysicsManager::
91  nassertv(f);
92  AngularForceVector::iterator found;
93  PT(AngularForce) ptaf = f;
94  found = find(_angular_forces.begin(), _angular_forces.end(), ptaf);
95  if (found == _angular_forces.end())
96  _angular_forces.push_back(f);
97 }
98 
99 ////////////////////////////////////////////////////////////////////
100 // Function : clear_angular_forces
101 // Access : Public
102 // Description : Resets the physics manager force vector
103 ////////////////////////////////////////////////////////////////////
104 INLINE void PhysicsManager::
106  _angular_forces.erase(_angular_forces.begin(), _angular_forces.end());
107 }
108 
109 ////////////////////////////////////////////////////////////////////
110 // Function : clear_physicals
111 // Access : Public
112 // Description : Resets the physics manager objects vector
113 ////////////////////////////////////////////////////////////////////
114 INLINE void PhysicsManager::
116  _physicals.erase(_physicals.begin(), _physicals.end());
117 }
118 
119 ////////////////////////////////////////////////////////////////////
120 // Function : set_viscosity
121 // Access : Public
122 // Description : Set the global viscosity.
123 ////////////////////////////////////////////////////////////////////
124 INLINE void PhysicsManager::
125 set_viscosity(PN_stdfloat viscosity) {
126  _viscosity=viscosity;
127 }
128 
129 ////////////////////////////////////////////////////////////////////
130 // Function : get_viscosity
131 // Access : Public
132 // Description : Get the global viscosity.
133 ////////////////////////////////////////////////////////////////////
134 INLINE PN_stdfloat PhysicsManager::
135 get_viscosity() const {
136  return _viscosity;
137 }
138 
139 ////////////////////////////////////////////////////////////////////
140 // Function : attach_linear_integrator
141 // Access : Public
142 // Description : Hooks a linear integrator into the manager
143 ////////////////////////////////////////////////////////////////////
144 INLINE void PhysicsManager::
146  nassertv(i);
147  _linear_integrator = i;
148 }
149 
150 ////////////////////////////////////////////////////////////////////
151 // Function : attach_angular_integrator
152 // Access : Public
153 // Description : Hooks an angular integrator into the manager
154 ////////////////////////////////////////////////////////////////////
155 INLINE void PhysicsManager::
157  nassertv(i);
158  _angular_integrator = i;
159 }
Pure virtual base class for physical modeling.
void add_angular_force(AngularForce *f)
Adds a global angular force to the physics manager.
void clear_angular_forces()
Resets the physics manager force vector.
void add_linear_force(LinearForce *f)
Adds a global linear force to the physics manager.
void attach_physical(Physical *p)
Registers a Physical class with the manager.
void clear_linear_forces()
Resets the physics manager force vector.
PN_stdfloat get_viscosity() const
Get the global viscosity.
void set_viscosity(PN_stdfloat viscosity)
Set the global viscosity.
A force that acts on a PhysicsObject by way of an Integrator.
Definition: linearForce.h:25
void attach_linear_integrator(LinearIntegrator *i)
Hooks a linear integrator into the manager.
Graph node that encapsulated a series of physical objects.
Definition: physicalNode.h:31
void attach_angular_integrator(AngularIntegrator *i)
Hooks an angular integrator into the manager.
Defines a set of physically modeled attributes.
Definition: physical.h:40
void attach_physicalnode(PhysicalNode *p)
Please call attach_physical_node instead.
pure virtual parent of all quat-based forces.
Definition: angularForce.h:24
Pure virtual base class for physical modeling.
void clear_physicals()
Resets the physics manager objects vector.
void attach_physical_node(PhysicalNode *p)
Registers a physicalnode with the manager.