mirror of
https://github.com/HifiExperiments/overte.git
synced 2025-08-14 13:36:29 +02:00
VerletPoint::_mass is now private
We set the mass of other avatars artificially high so they are less movable.
This commit is contained in:
parent
0f784a9cc5
commit
94da63006c
9 changed files with 46 additions and 12 deletions
|
@ -671,6 +671,7 @@ void SkeletonModel::buildShapes() {
|
|||
}
|
||||
|
||||
initRagdollPoints();
|
||||
float massScale = getMassScale();
|
||||
|
||||
float uniformScale = extractUniformScale(_scale);
|
||||
const int numStates = _jointStates.size();
|
||||
|
@ -689,12 +690,12 @@ void SkeletonModel::buildShapes() {
|
|||
if (type == Shape::SPHERE_SHAPE) {
|
||||
shape = new VerletSphereShape(radius, &(_ragdollPoints[i]));
|
||||
shape->setEntity(this);
|
||||
_ragdollPoints[i]._mass = glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume());
|
||||
_ragdollPoints[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
||||
} else if (type == Shape::CAPSULE_SHAPE) {
|
||||
assert(parentIndex != -1);
|
||||
shape = new VerletCapsuleShape(radius, &(_ragdollPoints[parentIndex]), &(_ragdollPoints[i]));
|
||||
shape->setEntity(this);
|
||||
_ragdollPoints[i]._mass = glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume());
|
||||
_ragdollPoints[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
||||
}
|
||||
if (parentIndex != -1) {
|
||||
// always disable collisions between joint and its parent
|
||||
|
@ -702,7 +703,7 @@ void SkeletonModel::buildShapes() {
|
|||
} else {
|
||||
// give the base joint a very large mass since it doesn't actually move
|
||||
// in the local-frame simulation (it defines the origin)
|
||||
_ragdollPoints[i]._mass = VERY_BIG_MASS;
|
||||
_ragdollPoints[i].setMass(VERY_BIG_MASS);
|
||||
}
|
||||
_shapes.push_back(shape);
|
||||
}
|
||||
|
|
|
@ -10,13 +10,11 @@
|
|||
//
|
||||
|
||||
#include "FixedConstraint.h"
|
||||
#include "Shape.h" // for MAX_SHAPE_MASS
|
||||
#include "VerletPoint.h"
|
||||
|
||||
FixedConstraint::FixedConstraint(glm::vec3* anchor, VerletPoint* point) : _anchor(anchor), _point(point) {
|
||||
assert(anchor);
|
||||
assert(point);
|
||||
_point->_mass = MAX_SHAPE_MASS;
|
||||
}
|
||||
|
||||
float FixedConstraint::enforce() {
|
||||
|
@ -34,5 +32,4 @@ void FixedConstraint::setAnchor(glm::vec3* anchor) {
|
|||
void FixedConstraint::setPoint(VerletPoint* point) {
|
||||
assert(point);
|
||||
_point = point;
|
||||
_point->_mass = MAX_SHAPE_MASS;
|
||||
}
|
||||
|
|
|
@ -133,6 +133,8 @@ void PhysicsSimulation::removeShapes(const PhysicsEntity* entity) {
|
|||
}
|
||||
}
|
||||
|
||||
const float OTHER_RAGDOLL_MASS_SCALE = 10.0f;
|
||||
|
||||
bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
||||
if (!doll) {
|
||||
return false;
|
||||
|
@ -154,6 +156,9 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
|||
assert(!(doll->_ragdollSimulation));
|
||||
doll->_ragdollSimulation = this;
|
||||
_otherRagdolls.push_back(doll);
|
||||
|
||||
// set the massScale of otherRagdolls artificially high
|
||||
doll->setMassScale(OTHER_RAGDOLL_MASS_SCALE);
|
||||
return true;
|
||||
}
|
||||
|
||||
|
@ -174,6 +179,7 @@ void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
|||
_otherRagdolls[i] = lastDoll;
|
||||
}
|
||||
doll->_ragdollSimulation = NULL;
|
||||
doll->setMassScale(1.0f);
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
@ -237,7 +243,7 @@ void PhysicsSimulation::computeCollisions() {
|
|||
|
||||
const QVector<Shape*> shapes = _entity->getShapes();
|
||||
int numShapes = shapes.size();
|
||||
// collide with self
|
||||
// collide main ragdoll with self
|
||||
for (int i = 0; i < numShapes; ++i) {
|
||||
const Shape* shape = shapes.at(i);
|
||||
if (!shape) {
|
||||
|
@ -251,7 +257,7 @@ void PhysicsSimulation::computeCollisions() {
|
|||
}
|
||||
}
|
||||
|
||||
// collide with others
|
||||
// collide main ragdoll with others
|
||||
int numEntities = _otherEntities.size();
|
||||
for (int i = 0; i < numEntities; ++i) {
|
||||
const QVector<Shape*> otherShapes = _otherEntities.at(i)->getShapes();
|
||||
|
|
|
@ -19,7 +19,7 @@
|
|||
#include "PhysicsSimulation.h"
|
||||
#include "SharedUtil.h" // for EPSILON
|
||||
|
||||
Ragdoll::Ragdoll() : _ragdollTranslation(0.0f), _translationInSimulationFrame(0.0f), _ragdollSimulation(NULL) {
|
||||
Ragdoll::Ragdoll() : _massScale(1.0f), _ragdollTranslation(0.0f), _translationInSimulationFrame(0.0f), _ragdollSimulation(NULL) {
|
||||
}
|
||||
|
||||
Ragdoll::~Ragdoll() {
|
||||
|
@ -99,3 +99,17 @@ void Ragdoll::updateSimulationTransforms(const glm::vec3& translation, const glm
|
|||
_translationInSimulationFrame = translation;
|
||||
_rotationInSimulationFrame = rotation;
|
||||
}
|
||||
|
||||
void Ragdoll::setMassScale(float scale) {
|
||||
const float MIN_SCALE = 1.0e-2f;
|
||||
const float MAX_SCALE = 1.0e6f;
|
||||
scale = glm::clamp(glm::abs(scale), MIN_SCALE, MAX_SCALE);
|
||||
if (scale != _massScale) {
|
||||
float rescale = scale / _massScale;
|
||||
int numPoints = _ragdollPoints.size();
|
||||
for (int i = 0; i < numPoints; ++i) {
|
||||
_ragdollPoints[i].setMass(rescale * _ragdollPoints[i].getMass());
|
||||
}
|
||||
_massScale = scale;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -49,11 +49,15 @@ public:
|
|||
|
||||
const glm::vec3& getTranslationInSimulationFrame() const { return _translationInSimulationFrame; }
|
||||
|
||||
void setMassScale(float scale);
|
||||
float getMassScale() const { return _massScale; }
|
||||
|
||||
protected:
|
||||
void clearRagdollConstraintsAndPoints();
|
||||
virtual void initRagdollPoints() = 0;
|
||||
virtual void buildRagdollConstraints() = 0;
|
||||
|
||||
float _massScale;
|
||||
glm::vec3 _ragdollTranslation; // world-frame
|
||||
glm::quat _ragdollRotation; // world-frame
|
||||
glm::vec3 _translationInSimulationFrame;
|
||||
|
|
|
@ -97,7 +97,7 @@ float VerletCapsuleShape::computeEffectiveMass(const glm::vec3& penetration, con
|
|||
_endLagrangeCoef = 1.0f;
|
||||
}
|
||||
// the effective mass is the weighted sum of the two endpoints
|
||||
return _startLagrangeCoef * _startPoint->_mass + _endLagrangeCoef * _endPoint->_mass;
|
||||
return _startLagrangeCoef * _startPoint->getMass() + _endLagrangeCoef * _endPoint->getMass();
|
||||
}
|
||||
|
||||
void VerletCapsuleShape::accumulateDelta(float relativeMassFactor, const glm::vec3& penetration) {
|
||||
|
|
|
@ -38,3 +38,12 @@ void VerletPoint::move(const glm::vec3& deltaPosition, const glm::quat& deltaRot
|
|||
arm = _lastPosition - oldPivot;
|
||||
_lastPosition += deltaPosition + (deltaRotation * arm - arm);
|
||||
}
|
||||
|
||||
void VerletPoint::setMass(float mass) {
|
||||
const float MIN_MASS = 1.0e-6f;
|
||||
const float MAX_MASS = 1.0e18f;
|
||||
if (glm::isnan(mass)) {
|
||||
mass = MIN_MASS;
|
||||
}
|
||||
_mass = glm::clamp(glm::abs(mass), MIN_MASS, MAX_MASS);
|
||||
}
|
||||
|
|
|
@ -26,11 +26,14 @@ public:
|
|||
void applyAccumulatedDelta();
|
||||
void move(const glm::vec3& deltaPosition, const glm::quat& deltaRotation, const glm::vec3& oldPivot);
|
||||
|
||||
void setMass(float mass);
|
||||
float getMass() const { return _mass; }
|
||||
|
||||
glm::vec3 _position;
|
||||
glm::vec3 _lastPosition;
|
||||
float _mass;
|
||||
|
||||
private:
|
||||
float _mass;
|
||||
glm::vec3 _accumulatedDelta;
|
||||
int _numDeltas;
|
||||
};
|
||||
|
|
|
@ -36,7 +36,7 @@ const glm::vec3& VerletSphereShape::getTranslation() const {
|
|||
|
||||
// virtual
|
||||
float VerletSphereShape::computeEffectiveMass(const glm::vec3& penetration, const glm::vec3& contactPoint) {
|
||||
return _point->_mass;
|
||||
return _point->getMass();
|
||||
}
|
||||
|
||||
// virtual
|
||||
|
|
Loading…
Reference in a new issue