Panda3D

Loading...
Searching...
No Matches
physicsManager.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 physicsManager.h
10 * @author charles
11 * @date 2000-06-14
12 */
13
14#ifndef PHYSICSMANAGER_H
15#define PHYSICSMANAGER_H
16
17#include "pandabase.h"
18#include "pointerTo.h"
19
20#include "physical.h"
21#include "linearForce.h"
22#include "angularForce.h"
23#include "linearIntegrator.h"
24#include "angularIntegrator.h"
25#include "physicalNode.h"
26
27#include "plist.h"
28#include "pvector.h"
29
30#include "configVariableInt.h"
31
32/**
33 * Physics don't get much higher-level than this. Attach as many Physicals
34 * (particle systems, etc..) as you want, pick an integrator and go.
35 */
36 class EXPCL_PANDA_PHYSICS PhysicsManager {
37 public:
38 // NOTE that the physicals container is NOT reference counted. this does
39 // indeed mean that you are NOT supposed to use this as a primary storage
40 // container for the physicals. This is so because physicals, on their
41 // death, ask to be removed from their current physicsmanager, if one
42 // exists, relieving the client from the task and also allowing for
43 // dynamically created and destroyed physicals.
44 typedef pvector<Physical *> PhysicalsVector;
45 typedef pvector<PT(LinearForce)> LinearForceVector;
46 typedef pvector<PT(AngularForce)> AngularForceVector;
47
48PUBLISHED:
49 PhysicsManager();
50 virtual ~PhysicsManager();
51
52 INLINE void attach_linear_integrator(LinearIntegrator *i);
53 INLINE void attach_angular_integrator(AngularIntegrator *i);
54 INLINE void attach_physical(Physical *p);
55 INLINE void attach_physicalnode(PhysicalNode *p); // use attach_physical_node instead.
56 INLINE void attach_physical_node(PhysicalNode *p);
57 INLINE void add_linear_force(LinearForce *f);
58 INLINE void add_angular_force(AngularForce *f);
59 INLINE void clear_linear_forces();
60 INLINE void clear_angular_forces();
61 INLINE void clear_physicals();
62
63 INLINE void set_viscosity(PN_stdfloat viscosity);
64 INLINE PN_stdfloat get_viscosity() const;
65
66 void remove_physical(Physical *p);
67 void remove_physical_node(PhysicalNode *p);
68 void remove_linear_force(LinearForce *f);
69 void remove_angular_force(AngularForce *f);
70 void do_physics(PN_stdfloat dt);
71 void do_physics(PN_stdfloat dt, Physical *p);
72 void init_random_seed();
73
74 virtual void output(std::ostream &out) const;
75 virtual void write_physicals(std::ostream &out, int indent=0) const;
76 virtual void write_linear_forces(std::ostream &out, int indent=0) const;
77 virtual void write_angular_forces(std::ostream &out, int indent=0) const;
78 virtual void write(std::ostream &out, int indent=0) const;
79
80 virtual void debug_output(std::ostream &out, int indent=0) const;
81
82 public:
83 friend class Physical;
84 static ConfigVariableInt _random_seed;
85
86 private:
87 PN_stdfloat _viscosity;
88 PhysicalsVector _physicals;
89 LinearForceVector _linear_forces;
90 AngularForceVector _angular_forces;
91
92 PT(LinearIntegrator) _linear_integrator;
93 PT(AngularIntegrator) _angular_integrator;
94};
95
96#include "physicsManager.I"
97
98#endif // PHYSICSMANAGER_H
angularForce.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
angularIntegrator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
AngularForce
pure virtual parent of all quat-based forces.
Definition angularForce.h:22
AngularIntegrator
Pure virtual base class for physical modeling.
Definition angularIntegrator.h:25
ConfigVariableInt
This is a convenience class to specialize ConfigVariable as an integer type.
Definition configVariableInt.h:24
LinearForce
A force that acts on a PhysicsObject by way of an Integrator.
Definition linearForce.h:23
LinearIntegrator
Pure virtual base class for physical modeling.
Definition linearIntegrator.h:26
PhysicalNode
Graph node that encapsulated a series of physical objects.
Definition physicalNode.h:28
PhysicsManager::get_viscosity
PN_stdfloat get_viscosity() const
Get the global viscosity.
Definition physicsManager.I:114
PhysicsManager::do_physics
void do_physics(PN_stdfloat dt)
This is the main high-level API call.
Definition physicsManager.cxx:125
PhysicsManager::attach_linear_integrator
void attach_linear_integrator(LinearIntegrator *i)
Hooks a linear integrator into the manager.
Definition physicsManager.I:122
PhysicsManager::clear_angular_forces
void clear_angular_forces()
Resets the physics manager force vector.
Definition physicsManager.I:90
PhysicsManager::output
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:181
PhysicsManager::write_linear_forces
virtual void write_linear_forces(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:211
PhysicsManager::remove_physical_node
void remove_physical_node(PhysicalNode *p)
Removes a physicalnode from the manager.
Definition physicsManager.cxx:113
PhysicsManager::clear_physicals
void clear_physicals()
Resets the physics manager objects vector.
Definition physicsManager.I:98
PhysicsManager::write_angular_forces
virtual void write_angular_forces(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:227
PhysicsManager::clear_linear_forces
void clear_linear_forces()
Resets the physics manager force vector.
Definition physicsManager.I:69
PhysicsManager::write
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:243
PhysicsManager::attach_physicalnode
void attach_physicalnode(PhysicalNode *p)
Please call attach_physical_node instead.
Definition physicsManager.I:46
PhysicsManager::attach_physical
void attach_physical(Physical *p)
Registers a Physical class with the manager.
Definition physicsManager.I:18
PhysicsManager::set_viscosity
void set_viscosity(PN_stdfloat viscosity)
Set the global viscosity.
Definition physicsManager.I:106
PhysicsManager::attach_angular_integrator
void attach_angular_integrator(AngularIntegrator *i)
Hooks an angular integrator into the manager.
Definition physicsManager.I:131
PhysicsManager::remove_angular_force
void remove_angular_force(AngularForce *f)
takes an angular force out of the physics list
Definition physicsManager.cxx:79
PhysicsManager::attach_physical_node
void attach_physical_node(PhysicalNode *p)
Registers a physicalnode with the manager.
Definition physicsManager.I:58
PhysicsManager::debug_output
virtual void debug_output(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:273
PhysicsManager::init_random_seed
void init_random_seed()
One-time config function, sets up the random seed used by the physics and particle systems.
Definition physicsManager.cxx:52
PhysicsManager::remove_physical
void remove_physical(Physical *p)
takes a physical out of the object list
Definition physicsManager.cxx:96
PhysicsManager::PhysicsManager
PhysicsManager()
Default Constructor.
Definition physicsManager.cxx:29
PhysicsManager::add_linear_force
void add_linear_force(LinearForce *f)
Adds a global linear force to the physics manager.
Definition physicsManager.I:32
PhysicsManager::remove_linear_force
void remove_linear_force(LinearForce *f)
takes a linear force out of the physics list
Definition physicsManager.cxx:62
PhysicsManager::add_angular_force
void add_angular_force(AngularForce *f)
Adds a global angular force to the physics manager.
Definition physicsManager.I:77
PhysicsManager::write_physicals
virtual void write_physicals(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
Definition physicsManager.cxx:191
configVariableInt.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
indent
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
Definition indent.cxx:20
linearForce.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
linearIntegrator.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pandabase.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physicalNode.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physical.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
physicsManager.I
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
plist.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pointerTo.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
pvector.h
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.