15 #include "linearEulerIntegrator.h" 16 #include "forceNode.h" 17 #include "physicalNode.h" 18 #include "config_physics.h" 54 void LinearEulerIntegrator::
63 precompute_linear_matrices(physical, forces);
64 const MatrixVector &matrices = get_precomputed_linear_matrices();
66 MatrixVector::const_iterator mi;
67 for (mi = matrices.begin(); mi != matrices.end(); ++mi) {
68 nassertv(!(*mi).is_nan());
82 PhysicsObject::Vector::const_iterator current_object_iter;
83 current_object_iter = physical->get_object_vector().begin();
84 for (; current_object_iter != physical->get_object_vector().end();
85 ++current_object_iter) {
104 md_accum_vec.set(0.0f, 0.0f, 0.0f);
105 non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
111 LinearForceVector::const_iterator f_cur;
114 f_cur = forces.begin();
116 for (; f_cur != forces.end(); ++f_cur) {
120 if (cur_force->get_active() ==
false) {
125 f = cur_force->get_vector(current_object) * matrices[index++];
127 physics_spam(
"child_integrate "<<f);
129 if (cur_force->get_mass_dependent() ==
true) {
132 non_md_accum_vec += f;
137 f_cur = physical->get_linear_forces().begin();
138 for (; f_cur != physical->get_linear_forces().end(); ++f_cur) {
142 if (cur_force->get_active() ==
false) {
147 f = cur_force->get_vector(current_object) * matrices[index++];
149 physics_spam(
"child_integrate "<<f);
151 if (cur_force->get_mass_dependent() ==
true) {
154 non_md_accum_vec += f;
161 PN_stdfloat mass = current_object->
get_mass();
165 nassertv(mass != 0.0f);
166 accel_vec = md_accum_vec / mass;
167 accel_vec += non_md_accum_vec;
171 vel_vec += accel_vec * dt;
174 PN_stdfloat len = vel_vec.
length();
185 accel_vec*=viscosityDamper;
188 pos += vel_vec * dt + 0.5 * accel_vec * dt * dt;
190 vel_vec += accel_vec * dt;
212 out<<
"LinearEulerIntegrator";
223 write(ostream &out,
unsigned int indent)
const {
226 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.
This is a three-component vector distance (as opposed to a three-component point, which represents a ...
This is a three-component point in space (as opposed to a three-component vector, which represents a ...
bool is_nan() const
Returns true if any component of the vector is not-a-number, false otherwise.
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(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>.
virtual ~LinearEulerIntegrator()
destructor
LVector3 get_velocity() const
Velocity Query per second.
Defines a set of physically modeled attributes.
float length() const
Returns the length of the vector, by the Pythagorean theorem.
virtual void write(ostream &out, unsigned int indent=0) const
Write a string representation of this instance to <out>.
LPoint3 get_position() const
Position Query.