|
@@ -27,7 +27,7 @@
|
|
|
// Description : constructor
|
|
// Description : constructor
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
LinearEulerIntegrator::
|
|
LinearEulerIntegrator::
|
|
|
-LinearEulerIntegrator(void) {
|
|
|
|
|
|
|
+LinearEulerIntegrator() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -36,7 +36,7 @@ LinearEulerIntegrator(void) {
|
|
|
// Description : destructor
|
|
// Description : destructor
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
LinearEulerIntegrator::
|
|
LinearEulerIntegrator::
|
|
|
-~LinearEulerIntegrator(void) {
|
|
|
|
|
|
|
+~LinearEulerIntegrator() {
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
@@ -45,20 +45,27 @@ LinearEulerIntegrator::
|
|
|
// Description : Integrate a step of motion (based on dt) by
|
|
// Description : Integrate a step of motion (based on dt) by
|
|
|
// applying every force in force_vec to every object
|
|
// applying every force in force_vec to every object
|
|
|
// in obj_vec.
|
|
// in obj_vec.
|
|
|
|
|
+//
|
|
|
|
|
+// physical,
|
|
|
|
|
+// The objects being acted upon and the
|
|
|
|
|
+// set of local forces that are applied
|
|
|
|
|
+// after the global forces.
|
|
|
|
|
+// forces,
|
|
|
|
|
+// Global forces to be applied first.
|
|
|
|
|
+// dt,
|
|
|
|
|
+// The delta time of this integration step.
|
|
|
////////////////////////////////////////////////////////////////////
|
|
////////////////////////////////////////////////////////////////////
|
|
|
void LinearEulerIntegrator::
|
|
void LinearEulerIntegrator::
|
|
|
child_integrate(Physical *physical,
|
|
child_integrate(Physical *physical,
|
|
|
pvector< PT(LinearForce) >& forces,
|
|
pvector< PT(LinearForce) >& forces,
|
|
|
float dt) {
|
|
float dt) {
|
|
|
- pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
|
|
|
|
|
-
|
|
|
|
|
// perform the precomputation. Note that the vector returned by
|
|
// perform the precomputation. Note that the vector returned by
|
|
|
// get_precomputed_matrices() has the matrices loaded in order of force
|
|
// get_precomputed_matrices() has the matrices loaded in order of force
|
|
|
// type: first global, then local. If you're using this as a guide to write
|
|
// type: first global, then local. If you're using this as a guide to write
|
|
|
// another integrator, be sure to process your forces global, then local.
|
|
// another integrator, be sure to process your forces global, then local.
|
|
|
// otherwise your transforms will be VERY bad.
|
|
// otherwise your transforms will be VERY bad.
|
|
|
precompute_linear_matrices(physical, forces);
|
|
precompute_linear_matrices(physical, forces);
|
|
|
- const pvector< LMatrix4f > &matrices = get_precomputed_linear_matrices();
|
|
|
|
|
|
|
+ const VectorOfMatrices &matrices = get_precomputed_linear_matrices();
|
|
|
|
|
|
|
|
// Loop through each object in the set. This processing occurs in O(pf) time,
|
|
// Loop through each object in the set. This processing occurs in O(pf) time,
|
|
|
// where p is the number of physical objects and f is the number of
|
|
// where p is the number of physical objects and f is the number of
|
|
@@ -67,14 +74,10 @@ child_integrate(Physical *physical,
|
|
|
// velocity of each physicsobject in the set. Accordingly, we have
|
|
// velocity of each physicsobject in the set. Accordingly, we have
|
|
|
// to grunt our way through each one. wrt caching of the xform matrix
|
|
// to grunt our way through each one. wrt caching of the xform matrix
|
|
|
// should help.
|
|
// should help.
|
|
|
-
|
|
|
|
|
|
|
+ pvector< PT(PhysicsObject) >::const_iterator current_object_iter;
|
|
|
current_object_iter = physical->get_object_vector().begin();
|
|
current_object_iter = physical->get_object_vector().begin();
|
|
|
for (; current_object_iter != physical->get_object_vector().end();
|
|
for (; current_object_iter != physical->get_object_vector().end();
|
|
|
current_object_iter++) {
|
|
current_object_iter++) {
|
|
|
- LVector3f md_accum_vec, non_md_accum_vec, accel_vec, vel_vec;
|
|
|
|
|
- LPoint3f pos;
|
|
|
|
|
- float mass;
|
|
|
|
|
-
|
|
|
|
|
PhysicsObject *current_object = *current_object_iter;
|
|
PhysicsObject *current_object = *current_object_iter;
|
|
|
|
|
|
|
|
// bail out if this object doesn't exist or doesn't want to be
|
|
// bail out if this object doesn't exist or doesn't want to be
|
|
@@ -86,6 +89,7 @@ child_integrate(Physical *physical,
|
|
|
continue;
|
|
continue;
|
|
|
|
|
|
|
|
// reset the accumulation vectors for this object
|
|
// reset the accumulation vectors for this object
|
|
|
|
|
+ LVector3f md_accum_vec, non_md_accum_vec, accel_vec, vel_vec;
|
|
|
md_accum_vec.set(0.0f, 0.0f, 0.0f);
|
|
md_accum_vec.set(0.0f, 0.0f, 0.0f);
|
|
|
non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
|
|
non_md_accum_vec.set(0.0f, 0.0f, 0.0f);
|
|
|
|
|
|
|
@@ -140,9 +144,9 @@ child_integrate(Physical *physical,
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
// get this object's physical info
|
|
// get this object's physical info
|
|
|
- pos = current_object->get_position();
|
|
|
|
|
|
|
+ LPoint3f pos = current_object->get_position();
|
|
|
vel_vec = current_object->get_velocity();
|
|
vel_vec = current_object->get_velocity();
|
|
|
- mass = current_object->get_mass();
|
|
|
|
|
|
|
+ float mass = current_object->get_mass();
|
|
|
|
|
|
|
|
// we want 'a' in F = ma
|
|
// we want 'a' in F = ma
|
|
|
// get it by computing F / m
|
|
// get it by computing F / m
|
|
@@ -170,6 +174,19 @@ child_integrate(Physical *physical,
|
|
|
}
|
|
}
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+// Function : output
|
|
|
|
|
+// Access : Public
|
|
|
|
|
+// Description : Write a string representation of this instance to
|
|
|
|
|
+// <out>.
|
|
|
|
|
+////////////////////////////////////////////////////////////////////
|
|
|
|
|
+void LinearEulerIntegrator::
|
|
|
|
|
+output(ostream &out, unsigned int indent) const {
|
|
|
|
|
+ out.width(indent);
|
|
|
|
|
+ out<<""<<"LinearEulerIntegrator:\n";
|
|
|
|
|
+ LinearIntegrator::output(out, indent+2);
|
|
|
|
|
+}
|
|
|
|
|
+
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|