cleanup Ragdoll API (less "ragdoll" qualifiers)

This commit is contained in:
Andrew Meadows 2014-08-14 14:41:51 -07:00
parent 46c91052c9
commit 60d411ead5
6 changed files with 75 additions and 75 deletions

View file

@ -497,7 +497,7 @@ void SkeletonModel::renderRagdoll() {
if (!_ragdoll) {
return;
}
const QVector<VerletPoint>& points = _ragdoll->getRagdollPoints();
const QVector<VerletPoint>& points = _ragdoll->getPoints();
const int BALL_SUBDIVISIONS = 6;
glDisable(GL_DEPTH_TEST);
glDisable(GL_LIGHTING);
@ -531,7 +531,7 @@ void SkeletonModel::updateVisibleJointStates() {
// no need to update visible transforms
return;
}
const QVector<VerletPoint>& ragdollPoints = _ragdoll->getRagdollPoints();
const QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
QVector<glm::vec3> points;
points.reserve(_jointStates.size());
glm::quat invRotation = glm::inverse(_rotation);
@ -599,8 +599,8 @@ void SkeletonModel::buildShapes() {
if (!_ragdoll) {
_ragdoll = new SkeletonRagdoll(this);
}
_ragdoll->initRagdollPoints();
QVector<VerletPoint>& points = _ragdoll->getRagdollPoints();
_ragdoll->initPoints();
QVector<VerletPoint>& points = _ragdoll->getPoints();
float massScale = _ragdoll->getMassScale();
@ -651,11 +651,11 @@ void SkeletonModel::buildShapes() {
// joints that are currently colliding.
disableCurrentSelfCollisions();
_ragdoll->buildRagdollConstraints();
_ragdoll->buildConstraints();
// ... then move shapes back to current joint positions
_ragdoll->slamPointPositions();
_ragdoll->enforceRagdollConstraints();
_ragdoll->enforceConstraints();
}
void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
@ -663,7 +663,7 @@ void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
// unravel a skelton that has become tangled in its constraints. So let's keep this
// around for a while just in case.
const int numStates = _jointStates.size();
QVector<VerletPoint>& ragdollPoints = _ragdoll->getRagdollPoints();
QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
assert(_jointStates.size() == ragdollPoints.size());
if (ragdollPoints.size() != numStates) {
return;
@ -688,7 +688,7 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
QVector<glm::mat4> transforms;
transforms.fill(glm::mat4(), numStates);
QVector<VerletPoint>& ragdollPoints = _ragdoll->getRagdollPoints();
QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
// compute the default transforms and slam the ragdoll positions accordingly
// (which puts the shapes where we want them)

View file

@ -24,9 +24,9 @@ SkeletonRagdoll::~SkeletonRagdoll() {
}
// virtual
void SkeletonRagdoll::stepRagdollForward(float deltaTime) {
setRagdollTransform(_model->getTranslation(), _model->getRotation());
Ragdoll::stepRagdollForward(deltaTime);
void SkeletonRagdoll::stepForward(float deltaTime) {
setTransform(_model->getTranslation(), _model->getRotation());
Ragdoll::stepForward(deltaTime);
updateMuscles();
int numConstraints = _muscleConstraints.size();
for (int i = 0; i < numConstraints; ++i) {
@ -38,30 +38,30 @@ void SkeletonRagdoll::slamPointPositions() {
QVector<JointState>& jointStates = _model->getJointStates();
int numStates = jointStates.size();
for (int i = 0; i < numStates; ++i) {
_ragdollPoints[i].initPosition(jointStates.at(i).getPosition());
_points[i].initPosition(jointStates.at(i).getPosition());
}
}
// virtual
void SkeletonRagdoll::initRagdollPoints() {
clearRagdollConstraintsAndPoints();
void SkeletonRagdoll::initPoints() {
clearConstraintsAndPoints();
_muscleConstraints.clear();
initRagdollTransform();
initTransform();
// one point for each joint
QVector<JointState>& jointStates = _model->getJointStates();
int numStates = jointStates.size();
_ragdollPoints.fill(VerletPoint(), numStates);
_points.fill(VerletPoint(), numStates);
slamPointPositions();
}
// virtual
void SkeletonRagdoll::buildRagdollConstraints() {
void SkeletonRagdoll::buildConstraints() {
QVector<JointState>& jointStates = _model->getJointStates();
// NOTE: the length of DistanceConstraints is computed and locked in at this time
// so make sure the ragdoll positions are in a normal configuration before here.
const int numPoints = _ragdollPoints.size();
const int numPoints = _points.size();
assert(numPoints == jointStates.size());
float minBone = FLT_MAX;
@ -71,10 +71,10 @@ void SkeletonRagdoll::buildRagdollConstraints() {
const JointState& state = jointStates.at(i);
int parentIndex = state.getParentIndex();
if (parentIndex == -1) {
FixedConstraint* anchor = new FixedConstraint(&_translationInSimulationFrame, &(_ragdollPoints[i]));
FixedConstraint* anchor = new FixedConstraint(&_translationInSimulationFrame, &(_points[i]));
_fixedConstraints.push_back(anchor);
} else {
DistanceConstraint* bone = new DistanceConstraint(&(_ragdollPoints[i]), &(_ragdollPoints[parentIndex]));
DistanceConstraint* bone = new DistanceConstraint(&(_points[i]), &(_points[parentIndex]));
bone->setDistance(state.getDistanceToParent());
_boneConstraints.push_back(bone);
families.insert(parentIndex, i);
@ -94,11 +94,11 @@ void SkeletonRagdoll::buildRagdollConstraints() {
int numChildren = children.size();
if (numChildren > 1) {
for (int i = 1; i < numChildren; ++i) {
DistanceConstraint* bone = new DistanceConstraint(&(_ragdollPoints[children[i-1]]), &(_ragdollPoints[children[i]]));
DistanceConstraint* bone = new DistanceConstraint(&(_points[children[i-1]]), &(_points[children[i]]));
_boneConstraints.push_back(bone);
}
if (numChildren > 2) {
DistanceConstraint* bone = new DistanceConstraint(&(_ragdollPoints[children[numChildren-1]]), &(_ragdollPoints[children[0]]));
DistanceConstraint* bone = new DistanceConstraint(&(_points[children[numChildren-1]]), &(_points[children[0]]));
_boneConstraints.push_back(bone);
}
}
@ -114,7 +114,7 @@ void SkeletonRagdoll::buildRagdollConstraints() {
if (p == -1) {
continue;
}
MuscleConstraint* constraint = new MuscleConstraint(&(_ragdollPoints[p]), &(_ragdollPoints[i]));
MuscleConstraint* constraint = new MuscleConstraint(&(_points[p]), &(_points[i]));
_muscleConstraints.push_back(constraint);
// Short joints are more susceptible to wiggle so we modulate the strength based on the joint's length:

View file

@ -28,10 +28,10 @@ public:
virtual ~SkeletonRagdoll();
void slamPointPositions();
virtual void stepRagdollForward(float deltaTime);
virtual void stepForward(float deltaTime);
virtual void initRagdollPoints();
virtual void buildRagdollConstraints();
virtual void initPoints();
virtual void buildConstraints();
void updateMuscles();
private:

View file

@ -47,12 +47,12 @@ PhysicsSimulation::~PhysicsSimulation() {
void PhysicsSimulation::setRagdoll(Ragdoll* ragdoll) {
if (_ragdoll != ragdoll) {
if (_ragdoll) {
_ragdoll->_ragdollSimulation = NULL;
_ragdoll->_simulation = NULL;
}
_ragdoll = ragdoll;
if (_ragdoll) {
assert(!(_ragdoll->_ragdollSimulation));
_ragdoll->_ragdollSimulation = this;
assert(!(_ragdoll->_simulation));
_ragdoll->_simulation = this;
}
}
}
@ -144,7 +144,7 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
// list is full
return false;
}
if (doll->_ragdollSimulation == this) {
if (doll->_simulation == this) {
for (int i = 0; i < numDolls; ++i) {
if (doll == _otherRagdolls[i]) {
// already in list
@ -153,8 +153,8 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
}
}
// add to list
assert(!(doll->_ragdollSimulation));
doll->_ragdollSimulation = this;
assert(!(doll->_simulation));
doll->_simulation = this;
_otherRagdolls.push_back(doll);
// set the massScale of otherRagdolls artificially high
@ -164,7 +164,7 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
int numDolls = _otherRagdolls.size();
if (doll->_ragdollSimulation != this) {
if (doll->_simulation != this) {
return;
}
for (int i = 0; i < numDolls; ++i) {
@ -178,7 +178,7 @@ void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
_otherRagdolls.pop_back();
_otherRagdolls[i] = lastDoll;
}
doll->_ragdollSimulation = NULL;
doll->_simulation = NULL;
doll->setMassScale(1.0f);
break;
}
@ -199,9 +199,9 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
int numDolls = _otherRagdolls.size();
{
PerformanceTimer perfTimer("enforce");
_ragdoll->enforceRagdollConstraints();
_ragdoll->enforceConstraints();
for (int i = 0; i < numDolls; ++i) {
_otherRagdolls[i]->enforceRagdollConstraints();
_otherRagdolls[i]->enforceConstraints();
}
}
@ -214,9 +214,9 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
{ // enforce constraints
PerformanceTimer perfTimer("enforce");
error = _ragdoll->enforceRagdollConstraints();
error = _ragdoll->enforceConstraints();
for (int i = 0; i < numDolls; ++i) {
error = glm::max(error, _otherRagdolls[i]->enforceRagdollConstraints());
error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
}
}
enforceContactConstraints();
@ -230,10 +230,10 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
void PhysicsSimulation::moveRagdolls(float deltaTime) {
PerformanceTimer perfTimer("integrate");
_ragdoll->stepRagdollForward(deltaTime);
_ragdoll->stepForward(deltaTime);
int numDolls = _otherRagdolls.size();
for (int i = 0; i < numDolls; ++i) {
_otherRagdolls[i]->stepRagdollForward(deltaTime);
_otherRagdolls[i]->stepForward(deltaTime);
}
}

View file

@ -19,27 +19,27 @@
#include "PhysicsSimulation.h"
#include "SharedUtil.h" // for EPSILON
Ragdoll::Ragdoll() : _massScale(1.0f), _ragdollTranslation(0.0f), _translationInSimulationFrame(0.0f), _ragdollSimulation(NULL) {
Ragdoll::Ragdoll() : _massScale(1.0f), _translation(0.0f), _translationInSimulationFrame(0.0f), _simulation(NULL) {
}
Ragdoll::~Ragdoll() {
clearRagdollConstraintsAndPoints();
if (_ragdollSimulation) {
_ragdollSimulation->removeRagdoll(this);
clearConstraintsAndPoints();
if (_simulation) {
_simulation->removeRagdoll(this);
}
}
void Ragdoll::stepRagdollForward(float deltaTime) {
if (_ragdollSimulation) {
updateSimulationTransforms(_ragdollTranslation - _ragdollSimulation->getTranslation(), _ragdollRotation);
void Ragdoll::stepForward(float deltaTime) {
if (_simulation) {
updateSimulationTransforms(_translation - _simulation->getTranslation(), _rotation);
}
int numPoints = _ragdollPoints.size();
int numPoints = _points.size();
for (int i = 0; i < numPoints; ++i) {
_ragdollPoints[i].integrateForward();
_points[i].integrateForward();
}
}
void Ragdoll::clearRagdollConstraintsAndPoints() {
void Ragdoll::clearConstraintsAndPoints() {
int numConstraints = _boneConstraints.size();
for (int i = 0; i < numConstraints; ++i) {
delete _boneConstraints[i];
@ -50,10 +50,10 @@ void Ragdoll::clearRagdollConstraintsAndPoints() {
delete _fixedConstraints[i];
}
_fixedConstraints.clear();
_ragdollPoints.clear();
_points.clear();
}
float Ragdoll::enforceRagdollConstraints() {
float Ragdoll::enforceConstraints() {
float maxDistance = 0.0f;
// enforce the bone constraints first
int numConstraints = _boneConstraints.size();
@ -68,16 +68,16 @@ float Ragdoll::enforceRagdollConstraints() {
return maxDistance;
}
void Ragdoll::initRagdollTransform() {
_ragdollTranslation = glm::vec3(0.0f);
_ragdollRotation = glm::quat();
void Ragdoll::initTransform() {
_translation = glm::vec3(0.0f);
_rotation = glm::quat();
_translationInSimulationFrame = glm::vec3(0.0f);
_rotationInSimulationFrame = glm::quat();
}
void Ragdoll::setRagdollTransform(const glm::vec3& translation, const glm::quat& rotation) {
_ragdollTranslation = translation;
_ragdollRotation = rotation;
void Ragdoll::setTransform(const glm::vec3& translation, const glm::quat& rotation) {
_translation = translation;
_rotation = rotation;
}
void Ragdoll::updateSimulationTransforms(const glm::vec3& translation, const glm::quat& rotation) {
@ -93,9 +93,9 @@ void Ragdoll::updateSimulationTransforms(const glm::vec3& translation, const glm
glm::quat deltaRotation = rotation * glm::inverse(_rotationInSimulationFrame);
// apply the deltas to all ragdollPoints
int numPoints = _ragdollPoints.size();
int numPoints = _points.size();
for (int i = 0; i < numPoints; ++i) {
_ragdollPoints[i].move(deltaPosition, deltaRotation, _translationInSimulationFrame);
_points[i].move(deltaPosition, deltaRotation, _translationInSimulationFrame);
}
// remember the current transform
@ -109,9 +109,9 @@ void Ragdoll::setMassScale(float scale) {
scale = glm::clamp(glm::abs(scale), MIN_SCALE, MAX_SCALE);
if (scale != _massScale) {
float rescale = scale / _massScale;
int numPoints = _ragdollPoints.size();
int numPoints = _points.size();
for (int i = 0; i < numPoints; ++i) {
_ragdollPoints[i].setMass(rescale * _ragdollPoints[i].getMass());
_points[i].setMass(rescale * _points[i].getMass());
}
_massScale = scale;
}

View file

@ -33,44 +33,44 @@ public:
Ragdoll();
virtual ~Ragdoll();
virtual void stepRagdollForward(float deltaTime);
virtual void stepForward(float deltaTime);
/// \return max distance of point movement
float enforceRagdollConstraints();
float enforceConstraints();
// both const and non-const getPoints()
const QVector<VerletPoint>& getRagdollPoints() const { return _ragdollPoints; }
QVector<VerletPoint>& getRagdollPoints() { return _ragdollPoints; }
const QVector<VerletPoint>& getPoints() const { return _points; }
QVector<VerletPoint>& getPoints() { return _points; }
void initRagdollTransform();
void initTransform();
/// set the translation and rotation of the Ragdoll and adjust all VerletPoints.
void setRagdollTransform(const glm::vec3& translation, const glm::quat& rotation);
void setTransform(const glm::vec3& translation, const glm::quat& rotation);
const glm::vec3& getTranslationInSimulationFrame() const { return _translationInSimulationFrame; }
void setMassScale(float scale);
float getMassScale() const { return _massScale; }
void clearRagdollConstraintsAndPoints();
virtual void initRagdollPoints() = 0;
virtual void buildRagdollConstraints() = 0;
void clearConstraintsAndPoints();
virtual void initPoints() = 0;
virtual void buildConstraints() = 0;
protected:
float _massScale;
glm::vec3 _ragdollTranslation; // world-frame
glm::quat _ragdollRotation; // world-frame
glm::vec3 _translation; // world-frame
glm::quat _rotation; // world-frame
glm::vec3 _translationInSimulationFrame;
glm::quat _rotationInSimulationFrame;
QVector<VerletPoint> _ragdollPoints;
QVector<VerletPoint> _points;
QVector<DistanceConstraint*> _boneConstraints;
QVector<FixedConstraint*> _fixedConstraints;
private:
void updateSimulationTransforms(const glm::vec3& translation, const glm::quat& rotation);
friend class PhysicsSimulation;
PhysicsSimulation* _ragdollSimulation;
PhysicsSimulation* _simulation;
};
#endif // hifi_Ragdoll_h