Panda3D
linearIntegrator.cxx
1 // Filename: linearIntegrator.cxx
2 // Created by: charles (02Aug00)
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 #include "linearIntegrator.h"
16 #include "config_physics.h"
17 #include "physicalNode.h"
18 #include "forceNode.h"
19 
20 ConfigVariableDouble LinearIntegrator::_max_linear_dt
21 ("default_max_linear_dt", 1.0f / 30.0f);
22 
23 
24 ////////////////////////////////////////////////////////////////////
25 // Function : BaseLinearIntegrator
26 // Access : Protected
27 // Description : constructor
28 ////////////////////////////////////////////////////////////////////
29 LinearIntegrator::
30 LinearIntegrator() {
31 }
32 
33 ////////////////////////////////////////////////////////////////////
34 // Function : ~LinearIntegrator
35 // Access : public, virtual
36 // Description : destructor
37 ////////////////////////////////////////////////////////////////////
40 }
41 
42 ////////////////////////////////////////////////////////////////////
43 // Function : integrate
44 // Access : public
45 // Description : parent integration routine, hands off to child
46 // virtual.
47 ////////////////////////////////////////////////////////////////////
50  PN_stdfloat dt) {
51 /* <-- darren, 2000.10.06
52  // cap dt so physics don't go flying off on lags
53  if (dt > _max_linear_dt)
54  dt = _max_linear_dt;
55 */
56 
57  PhysicsObject::Vector::const_iterator current_object_iter;
58  current_object_iter = physical->get_object_vector().begin();
59  for (; current_object_iter != physical->get_object_vector().end();
60  ++current_object_iter) {
61  PhysicsObject *current_object = *current_object_iter;
62 
63  // bail out if this object doesn't exist or doesn't want to be
64  // processed.
65  if (current_object == (PhysicsObject *) NULL) {
66  continue;
67  }
68 
69  // set the object's last position to its current position before we move it
70  current_object->set_last_position(current_object->get_position());
71  }
72  child_integrate(physical, forces, dt);
73 }
74 
75 ////////////////////////////////////////////////////////////////////
76 // Function : output
77 // Access : Public
78 // Description : Write a string representation of this instance to
79 // <out>.
80 ////////////////////////////////////////////////////////////////////
82 output(ostream &out) const {
83  #ifndef NDEBUG //[
84  out<<"LinearIntegrator";
85  #endif //] NDEBUG
86 }
87 
88 ////////////////////////////////////////////////////////////////////
89 // Function : write
90 // Access : Public
91 // Description : Write a string representation of this instance to
92 // <out>.
93 ////////////////////////////////////////////////////////////////////
95 write(ostream &out, unsigned int indent) const {
96  #ifndef NDEBUG //[
97  out.width(indent); out<<""; out<<"LinearIntegrator:\n";
98  out.width(indent+2); out<<""; out<<"_max_linear_dt "<<_max_linear_dt<<" (class static)\n";
99  BaseIntegrator::write(out, indent+2);
100  #endif //] NDEBUG
101 }
void integrate(Physical *physical, LinearForceVector &forces, PN_stdfloat dt)
parent integration routine, hands off to child virtual.
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
A body on which physics will be applied.
Definition: physicsObject.h:29
This is a convenience class to specialize ConfigVariable as a floating-point type.
void set_last_position(const LPoint3 &pos)
Last position assignment.
Definition: physicsObject.I:83
virtual void output(ostream &out) const
Write a string representation of this instance to <out>.
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
Defines a set of physically modeled attributes.
Definition: physical.h:40
virtual ~LinearIntegrator()
destructor
LPoint3 get_position() const
Position Query.