Skip to content

Commit

Permalink
UPBGE: Fix T46902: motion actuator apply zero velocity anyways.
Browse files Browse the repository at this point in the history
Previously even if there're a force or torque, the velocity was applied. To solve this the code check before appling velocity if there's a no force
for linear velocity and no torque for angular velocity.
  • Loading branch information
panzergame committed Dec 3, 2015
1 parent 9f57a7b commit 819e6cc
Showing 1 changed file with 53 additions and 49 deletions.
102 changes: 53 additions & 49 deletions source/gameengine/Ketsji/KX_ObjectActuator.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -277,64 +277,68 @@ bool KX_ObjectActuator::Update()
parent->ApplyRotation(m_drot,(m_bitLocalFlag.DRot) != 0);
}

if (m_bitLocalFlag.ZeroLinearVelocity) {
if (!m_bitLocalFlag.AddOrSetLinV) {
/* No need to select local or world, as the velocity is zero anyway,
* and setLinearVelocity() converts local to world first. We do need to
* pass a true zero vector, as m_linear_velocity is only fuzzily zero. */
parent->setLinearVelocity(MT_Vector3(0, 0, 0), false);
if (m_bitLocalFlag.ZeroForce) {
if (m_bitLocalFlag.ZeroLinearVelocity) {
if (!m_bitLocalFlag.AddOrSetLinV) {
/* No need to select local or world, as the velocity is zero anyway,
* and setLinearVelocity() converts local to world first. We do need to
* pass a true zero vector, as m_linear_velocity is only fuzzily zero. */
parent->setLinearVelocity(MT_Vector3(0, 0, 0), false);
}
}
else {
if (m_bitLocalFlag.AddOrSetLinV) {
parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
} else {
m_active_combined_velocity = true;
if (m_damping > 0) {
MT_Vector3 linV;
if (!m_linear_damping_active) {
// delta and the start speed (depends on the existing speed in that direction)
linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
// keep only the projection along the desired direction
m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2;
m_linear_damping_active = true;
}
if (m_current_linear_factor < 1.0)
m_current_linear_factor += 1.0/m_damping;
if (m_current_linear_factor > 1.0)
m_current_linear_factor = 1.0;
linV = m_current_linear_factor * m_linear_velocity;
parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0);
} else {
parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
}
}
}
}
else {
if (m_bitLocalFlag.AddOrSetLinV) {
parent->addLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
} else {
if (m_bitLocalFlag.ZeroTorque) {
if (m_bitLocalFlag.ZeroAngularVelocity) {
/* No need to select local or world, as the velocity is zero anyway,
* and setAngularVelocity() converts local to world first. We do need to
* pass a true zero vector, as m_angular_velocity is only fuzzily zero. */
parent->setAngularVelocity(MT_Vector3(0, 0, 0), false);
}
else {
m_active_combined_velocity = true;
if (m_damping > 0) {
MT_Vector3 linV;
if (!m_linear_damping_active) {
MT_Vector3 angV;
if (!m_angular_damping_active) {
// delta and the start speed (depends on the existing speed in that direction)
linV = parent->GetLinearVelocity(m_bitLocalFlag.LinearVelocity);
angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
// keep only the projection along the desired direction
m_current_linear_factor = linV.dot(m_linear_velocity)/m_linear_length2;
m_linear_damping_active = true;
m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2;
m_angular_damping_active = true;
}
if (m_current_linear_factor < 1.0)
m_current_linear_factor += 1.0/m_damping;
if (m_current_linear_factor > 1.0)
m_current_linear_factor = 1.0;
linV = m_current_linear_factor * m_linear_velocity;
parent->setLinearVelocity(linV,(m_bitLocalFlag.LinearVelocity) != 0);
if (m_current_angular_factor < 1.0)
m_current_angular_factor += 1.0/m_damping;
if (m_current_angular_factor > 1.0)
m_current_angular_factor = 1.0;
angV = m_current_angular_factor * m_angular_velocity;
parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0);
} else {
parent->setLinearVelocity(m_linear_velocity,(m_bitLocalFlag.LinearVelocity) != 0);
}
}
}
if (m_bitLocalFlag.ZeroAngularVelocity) {
/* No need to select local or world, as the velocity is zero anyway,
* and setAngularVelocity() converts local to world first. We do need to
* pass a true zero vector, as m_angular_velocity is only fuzzily zero. */
parent->setAngularVelocity(MT_Vector3(0, 0, 0), false);
}
else {
m_active_combined_velocity = true;
if (m_damping > 0) {
MT_Vector3 angV;
if (!m_angular_damping_active) {
// delta and the start speed (depends on the existing speed in that direction)
angV = parent->GetAngularVelocity(m_bitLocalFlag.AngularVelocity);
// keep only the projection along the desired direction
m_current_angular_factor = angV.dot(m_angular_velocity)/m_angular_length2;
m_angular_damping_active = true;
parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0);
}
if (m_current_angular_factor < 1.0)
m_current_angular_factor += 1.0/m_damping;
if (m_current_angular_factor > 1.0)
m_current_angular_factor = 1.0;
angV = m_current_angular_factor * m_angular_velocity;
parent->setAngularVelocity(angV,(m_bitLocalFlag.AngularVelocity) != 0);
} else {
parent->setAngularVelocity(m_angular_velocity,(m_bitLocalFlag.AngularVelocity) != 0);
}
}
}
Expand Down

0 comments on commit 819e6cc

Please sign in to comment.