Added support to modify the angular factor of a kart. The angular

factor can be used to reduce the effect of an impulse for roll
and pitch - keeping karts more parallel to the ground.
This commit is contained in:
hiker 2017-03-23 19:07:34 +11:00
parent f55c39b3b1
commit b8655e53cc
8 changed files with 37 additions and 2 deletions

View File

@ -45,6 +45,9 @@
the ground if its off ground. Reduces the affect if a kart loses the ground if its off ground. Reduces the affect if a kart loses
contact with the ground (i.e. it then can't steer or accelerate contact with the ground (i.e. it then can't steer or accelerate
anymore). anymore).
angular-factor: Factor to change angular impulses. X and Z rotations
are damped to avoid that karts in a collision are too easily pushed
into a roll or pitch, which makes them topple over
smooth-flying-impulse: apply a torque impulse to flying kart to keep smooth-flying-impulse: apply a torque impulse to flying kart to keep
them parallel to the ground. --> them parallel to the ground. -->
<stability roll-influence="0.3" <stability roll-influence="0.3"
@ -52,6 +55,7 @@
chassis-angular-damping="0" chassis-angular-damping="0"
downward-impulse-factor="5" downward-impulse-factor="5"
track-connection-accel="2" track-connection-accel="2"
angular-factor="1.0 1.0 1.0"
smooth-flying-impulse="250" /> smooth-flying-impulse="250" />
<!-- Turning <!-- Turning

View File

@ -74,6 +74,8 @@ AbstractCharacteristic::ValueType AbstractCharacteristic::getType(
return TYPE_FLOAT; return TYPE_FLOAT;
case STABILITY_TRACK_CONNECTION_ACCEL: case STABILITY_TRACK_CONNECTION_ACCEL:
return TYPE_FLOAT; return TYPE_FLOAT;
case STABILITY_ANGULAR_FACTOR:
return TYPE_FLOAT_VECTOR;
case STABILITY_SMOOTH_FLYING_IMPULSE: case STABILITY_SMOOTH_FLYING_IMPULSE:
return TYPE_FLOAT; return TYPE_FLOAT;
case TURN_RADIUS: case TURN_RADIUS:
@ -304,6 +306,8 @@ std::string AbstractCharacteristic::getName(CharacteristicType type)
return "STABILITY_DOWNWARD_IMPULSE_FACTOR"; return "STABILITY_DOWNWARD_IMPULSE_FACTOR";
case STABILITY_TRACK_CONNECTION_ACCEL: case STABILITY_TRACK_CONNECTION_ACCEL:
return "STABILITY_TRACK_CONNECTION_ACCEL"; return "STABILITY_TRACK_CONNECTION_ACCEL";
case STABILITY_ANGULAR_FACTOR:
return "STABILITY_ANGULAR_FACTOR";
case STABILITY_SMOOTH_FLYING_IMPULSE: case STABILITY_SMOOTH_FLYING_IMPULSE:
return "STABILITY_SMOOTH_FLYING_IMPULSE"; return "STABILITY_SMOOTH_FLYING_IMPULSE";
case TURN_RADIUS: case TURN_RADIUS:
@ -626,6 +630,18 @@ float AbstractCharacteristic::getStabilityTrackConnectionAccel() const
return result; return result;
} // getStabilityTrackConnectionAccel } // getStabilityTrackConnectionAccel
// ----------------------------------------------------------------------------
std::vector<float> AbstractCharacteristic::getStabilityAngularFactor() const
{
std::vector<float> result;
bool is_set = false;
process(STABILITY_ANGULAR_FACTOR, &result, &is_set);
if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(STABILITY_ANGULAR_FACTOR).c_str());
return result;
} // getStabilityAngularFactor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float AbstractCharacteristic::getStabilitySmoothFlyingImpulse() const float AbstractCharacteristic::getStabilitySmoothFlyingImpulse() const
{ {
@ -1006,7 +1022,7 @@ float AbstractCharacteristic::getFrictionKartFriction() const
process(FRICTION_KART_FRICTION, &result, &is_set); process(FRICTION_KART_FRICTION, &result, &is_set);
if (!is_set) if (!is_set)
Log::fatal("AbstractCharacteristic", "Can't get characteristic %s", Log::fatal("AbstractCharacteristic", "Can't get characteristic %s",
getName(FRICTION_KART_FRICTION).c_str()); getName(FRICTION_KART_FRICTION).c_str());
return result; return result;
} // getFrictionKartFriction } // getFrictionKartFriction

View File

@ -84,6 +84,7 @@ public:
STABILITY_CHASSIS_ANGULAR_DAMPING, STABILITY_CHASSIS_ANGULAR_DAMPING,
STABILITY_DOWNWARD_IMPULSE_FACTOR, STABILITY_DOWNWARD_IMPULSE_FACTOR,
STABILITY_TRACK_CONNECTION_ACCEL, STABILITY_TRACK_CONNECTION_ACCEL,
STABILITY_ANGULAR_FACTOR,
STABILITY_SMOOTH_FLYING_IMPULSE, STABILITY_SMOOTH_FLYING_IMPULSE,
// Turn // Turn
@ -269,6 +270,7 @@ public:
float getStabilityChassisAngularDamping() const; float getStabilityChassisAngularDamping() const;
float getStabilityDownwardImpulseFactor() const; float getStabilityDownwardImpulseFactor() const;
float getStabilityTrackConnectionAccel() const; float getStabilityTrackConnectionAccel() const;
std::vector<float> getStabilityAngularFactor() const;
float getStabilitySmoothFlyingImpulse() const; float getStabilitySmoothFlyingImpulse() const;
InterpolationArray getTurnRadius() const; InterpolationArray getTurnRadius() const;

View File

@ -668,6 +668,10 @@ void Kart::createPhysics()
trans.setIdentity(); trans.setIdentity();
createBody(mass, trans, &m_kart_chassis, createBody(mass, trans, &m_kart_chassis,
m_kart_properties->getRestitution()); m_kart_properties->getRestitution());
std::vector<float> ang_fact = m_kart_properties->getStabilityAngularFactor();
// The angular factor (with X and Z values <1) helps to keep the kart
// upright, especially in case of a collision.
m_body->setAngularFactor(Vec3(ang_fact[0], ang_fact[1], ang_fact[2]));
m_body->setFriction(m_kart_properties->getFrictionKartFriction()); m_body->setFriction(m_kart_properties->getFrictionKartFriction());
m_user_pointer.set(this); m_user_pointer.set(this);
m_body->setDamping(m_kart_properties->getStabilityChassisLinearDamping(), m_body->setDamping(m_kart_properties->getStabilityChassisLinearDamping(),

View File

@ -597,6 +597,12 @@ float KartProperties::getStabilityTrackConnectionAccel() const
return m_cached_characteristic->getStabilityTrackConnectionAccel(); return m_cached_characteristic->getStabilityTrackConnectionAccel();
} // getStabilityTrackConnectionAccel } // getStabilityTrackConnectionAccel
// ----------------------------------------------------------------------------
std::vector<float> KartProperties::getStabilityAngularFactor() const
{
return m_cached_characteristic->getStabilityAngularFactor();
} // getStabilityAngularFactor
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
float KartProperties::getStabilitySmoothFlyingImpulse() const float KartProperties::getStabilitySmoothFlyingImpulse() const
{ {

View File

@ -431,6 +431,7 @@ public:
float getStabilityChassisAngularDamping() const; float getStabilityChassisAngularDamping() const;
float getStabilityDownwardImpulseFactor() const; float getStabilityDownwardImpulseFactor() const;
float getStabilityTrackConnectionAccel() const; float getStabilityTrackConnectionAccel() const;
std::vector<float> getStabilityAngularFactor() const;
float getStabilitySmoothFlyingImpulse() const; float getStabilitySmoothFlyingImpulse() const;
InterpolationArray getTurnRadius() const; InterpolationArray getTurnRadius() const;

View File

@ -343,6 +343,8 @@ void XmlCharacteristic::load(const XMLNode *node)
&m_values[STABILITY_DOWNWARD_IMPULSE_FACTOR]); &m_values[STABILITY_DOWNWARD_IMPULSE_FACTOR]);
sub_node->get("track-connection-accel", sub_node->get("track-connection-accel",
&m_values[STABILITY_TRACK_CONNECTION_ACCEL]); &m_values[STABILITY_TRACK_CONNECTION_ACCEL]);
sub_node->get("angular-factor",
&m_values[STABILITY_ANGULAR_FACTOR]);
sub_node->get("smooth-flying-impulse", sub_node->get("smooth-flying-impulse",
&m_values[STABILITY_SMOOTH_FLYING_IMPULSE]); &m_values[STABILITY_SMOOTH_FLYING_IMPULSE]);
} }

View File

@ -28,7 +28,7 @@ import sys
# Each line contains a topic and the attributes of that topic. # Each line contains a topic and the attributes of that topic.
# This model is used for the xml file and to access the kart properties in the code. # This model is used for the xml file and to access the kart properties in the code.
characteristics = """Suspension: stiffness, rest, travel, expSpringResponse(bool), maxForce characteristics = """Suspension: stiffness, rest, travel, expSpringResponse(bool), maxForce
Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, smoothFlyingImpulse Stability: rollInfluence, chassisLinearDamping, chassisAngularDamping, downwardImpulseFactor, trackConnectionAccel, angularFactor(std::vector<float>/floatVector), smoothFlyingImpulse
Turn: radius(InterpolationArray), timeResetSteer, timeFullSteer(InterpolationArray) Turn: radius(InterpolationArray), timeResetSteer, timeFullSteer(InterpolationArray)
Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio Engine: power, maxSpeed, brakeFactor, brakeTimeIncrease, maxSpeedReverseRatio
Gear: switchRatio(std::vector<float>/floatVector), powerIncrease(std::vector<float>/floatVector) Gear: switchRatio(std::vector<float>/floatVector), powerIncrease(std::vector<float>/floatVector)