create MuscleConstraint for driving ragdolls

This commit is contained in:
Andrew Meadows 2014-07-25 15:24:14 -07:00
parent 60612f6397
commit c8405d192d
2 changed files with 77 additions and 0 deletions

View file

@ -0,0 +1,34 @@
//
// MuscleConstraint.cpp
// interface/src/avatar
//
// Created by Andrew Meadows 2014.07.24
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#include <SharedUtil.h>
#include <VerletPoint.h>
#include "MuscleConstraint.h"
const float DEFAULT_MUSCLE_STRENGTH = 0.5f * MAX_MUSCLE_STRENGTH;
MuscleConstraint::MuscleConstraint(VerletPoint* parent, VerletPoint* child)
: _rootPoint(parent), _childoint(child),
_parentIndex(-1), _childndex(-1), _strength(DEFAULT_MUSCLE_STRENGTH) {
_childOffset = child->_position - parent->_position;
}
float MuscleConstraint::enforce() {
_childoint->_position = (1.0f - _strength) * _childoint->_position + _strength * (_rootPoint->_position + _childOffset);
return 0.0f;
}
void MuscleConstraint::setIndices(int parent, int child) {
_parentIndex = parent;
_childndex = child;
}

View file

@ -0,0 +1,43 @@
//
// MuscleConstraint.h
// interface/src/avatar
//
// Created by Andrew Meadows 2014.07.24
// Copyright 2014 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifndef hifi_MuscleConstraint_h
#define hifi_MuscleConstraint_h
#include <Constraint.h>
// MuscleConstraint is a simple constraint that pushes the child toward an offset relative to the parent.
// It does NOT push the parent.
const float MAX_MUSCLE_STRENGTH = 0.5f;
class MuscleConstraint : public Constraint {
public:
MuscleConstraint(VerletPoint* parent, VerletPoint* child);
MuscleConstraint(const MuscleConstraint& other);
float enforce();
void setIndices(int parent, int child);
int getParentIndex() const { return _parentIndex; }
int getChildIndex() const { return _childndex; }
void setChildOffset(const glm::vec3& offset) { _childOffset = offset; }
void setStrength(float strength) { _strength = glm::clamp(strength, 0.0f, MAX_MUSCLE_STRENGTH); }
float getStrength() const { return _strength; }
private:
VerletPoint* _rootPoint;
VerletPoint* _childoint;
int _parentIndex;
int _childndex;
glm::vec3 _childOffset;
float _strength; // a value in range [0,MAX_MUSCLE_STRENGTH]
};
#endif // hifi_MuscleConstraint_h