RagDoll keeps a pointer to list of shapes

This commit is contained in:
Andrew Meadows 2014-06-09 11:04:20 -07:00
parent b70020595c
commit 5a76a9b4b1
3 changed files with 22 additions and 11 deletions

View file

@ -37,7 +37,7 @@ void SkeletonModel::setJointStates(QVector<JointState> states) {
points.push_back(state.getPosition());
}
// ... and feed the results to _ragDoll
_ragDoll.init(parentIndices, points);
_ragDoll.init(&_jointShapes, parentIndices, points);
}
}
@ -286,7 +286,7 @@ void SkeletonModel::updateJointState(int index) {
void SkeletonModel::updateShapePositions() {
if (isActive() && _owningAvatar->isMyAvatar() &&
Menu::getInstance()->isOptionChecked(MenuOption::CollideAsRagDoll)) {
_ragDoll.updateShapes(_jointShapes, _rotation, _translation);
_ragDoll.updateShapes(_rotation, _translation);
} else {
Model::updateShapePositions();
}

View file

@ -94,15 +94,16 @@ void DistanceConstraint::updateProxyShape(Shape* shape, const glm::quat& rotatio
// RagDoll
// ----------------------------------------------------------------------------
RagDoll::RagDoll() {
RagDoll::RagDoll() : _shapes(NULL) {
}
RagDoll::~RagDoll() {
clear();
}
void RagDoll::init(const QVector<int>& parentIndices, const QVector<glm::vec3>& points) {
void RagDoll::init(QVector<Shape*>* shapes, const QVector<int>& parentIndices, const QVector<glm::vec3>& points) {
clear();
_shapes = shapes;
const int numPoints = points.size();
assert(numPoints == parentIndices.size());
_points.reserve(numPoints);
@ -143,10 +144,15 @@ float RagDoll::enforceConstraints() {
return maxDistance;
}
void RagDoll::updateShapes(const QVector<Shape*>& shapes, const glm::quat& rotation, const glm::vec3& translation) const {
int numShapes = shapes.size();
void RagDoll::updateShapes(const glm::quat& rotation, const glm::vec3& translation) const {
if (!_shapes) {
return;
}
int numShapes = _shapes->size();
int numConstraints = _constraints.size();
// NOTE: we assume a one-to-one relationship between shapes and constraints
for (int i = 0; i < numShapes && i < numConstraints; ++i) {
_constraints[i]->updateProxyShape(shapes[i], rotation, translation);
_constraints[i]->updateProxyShape((*_shapes)[i], rotation, translation);
}
}

View file

@ -69,7 +69,9 @@ public:
/// Create points and constraints based on topology of collection of joints
/// \param joints list of connected joint states
void init(const QVector<int>& parentIndices, const QVector<glm::vec3>& points);
void init(QVector<Shape*>* shapes, const QVector<int>& parentIndices, const QVector<glm::vec3>& points);
void setShapes(QVector<Shape*>* shapes) { _shapes = shapes; }
/// Delete all data.
void clear();
@ -82,14 +84,17 @@ public:
const QVector<glm::vec3>& getPoints() const { return _points; }
QVector<glm::vec3>& getPoints() { return _points; }
/// \param shapes list of shapes to be updated with new positions
/// \param rotation rotation into shapes' collision frame
/// \param translation translation into shapes' collision frame
void updateShapes(const QVector<Shape*>& shapes, const glm::quat& rotation, const glm::vec3& translation) const;
/// Moves and modifies elements of _shapes to agree with state of _points
void updateShapes(const glm::quat& rotation, const glm::vec3& translation) const;
private:
QVector<Constraint*> _constraints;
QVector<glm::vec3> _points;
QVector<Constraint*> _constraints;
// the RagDoll does NOT own the data in _shapes.
QVector<Shape*>* _shapes;
};
#endif // hifi_RagDoll_h