remove unused parameters from ObjectConstraintHinge

This commit is contained in:
Andrew Meadows 2017-05-12 12:01:54 -07:00
parent bc6fb182eb
commit 18b1bb8b7f
2 changed files with 14 additions and 68 deletions

View file

@ -16,7 +16,8 @@
#include "PhysicsLogging.h"
const uint16_t ObjectConstraintHinge::constraintVersion = 1;
const uint16_t HINGE_VERSION_WITH_UNUSED_PAREMETERS = 1;
const uint16_t ObjectConstraintHinge::constraintVersion = 2;
const glm::vec3 DEFAULT_HINGE_AXIS(1.0f, 0.0f, 0.0f);
ObjectConstraintHinge::ObjectConstraintHinge(const QUuid& id, EntityItemPointer ownerEntity) :
@ -56,25 +57,19 @@ void ObjectConstraintHinge::updateHinge() {
glm::vec3 axisInA;
float low;
float high;
float softness;
float biasFactor;
float relaxationFactor;
withReadLock([&]{
axisInA = _axisInA;
constraint = static_cast<btHingeConstraint*>(_constraint);
low = _low;
high = _high;
biasFactor = _biasFactor;
relaxationFactor = _relaxationFactor;
softness = _softness;
});
if (!constraint) {
return;
}
constraint->setLimit(low, high, softness, biasFactor, relaxationFactor);
constraint->setLimit(low, high);
}
@ -159,9 +154,6 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
glm::vec3 axisInB;
float low;
float high;
float softness;
float biasFactor;
float relaxationFactor;
bool needUpdate = false;
bool somethingChanged = ObjectDynamic::updateArguments(arguments);
@ -209,25 +201,6 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
high = _high;
}
ok = true;
softness = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments, "softness", ok, false);
if (!ok) {
softness = _softness;
}
ok = true;
biasFactor = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments, "biasFactor", ok, false);
if (!ok) {
biasFactor = _biasFactor;
}
ok = true;
relaxationFactor = EntityDynamicInterface::extractFloatArgument("hinge constraint", arguments,
"relaxationFactor", ok, false);
if (!ok) {
relaxationFactor = _relaxationFactor;
}
if (somethingChanged ||
pivotInA != _pivotInA ||
axisInA != _axisInA ||
@ -235,10 +208,7 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
pivotInB != _pivotInB ||
axisInB != _axisInB ||
low != _low ||
high != _high ||
softness != _softness ||
biasFactor != _biasFactor ||
relaxationFactor != _relaxationFactor) {
high != _high) {
// something changed
needUpdate = true;
}
@ -253,9 +223,6 @@ bool ObjectConstraintHinge::updateArguments(QVariantMap arguments) {
_axisInB = axisInB;
_low = low;
_high = high;
_softness = softness;
_biasFactor = biasFactor;
_relaxationFactor = relaxationFactor;
_active = true;
@ -282,9 +249,6 @@ QVariantMap ObjectConstraintHinge::getArguments() {
arguments["otherAxis"] = glmToQMap(_axisInB);
arguments["low"] = _low;
arguments["high"] = _high;
arguments["softness"] = _softness;
arguments["biasFactor"] = _biasFactor;
arguments["relaxationFactor"] = _relaxationFactor;
if (_constraint) {
arguments["angle"] = static_cast<btHingeConstraint*>(_constraint)->getHingeAngle(); // [-PI,PI]
} else {
@ -310,9 +274,6 @@ QByteArray ObjectConstraintHinge::serialize() const {
dataStream << _axisInB;
dataStream << _low;
dataStream << _high;
dataStream << _softness;
dataStream << _biasFactor;
dataStream << _relaxationFactor;
dataStream << localTimeToServerTime(_expires);
dataStream << _tag;
@ -334,7 +295,7 @@ void ObjectConstraintHinge::deserialize(QByteArray serializedArguments) {
uint16_t serializationVersion;
dataStream >> serializationVersion;
if (serializationVersion != ObjectConstraintHinge::constraintVersion) {
if (serializationVersion > ObjectConstraintHinge::constraintVersion) {
assert(false);
return;
}
@ -347,9 +308,12 @@ void ObjectConstraintHinge::deserialize(QByteArray serializedArguments) {
dataStream >> _axisInB;
dataStream >> _low;
dataStream >> _high;
dataStream >> _softness;
dataStream >> _biasFactor;
dataStream >> _relaxationFactor;
if (serializationVersion == HINGE_VERSION_WITH_UNUSED_PAREMETERS) {
float softness, biasFactor, relaxationFactor;
dataStream >> softness;
dataStream >> biasFactor;
dataStream >> relaxationFactor;
}
quint64 serverExpires;
dataStream >> serverExpires;

View file

@ -48,27 +48,9 @@ protected:
// https://gamedev.stackexchange.com/questions/71436/what-are-the-parameters-for-bthingeconstraintsetlimit
//
// softness: a negative measure of the friction that determines how much the hinge rotates for a given force. A high
// softness would make the hinge rotate easily like it's oiled then.
// biasFactor: an offset for the relaxed rotation of the hinge. It won't be right in the middle of the low and high angles
// anymore. 1.0f is the neural value.
// relaxationFactor: a measure of how much force is applied internally to bring the hinge in its central rotation.
// This is right in the middle of the low and high angles. For example, consider a western swing door. After
// walking through it will swing in both directions but at the end it stays right in the middle.
// http://javadoc.jmonkeyengine.org/com/jme3/bullet/joints/HingeJoint.html
//
// _softness - the factor at which the velocity error correction starts operating, i.e. a softness of 0.9 means that
// the vel. corr starts at 90% of the limit range.
// _biasFactor - the magnitude of the position correction. It tells you how strictly the position error (drift) is
// corrected.
// _relaxationFactor - the rate at which velocity errors are corrected. This can be seen as the strength of the
// limits. A low value will make the the limits more spongy.
float _softness { 0.9f };
float _biasFactor { 0.3f };
float _relaxationFactor { 1.0f };
// softness: unused
// biasFactor: unused
// relaxationFactor: unused
};
#endif // hifi_ObjectConstraintHinge_h