work in progress: add_impact

This commit is contained in:
Dave Schuyler 2006-03-14 02:02:23 +00:00
parent efc319c451
commit b2a0448de9

View File

@ -124,19 +124,26 @@ add_local_impact(const LPoint3f &offset_from_center_of_mass,
// offset and force are in global (or parent) coordinates. // offset and force are in global (or parent) coordinates.
//////////////////////////////////////////////////////////////////// ////////////////////////////////////////////////////////////////////
void PhysicsObject:: void PhysicsObject::
add_impact(const LPoint3f &offset_from_center_of_mass, add_impact(const LPoint3f &offset,
const LVector3f &force) { const LVector3f &force) {
nassertv(!offset_from_center_of_mass.is_nan()); nassertv(!offset.is_nan());
nassertv(!force.is_nan()); nassertv(!force.is_nan());
LVector3f a = -offset_from_center_of_mass; LVector3f a = offset;
LVector3f b = force; LVector3f b = force;
a.normalize(); a.normalize();
b.normalize(); b.normalize();
float theta = a.dot(b); a = a.cross(b);
LRotationf torque; float angle = a.length();
torque.set_from_axis_angle((1.0f - theta) * a.length(), b.cross(a).normalize()); if (angle) {
LVector3f impulse = theta * force; LRotationf torque;
add_torque(torque); float spin = force.length()*0.1f; // todo: this should account for
// impact distance and mass.
a.normalize();
assert(IS_THRESHOLD_EQUAL(a.length(), 1.0f, 0.001f));
torque.set_from_axis_angle(spin, a);
add_torque(torque);
}
LVector3f impulse = (1.0f - angle) * force;
add_impulse(impulse); add_impulse(impulse);
} }