41 void LinearEulerIntegrator::
43 LinearForceVector& forces,
50 precompute_linear_matrices(physical, forces);
51 const MatrixVector &matrices = get_precomputed_linear_matrices();
53 MatrixVector::const_iterator mi;
54 for (mi = matrices.begin(); mi != matrices.end(); ++mi) {
55 nassertv(!(*mi).is_nan());
68 PhysicsObject::Vector::const_iterator current_object_iter;
69 current_object_iter = physical->get_object_vector().begin();
70 for (; current_object_iter != physical->get_object_vector().end();
71 ++current_object_iter) {
75 if (current_object ==
nullptr) {
83 LVector3 md_accum_vec;
84 LVector3 non_md_accum_vec;
89 md_accum_vec.set(0.0f, 0.0f, 0.0f);
90 non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
96 LinearForceVector::const_iterator f_cur;
99 f_cur = forces.begin();
101 for (; f_cur != forces.end(); ++f_cur) {
105 if (cur_force->get_active() ==
false) {
110 f = cur_force->get_vector(current_object) * matrices[index++];
112 physics_spam(
"child_integrate "<<f);
114 if (cur_force->get_mass_dependent() ==
true) {
117 non_md_accum_vec += f;
122 f_cur = physical->get_linear_forces().begin();
123 for (; f_cur != physical->get_linear_forces().end(); ++f_cur) {
127 if (cur_force->get_active() ==
false) {
132 f = cur_force->get_vector(current_object) * matrices[index++];
134 physics_spam(
"child_integrate "<<f);
136 if (cur_force->get_mass_dependent() ==
true) {
139 non_md_accum_vec += f;
146 PN_stdfloat mass = current_object->
get_mass();
149 nassertv(mass != 0.0f);
150 accel_vec = md_accum_vec / mass;
151 accel_vec += non_md_accum_vec;
155 vel_vec += accel_vec * dt;
158 PN_stdfloat len = vel_vec.length();
170 accel_vec*=viscosityDamper;
173 pos += vel_vec * dt + 0.5 * accel_vec * dt * dt;
175 vel_vec += accel_vec * dt;
182 if (!vel_vec.is_nan()) {
194 out<<
"LinearEulerIntegrator";
205 out<<
""<<
"LinearEulerIntegrator:\n";
PN_stdfloat get_terminal_velocity() const
tv query
LPoint3 get_last_position() const
Get the position of the physics object at the start of the most recent do_physics.
LinearEulerIntegrator()
constructor
void set_position(const LPoint3 &pos)
Vector position assignment.
bool get_active() const
Process Flag Query.
A body on which physics will be applied.
PN_stdfloat get_viscosity() const
Get the local viscosity.
void set_velocity(const LVector3 &vel)
Vector velocity assignment.
PN_stdfloat get_mass() const
Get the mass in slugs (or kilograms).
A force that acts on a PhysicsObject by way of an Integrator.
virtual void output(std::ostream &out) const
Write a string representation of this instance to <out>.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
std::ostream & indent(std::ostream &out, int indent_level)
A handy function for doing text formatting.
virtual ~LinearEulerIntegrator()
destructor
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
LVector3 get_velocity() const
Velocity Query per second.
Defines a set of physically modeled attributes.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.
virtual void write(std::ostream &out, int indent=0) const
Write a string representation of this instance to <out>.
LPoint3 get_position() const
Position Query.
PANDA 3D SOFTWARE Copyright (c) Carnegie Mellon University.