mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 02:36:54 +02:00
Merge branch 'master' of https://github.com/highfidelity/hifi into record_feature
This commit is contained in:
commit
1d30b52ec2
18 changed files with 489 additions and 275 deletions
|
@ -242,6 +242,8 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
|
||||||
|
|
||||||
connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
|
connect(&domainHandler, SIGNAL(hostnameChanged(const QString&)), SLOT(domainChanged(const QString&)));
|
||||||
connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&)));
|
connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(connectedToDomain(const QString&)));
|
||||||
|
connect(&domainHandler, SIGNAL(connectedToDomain(const QString&)), SLOT(updateWindowTitle()));
|
||||||
|
connect(&domainHandler, SIGNAL(disconnectedFromDomain()), SLOT(updateWindowTitle()));
|
||||||
connect(&domainHandler, &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived);
|
connect(&domainHandler, &DomainHandler::settingsReceived, this, &Application::domainSettingsReceived);
|
||||||
|
|
||||||
// hookup VoxelEditSender to PaymentManager so we can pay for octree edits
|
// hookup VoxelEditSender to PaymentManager so we can pay for octree edits
|
||||||
|
@ -3341,9 +3343,10 @@ void Application::updateWindowTitle(){
|
||||||
QString buildVersion = " (build " + applicationVersion() + ")";
|
QString buildVersion = " (build " + applicationVersion() + ")";
|
||||||
NodeList* nodeList = NodeList::getInstance();
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
|
|
||||||
|
QString connectionStatus = nodeList->getDomainHandler().isConnected() ? "" : " (NOT CONNECTED) ";
|
||||||
QString username = AccountManager::getInstance().getAccountInfo().getUsername();
|
QString username = AccountManager::getInstance().getAccountInfo().getUsername();
|
||||||
QString title = QString() + (!username.isEmpty() ? username + " @ " : QString())
|
QString title = QString() + (!username.isEmpty() ? username + " @ " : QString())
|
||||||
+ nodeList->getDomainHandler().getHostname() + buildVersion;
|
+ nodeList->getDomainHandler().getHostname() + connectionStatus + buildVersion;
|
||||||
|
|
||||||
AccountManager& accountManager = AccountManager::getInstance();
|
AccountManager& accountManager = AccountManager::getInstance();
|
||||||
if (accountManager.getAccountInfo().hasBalance()) {
|
if (accountManager.getAccountInfo().hasBalance()) {
|
||||||
|
|
|
@ -84,10 +84,11 @@ MyAvatar::MyAvatar() :
|
||||||
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
|
||||||
_driveKeys[i] = 0.0f;
|
_driveKeys[i] = 0.0f;
|
||||||
}
|
}
|
||||||
_skeletonModel.setEnableShapes(true);
|
|
||||||
// The skeleton is both a PhysicsEntity and Ragdoll, so we add it to the simulation once for each type.
|
|
||||||
_physicsSimulation.setEntity(&_skeletonModel);
|
_physicsSimulation.setEntity(&_skeletonModel);
|
||||||
_physicsSimulation.setRagdoll(&_skeletonModel);
|
|
||||||
|
_skeletonModel.setEnableShapes(true);
|
||||||
|
Ragdoll* ragdoll = _skeletonModel.buildRagdoll();
|
||||||
|
_physicsSimulation.setRagdoll(ragdoll);
|
||||||
}
|
}
|
||||||
|
|
||||||
MyAvatar::~MyAvatar() {
|
MyAvatar::~MyAvatar() {
|
||||||
|
@ -1678,10 +1679,10 @@ void MyAvatar::updateCollisionWithAvatars(float deltaTime) {
|
||||||
if (simulation != &(_physicsSimulation)) {
|
if (simulation != &(_physicsSimulation)) {
|
||||||
skeleton->setEnableShapes(true);
|
skeleton->setEnableShapes(true);
|
||||||
_physicsSimulation.addEntity(skeleton);
|
_physicsSimulation.addEntity(skeleton);
|
||||||
_physicsSimulation.addRagdoll(skeleton);
|
_physicsSimulation.addRagdoll(skeleton->getRagdoll());
|
||||||
}
|
}
|
||||||
} else if (simulation == &(_physicsSimulation)) {
|
} else if (simulation == &(_physicsSimulation)) {
|
||||||
_physicsSimulation.removeRagdoll(skeleton);
|
_physicsSimulation.removeRagdoll(skeleton->getRagdoll());
|
||||||
_physicsSimulation.removeEntity(skeleton);
|
_physicsSimulation.removeEntity(skeleton);
|
||||||
skeleton->setEnableShapes(false);
|
skeleton->setEnableShapes(false);
|
||||||
}
|
}
|
||||||
|
|
|
@ -23,13 +23,19 @@
|
||||||
#include "Menu.h"
|
#include "Menu.h"
|
||||||
#include "MuscleConstraint.h"
|
#include "MuscleConstraint.h"
|
||||||
#include "SkeletonModel.h"
|
#include "SkeletonModel.h"
|
||||||
|
#include "SkeletonRagdoll.h"
|
||||||
|
|
||||||
SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) :
|
SkeletonModel::SkeletonModel(Avatar* owningAvatar, QObject* parent) :
|
||||||
Model(parent),
|
Model(parent),
|
||||||
Ragdoll(),
|
|
||||||
_owningAvatar(owningAvatar),
|
_owningAvatar(owningAvatar),
|
||||||
_boundingShape(),
|
_boundingShape(),
|
||||||
_boundingShapeLocalOffset(0.0f) {
|
_boundingShapeLocalOffset(0.0f),
|
||||||
|
_ragdoll(NULL) {
|
||||||
|
}
|
||||||
|
|
||||||
|
SkeletonModel::~SkeletonModel() {
|
||||||
|
delete _ragdoll;
|
||||||
|
_ragdoll = NULL;
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonModel::setJointStates(QVector<JointState> states) {
|
void SkeletonModel::setJointStates(QVector<JointState> states) {
|
||||||
|
@ -161,9 +167,6 @@ void SkeletonModel::getBodyShapes(QVector<const Shape*>& shapes) const {
|
||||||
void SkeletonModel::renderIKConstraints() {
|
void SkeletonModel::renderIKConstraints() {
|
||||||
renderJointConstraints(getRightHandJointIndex());
|
renderJointConstraints(getRightHandJointIndex());
|
||||||
renderJointConstraints(getLeftHandJointIndex());
|
renderJointConstraints(getLeftHandJointIndex());
|
||||||
//if (isActive() && _owningAvatar->isMyAvatar()) {
|
|
||||||
// renderRagdoll();
|
|
||||||
//}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
class IndexValue {
|
class IndexValue {
|
||||||
|
@ -495,21 +498,25 @@ bool SkeletonModel::getEyePositions(glm::vec3& firstEyePosition, glm::vec3& seco
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonModel::renderRagdoll() {
|
void SkeletonModel::renderRagdoll() {
|
||||||
|
if (!_ragdoll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
const QVector<VerletPoint>& points = _ragdoll->getPoints();
|
||||||
const int BALL_SUBDIVISIONS = 6;
|
const int BALL_SUBDIVISIONS = 6;
|
||||||
glDisable(GL_DEPTH_TEST);
|
glDisable(GL_DEPTH_TEST);
|
||||||
glDisable(GL_LIGHTING);
|
glDisable(GL_LIGHTING);
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
|
|
||||||
Application::getInstance()->loadTranslatedViewMatrix(_translation);
|
Application::getInstance()->loadTranslatedViewMatrix(_translation);
|
||||||
int numPoints = _ragdollPoints.size();
|
int numPoints = points.size();
|
||||||
float alpha = 0.3f;
|
float alpha = 0.3f;
|
||||||
float radius1 = 0.008f;
|
float radius1 = 0.008f;
|
||||||
float radius2 = 0.01f;
|
float radius2 = 0.01f;
|
||||||
glm::vec3 simulationTranslation = getTranslationInSimulationFrame();
|
glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame();
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
// NOTE: ragdollPoints are in simulation-frame but we want them to be model-relative
|
// NOTE: ragdollPoints are in simulation-frame but we want them to be model-relative
|
||||||
glm::vec3 position = _ragdollPoints[i]._position - simulationTranslation;
|
glm::vec3 position = points[i]._position - simulationTranslation;
|
||||||
glTranslatef(position.x, position.y, position.z);
|
glTranslatef(position.x, position.y, position.z);
|
||||||
// draw each point as a yellow hexagon with black border
|
// draw each point as a yellow hexagon with black border
|
||||||
glColor4f(0.0f, 0.0f, 0.0f, alpha);
|
glColor4f(0.0f, 0.0f, 0.0f, alpha);
|
||||||
|
@ -523,109 +530,18 @@ void SkeletonModel::renderRagdoll() {
|
||||||
glEnable(GL_LIGHTING);
|
glEnable(GL_LIGHTING);
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
|
||||||
void SkeletonModel::initRagdollPoints() {
|
|
||||||
clearRagdollConstraintsAndPoints();
|
|
||||||
_muscleConstraints.clear();
|
|
||||||
|
|
||||||
initRagdollTransform();
|
|
||||||
// one point for each joint
|
|
||||||
int numStates = _jointStates.size();
|
|
||||||
_ragdollPoints.fill(VerletPoint(), numStates);
|
|
||||||
for (int i = 0; i < numStates; ++i) {
|
|
||||||
const JointState& state = _jointStates.at(i);
|
|
||||||
// _ragdollPoints start in model-frame
|
|
||||||
_ragdollPoints[i].initPosition(state.getPosition());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkeletonModel::buildRagdollConstraints() {
|
|
||||||
// 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();
|
|
||||||
assert(numPoints == _jointStates.size());
|
|
||||||
|
|
||||||
float minBone = FLT_MAX;
|
|
||||||
float maxBone = -FLT_MAX;
|
|
||||||
QMultiMap<int, int> families;
|
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
|
||||||
const JointState& state = _jointStates.at(i);
|
|
||||||
int parentIndex = state.getParentIndex();
|
|
||||||
if (parentIndex == -1) {
|
|
||||||
FixedConstraint* anchor = new FixedConstraint(&_translationInSimulationFrame, &(_ragdollPoints[i]));
|
|
||||||
_fixedConstraints.push_back(anchor);
|
|
||||||
} else {
|
|
||||||
DistanceConstraint* bone = new DistanceConstraint(&(_ragdollPoints[i]), &(_ragdollPoints[parentIndex]));
|
|
||||||
bone->setDistance(state.getDistanceToParent());
|
|
||||||
_boneConstraints.push_back(bone);
|
|
||||||
families.insert(parentIndex, i);
|
|
||||||
}
|
|
||||||
float boneLength = glm::length(state.getPositionInParentFrame());
|
|
||||||
if (boneLength > maxBone) {
|
|
||||||
maxBone = boneLength;
|
|
||||||
} else if (boneLength < minBone) {
|
|
||||||
minBone = boneLength;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
// Joints that have multiple children effectively have rigid constraints between the children
|
|
||||||
// in the parent frame, so we add DistanceConstraints between children in the same family.
|
|
||||||
QMultiMap<int, int>::iterator itr = families.begin();
|
|
||||||
while (itr != families.end()) {
|
|
||||||
QList<int> children = families.values(itr.key());
|
|
||||||
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]]));
|
|
||||||
_boneConstraints.push_back(bone);
|
|
||||||
}
|
|
||||||
if (numChildren > 2) {
|
|
||||||
DistanceConstraint* bone = new DistanceConstraint(&(_ragdollPoints[children[numChildren-1]]), &(_ragdollPoints[children[0]]));
|
|
||||||
_boneConstraints.push_back(bone);
|
|
||||||
}
|
|
||||||
}
|
|
||||||
++itr;
|
|
||||||
}
|
|
||||||
|
|
||||||
float MAX_STRENGTH = 0.6f;
|
|
||||||
float MIN_STRENGTH = 0.05f;
|
|
||||||
// each joint gets a MuscleConstraint to its parent
|
|
||||||
for (int i = 1; i < numPoints; ++i) {
|
|
||||||
const JointState& state = _jointStates.at(i);
|
|
||||||
int p = state.getParentIndex();
|
|
||||||
if (p == -1) {
|
|
||||||
continue;
|
|
||||||
}
|
|
||||||
MuscleConstraint* constraint = new MuscleConstraint(&(_ragdollPoints[p]), &(_ragdollPoints[i]));
|
|
||||||
_muscleConstraints.push_back(constraint);
|
|
||||||
|
|
||||||
// Short joints are more susceptible to wiggle so we modulate the strength based on the joint's length:
|
|
||||||
// long = weak and short = strong.
|
|
||||||
constraint->setIndices(p, i);
|
|
||||||
float boneLength = glm::length(state.getPositionInParentFrame());
|
|
||||||
|
|
||||||
float strength = MIN_STRENGTH + (MAX_STRENGTH - MIN_STRENGTH) * (maxBone - boneLength) / (maxBone - minBone);
|
|
||||||
if (!families.contains(i)) {
|
|
||||||
// Although muscles only pull on the children not parents, nevertheless those joints that have
|
|
||||||
// parents AND children are more stable than joints at the end such as fingers. For such joints we
|
|
||||||
// bestow maximum strength which helps reduce wiggle.
|
|
||||||
strength = MAX_MUSCLE_STRENGTH;
|
|
||||||
}
|
|
||||||
constraint->setStrength(strength);
|
|
||||||
}
|
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkeletonModel::updateVisibleJointStates() {
|
void SkeletonModel::updateVisibleJointStates() {
|
||||||
if (_showTrueJointTransforms) {
|
if (_showTrueJointTransforms || !_ragdoll) {
|
||||||
// no need to update visible transforms
|
// no need to update visible transforms
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
const QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
|
||||||
QVector<glm::vec3> points;
|
QVector<glm::vec3> points;
|
||||||
points.reserve(_jointStates.size());
|
points.reserve(_jointStates.size());
|
||||||
glm::quat invRotation = glm::inverse(_rotation);
|
glm::quat invRotation = glm::inverse(_rotation);
|
||||||
for (int i = 0; i < _jointStates.size(); i++) {
|
for (int i = 0; i < _jointStates.size(); i++) {
|
||||||
JointState& state = _jointStates[i];
|
JointState& state = _jointStates[i];
|
||||||
points.push_back(_ragdollPoints[i]._position);
|
points.push_back(ragdollPoints[i]._position);
|
||||||
|
|
||||||
// get the parent state (this is the state that we want to rotate)
|
// get the parent state (this is the state that we want to rotate)
|
||||||
int parentIndex = state.getParentIndex();
|
int parentIndex = state.getParentIndex();
|
||||||
|
@ -659,15 +575,14 @@ void SkeletonModel::updateVisibleJointStates() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
SkeletonRagdoll* SkeletonModel::buildRagdoll() {
|
||||||
void SkeletonModel::stepRagdollForward(float deltaTime) {
|
if (!_ragdoll) {
|
||||||
setRagdollTransform(_translation, _rotation);
|
_ragdoll = new SkeletonRagdoll(this);
|
||||||
Ragdoll::stepRagdollForward(deltaTime);
|
if (_enableShapes) {
|
||||||
updateMuscles();
|
buildShapes();
|
||||||
int numConstraints = _muscleConstraints.size();
|
}
|
||||||
for (int i = 0; i < numConstraints; ++i) {
|
|
||||||
_muscleConstraints[i]->enforce();
|
|
||||||
}
|
}
|
||||||
|
return _ragdoll;
|
||||||
}
|
}
|
||||||
|
|
||||||
float DENSITY_OF_WATER = 1000.0f; // kg/m^3
|
float DENSITY_OF_WATER = 1000.0f; // kg/m^3
|
||||||
|
@ -685,8 +600,13 @@ void SkeletonModel::buildShapes() {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
initRagdollPoints();
|
if (!_ragdoll) {
|
||||||
float massScale = getMassScale();
|
_ragdoll = new SkeletonRagdoll(this);
|
||||||
|
}
|
||||||
|
_ragdoll->initPoints();
|
||||||
|
QVector<VerletPoint>& points = _ragdoll->getPoints();
|
||||||
|
|
||||||
|
float massScale = _ragdoll->getMassScale();
|
||||||
|
|
||||||
float uniformScale = extractUniformScale(_scale);
|
float uniformScale = extractUniformScale(_scale);
|
||||||
const int numStates = _jointStates.size();
|
const int numStates = _jointStates.size();
|
||||||
|
@ -706,14 +626,14 @@ void SkeletonModel::buildShapes() {
|
||||||
Shape* shape = NULL;
|
Shape* shape = NULL;
|
||||||
int parentIndex = joint.parentIndex;
|
int parentIndex = joint.parentIndex;
|
||||||
if (type == Shape::SPHERE_SHAPE) {
|
if (type == Shape::SPHERE_SHAPE) {
|
||||||
shape = new VerletSphereShape(radius, &(_ragdollPoints[i]));
|
shape = new VerletSphereShape(radius, &(points[i]));
|
||||||
shape->setEntity(this);
|
shape->setEntity(this);
|
||||||
_ragdollPoints[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
points[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
||||||
} else if (type == Shape::CAPSULE_SHAPE) {
|
} else if (type == Shape::CAPSULE_SHAPE) {
|
||||||
assert(parentIndex != -1);
|
assert(parentIndex != -1);
|
||||||
shape = new VerletCapsuleShape(radius, &(_ragdollPoints[parentIndex]), &(_ragdollPoints[i]));
|
shape = new VerletCapsuleShape(radius, &(points[parentIndex]), &(points[i]));
|
||||||
shape->setEntity(this);
|
shape->setEntity(this);
|
||||||
_ragdollPoints[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
points[i].setMass(massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()));
|
||||||
}
|
}
|
||||||
if (parentIndex != -1) {
|
if (parentIndex != -1) {
|
||||||
// always disable collisions between joint and its parent
|
// always disable collisions between joint and its parent
|
||||||
|
@ -723,7 +643,7 @@ void SkeletonModel::buildShapes() {
|
||||||
} else {
|
} else {
|
||||||
// give the base joint a very large mass since it doesn't actually move
|
// give the base joint a very large mass since it doesn't actually move
|
||||||
// in the local-frame simulation (it defines the origin)
|
// in the local-frame simulation (it defines the origin)
|
||||||
_ragdollPoints[i].setMass(VERY_BIG_MASS);
|
points[i].setMass(VERY_BIG_MASS);
|
||||||
}
|
}
|
||||||
_shapes.push_back(shape);
|
_shapes.push_back(shape);
|
||||||
}
|
}
|
||||||
|
@ -735,17 +655,11 @@ void SkeletonModel::buildShapes() {
|
||||||
// joints that are currently colliding.
|
// joints that are currently colliding.
|
||||||
disableCurrentSelfCollisions();
|
disableCurrentSelfCollisions();
|
||||||
|
|
||||||
buildRagdollConstraints();
|
_ragdoll->buildConstraints();
|
||||||
|
|
||||||
// ... then move shapes back to current joint positions
|
// ... then move shapes back to current joint positions
|
||||||
if (_ragdollPoints.size() == numStates) {
|
_ragdoll->slamPointPositions();
|
||||||
int numStates = _jointStates.size();
|
_ragdoll->enforceConstraints();
|
||||||
for (int i = 0; i < numStates; ++i) {
|
|
||||||
// ragdollPoints start in model-frame
|
|
||||||
_ragdollPoints[i].initPosition(_jointStates.at(i).getPosition());
|
|
||||||
}
|
|
||||||
}
|
|
||||||
enforceRagdollConstraints();
|
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
|
void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
|
||||||
|
@ -753,8 +667,9 @@ void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
|
||||||
// unravel a skelton that has become tangled in its constraints. So let's keep this
|
// unravel a skelton that has become tangled in its constraints. So let's keep this
|
||||||
// around for a while just in case.
|
// around for a while just in case.
|
||||||
const int numStates = _jointStates.size();
|
const int numStates = _jointStates.size();
|
||||||
assert(_jointStates.size() == _ragdollPoints.size());
|
QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
|
||||||
if (_ragdollPoints.size() != numStates) {
|
assert(_jointStates.size() == ragdollPoints.size());
|
||||||
|
if (ragdollPoints.size() != numStates) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -763,32 +678,22 @@ void SkeletonModel::moveShapesTowardJoints(float deltaTime) {
|
||||||
float fraction = glm::clamp(deltaTime / RAGDOLL_FOLLOWS_JOINTS_TIMESCALE, 0.0f, 1.0f);
|
float fraction = glm::clamp(deltaTime / RAGDOLL_FOLLOWS_JOINTS_TIMESCALE, 0.0f, 1.0f);
|
||||||
|
|
||||||
float oneMinusFraction = 1.0f - fraction;
|
float oneMinusFraction = 1.0f - fraction;
|
||||||
glm::vec3 simulationTranslation = getTranslationInSimulationFrame();
|
glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame();
|
||||||
for (int i = 0; i < numStates; ++i) {
|
for (int i = 0; i < numStates; ++i) {
|
||||||
// ragdollPoints are in simulation-frame but jointStates are in model-frame
|
// ragdollPoints are in simulation-frame but jointStates are in model-frame
|
||||||
_ragdollPoints[i].initPosition(oneMinusFraction * _ragdollPoints[i]._position +
|
ragdollPoints[i].initPosition(oneMinusFraction * ragdollPoints[i]._position +
|
||||||
fraction * (simulationTranslation + _rotation * (_jointStates.at(i).getPosition())));
|
fraction * (simulationTranslation + _rotation * (_jointStates.at(i).getPosition())));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void SkeletonModel::updateMuscles() {
|
|
||||||
int numConstraints = _muscleConstraints.size();
|
|
||||||
for (int i = 0; i < numConstraints; ++i) {
|
|
||||||
MuscleConstraint* constraint = _muscleConstraints[i];
|
|
||||||
int j = constraint->getParentIndex();
|
|
||||||
int k = constraint->getChildIndex();
|
|
||||||
assert(j != -1 && k != -1);
|
|
||||||
// ragdollPoints are in simulation-frame but jointStates are in model-frame
|
|
||||||
constraint->setChildOffset(_rotation * (_jointStates.at(k).getPosition() - _jointStates.at(j).getPosition()));
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
|
void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
|
||||||
// compute default joint transforms
|
// compute default joint transforms
|
||||||
int numStates = _jointStates.size();
|
int numStates = _jointStates.size();
|
||||||
QVector<glm::mat4> transforms;
|
QVector<glm::mat4> transforms;
|
||||||
transforms.fill(glm::mat4(), numStates);
|
transforms.fill(glm::mat4(), numStates);
|
||||||
|
|
||||||
|
QVector<VerletPoint>& ragdollPoints = _ragdoll->getPoints();
|
||||||
|
|
||||||
// compute the default transforms and slam the ragdoll positions accordingly
|
// compute the default transforms and slam the ragdoll positions accordingly
|
||||||
// (which puts the shapes where we want them)
|
// (which puts the shapes where we want them)
|
||||||
for (int i = 0; i < numStates; i++) {
|
for (int i = 0; i < numStates; i++) {
|
||||||
|
@ -797,7 +702,7 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
|
||||||
int parentIndex = joint.parentIndex;
|
int parentIndex = joint.parentIndex;
|
||||||
if (parentIndex == -1) {
|
if (parentIndex == -1) {
|
||||||
transforms[i] = _jointStates[i].getTransform();
|
transforms[i] = _jointStates[i].getTransform();
|
||||||
_ragdollPoints[i].initPosition(extractTranslation(transforms[i]));
|
ragdollPoints[i].initPosition(extractTranslation(transforms[i]));
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -805,7 +710,7 @@ void SkeletonModel::computeBoundingShape(const FBXGeometry& geometry) {
|
||||||
transforms[i] = transforms[parentIndex] * glm::translate(joint.translation)
|
transforms[i] = transforms[parentIndex] * glm::translate(joint.translation)
|
||||||
* joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform;
|
* joint.preTransform * glm::mat4_cast(modifiedRotation) * joint.postTransform;
|
||||||
// setting the ragdollPoints here slams the VerletShapes into their default positions
|
// setting the ragdollPoints here slams the VerletShapes into their default positions
|
||||||
_ragdollPoints[i].initPosition(extractTranslation(transforms[i]));
|
ragdollPoints[i].initPosition(extractTranslation(transforms[i]));
|
||||||
}
|
}
|
||||||
|
|
||||||
// compute bounding box that encloses all shapes
|
// compute bounding box that encloses all shapes
|
||||||
|
@ -924,9 +829,12 @@ const int BALL_SUBDIVISIONS = 10;
|
||||||
|
|
||||||
// virtual
|
// virtual
|
||||||
void SkeletonModel::renderJointCollisionShapes(float alpha) {
|
void SkeletonModel::renderJointCollisionShapes(float alpha) {
|
||||||
|
if (!_ragdoll) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
glPushMatrix();
|
glPushMatrix();
|
||||||
Application::getInstance()->loadTranslatedViewMatrix(_translation);
|
Application::getInstance()->loadTranslatedViewMatrix(_translation);
|
||||||
glm::vec3 simulationTranslation = getTranslationInSimulationFrame();
|
glm::vec3 simulationTranslation = _ragdoll->getTranslationInSimulationFrame();
|
||||||
for (int i = 0; i < _shapes.size(); i++) {
|
for (int i = 0; i < _shapes.size(); i++) {
|
||||||
Shape* shape = _shapes[i];
|
Shape* shape = _shapes[i];
|
||||||
if (!shape) {
|
if (!shape) {
|
||||||
|
|
|
@ -15,18 +15,20 @@
|
||||||
#include "renderer/Model.h"
|
#include "renderer/Model.h"
|
||||||
|
|
||||||
#include <CapsuleShape.h>
|
#include <CapsuleShape.h>
|
||||||
#include <Ragdoll.h>
|
#include "SkeletonRagdoll.h"
|
||||||
|
|
||||||
class Avatar;
|
class Avatar;
|
||||||
class MuscleConstraint;
|
class MuscleConstraint;
|
||||||
|
class SkeletonRagdoll;
|
||||||
|
|
||||||
/// A skeleton loaded from a model.
|
/// A skeleton loaded from a model.
|
||||||
class SkeletonModel : public Model, public Ragdoll {
|
class SkeletonModel : public Model {
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
|
|
||||||
SkeletonModel(Avatar* owningAvatar, QObject* parent = NULL);
|
SkeletonModel(Avatar* owningAvatar, QObject* parent = NULL);
|
||||||
|
~SkeletonModel();
|
||||||
|
|
||||||
void setJointStates(QVector<JointState> states);
|
void setJointStates(QVector<JointState> states);
|
||||||
|
|
||||||
|
@ -96,12 +98,11 @@ public:
|
||||||
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
bool getEyePositions(glm::vec3& firstEyePosition, glm::vec3& secondEyePosition) const;
|
||||||
|
|
||||||
virtual void updateVisibleJointStates();
|
virtual void updateVisibleJointStates();
|
||||||
|
|
||||||
// virtual overrride from Ragdoll
|
|
||||||
virtual void stepRagdollForward(float deltaTime);
|
|
||||||
|
|
||||||
|
SkeletonRagdoll* buildRagdoll();
|
||||||
|
SkeletonRagdoll* getRagdoll() { return _ragdoll; }
|
||||||
|
|
||||||
void moveShapesTowardJoints(float fraction);
|
void moveShapesTowardJoints(float fraction);
|
||||||
void updateMuscles();
|
|
||||||
|
|
||||||
void computeBoundingShape(const FBXGeometry& geometry);
|
void computeBoundingShape(const FBXGeometry& geometry);
|
||||||
void renderBoundingCollisionShapes(float alpha);
|
void renderBoundingCollisionShapes(float alpha);
|
||||||
|
@ -115,10 +116,6 @@ public:
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
|
|
||||||
// virtual overrrides from Ragdoll
|
|
||||||
void initRagdollPoints();
|
|
||||||
void buildRagdollConstraints();
|
|
||||||
|
|
||||||
void buildShapes();
|
void buildShapes();
|
||||||
|
|
||||||
/// \param jointIndex index of joint in model
|
/// \param jointIndex index of joint in model
|
||||||
|
@ -147,7 +144,7 @@ private:
|
||||||
|
|
||||||
CapsuleShape _boundingShape;
|
CapsuleShape _boundingShape;
|
||||||
glm::vec3 _boundingShapeLocalOffset;
|
glm::vec3 _boundingShapeLocalOffset;
|
||||||
QVector<MuscleConstraint*> _muscleConstraints;
|
SkeletonRagdoll* _ragdoll;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_SkeletonModel_h
|
#endif // hifi_SkeletonModel_h
|
||||||
|
|
148
interface/src/avatar/SkeletonRagdoll.cpp
Normal file
148
interface/src/avatar/SkeletonRagdoll.cpp
Normal file
|
@ -0,0 +1,148 @@
|
||||||
|
//
|
||||||
|
// SkeletonRagdoll.cpp
|
||||||
|
// interface/src/avatar
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows 2014.08.14
|
||||||
|
// 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 <DistanceConstraint.h>
|
||||||
|
#include <FixedConstraint.h>
|
||||||
|
|
||||||
|
#include "SkeletonRagdoll.h"
|
||||||
|
#include "MuscleConstraint.h"
|
||||||
|
#include "../renderer/Model.h"
|
||||||
|
|
||||||
|
SkeletonRagdoll::SkeletonRagdoll(Model* model) : Ragdoll(), _model(model) {
|
||||||
|
assert(_model);
|
||||||
|
}
|
||||||
|
|
||||||
|
SkeletonRagdoll::~SkeletonRagdoll() {
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtual
|
||||||
|
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) {
|
||||||
|
_muscleConstraints[i]->enforce();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkeletonRagdoll::slamPointPositions() {
|
||||||
|
QVector<JointState>& jointStates = _model->getJointStates();
|
||||||
|
int numStates = jointStates.size();
|
||||||
|
for (int i = 0; i < numStates; ++i) {
|
||||||
|
_points[i].initPosition(jointStates.at(i).getPosition());
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtual
|
||||||
|
void SkeletonRagdoll::initPoints() {
|
||||||
|
clearConstraintsAndPoints();
|
||||||
|
_muscleConstraints.clear();
|
||||||
|
|
||||||
|
initTransform();
|
||||||
|
// one point for each joint
|
||||||
|
QVector<JointState>& jointStates = _model->getJointStates();
|
||||||
|
int numStates = jointStates.size();
|
||||||
|
_points.fill(VerletPoint(), numStates);
|
||||||
|
slamPointPositions();
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtual
|
||||||
|
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 = _points.size();
|
||||||
|
assert(numPoints == jointStates.size());
|
||||||
|
|
||||||
|
float minBone = FLT_MAX;
|
||||||
|
float maxBone = -FLT_MAX;
|
||||||
|
QMultiMap<int, int> families;
|
||||||
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
|
const JointState& state = jointStates.at(i);
|
||||||
|
int parentIndex = state.getParentIndex();
|
||||||
|
if (parentIndex == -1) {
|
||||||
|
FixedConstraint* anchor = new FixedConstraint(&_translationInSimulationFrame, &(_points[i]));
|
||||||
|
_fixedConstraints.push_back(anchor);
|
||||||
|
} else {
|
||||||
|
DistanceConstraint* bone = new DistanceConstraint(&(_points[i]), &(_points[parentIndex]));
|
||||||
|
bone->setDistance(state.getDistanceToParent());
|
||||||
|
_boneConstraints.push_back(bone);
|
||||||
|
families.insert(parentIndex, i);
|
||||||
|
}
|
||||||
|
float boneLength = glm::length(state.getPositionInParentFrame());
|
||||||
|
if (boneLength > maxBone) {
|
||||||
|
maxBone = boneLength;
|
||||||
|
} else if (boneLength < minBone) {
|
||||||
|
minBone = boneLength;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
// Joints that have multiple children effectively have rigid constraints between the children
|
||||||
|
// in the parent frame, so we add DistanceConstraints between children in the same family.
|
||||||
|
QMultiMap<int, int>::iterator itr = families.begin();
|
||||||
|
while (itr != families.end()) {
|
||||||
|
QList<int> children = families.values(itr.key());
|
||||||
|
int numChildren = children.size();
|
||||||
|
if (numChildren > 1) {
|
||||||
|
for (int i = 1; i < numChildren; ++i) {
|
||||||
|
DistanceConstraint* bone = new DistanceConstraint(&(_points[children[i-1]]), &(_points[children[i]]));
|
||||||
|
_boneConstraints.push_back(bone);
|
||||||
|
}
|
||||||
|
if (numChildren > 2) {
|
||||||
|
DistanceConstraint* bone = new DistanceConstraint(&(_points[children[numChildren-1]]), &(_points[children[0]]));
|
||||||
|
_boneConstraints.push_back(bone);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
|
||||||
|
float MAX_STRENGTH = 0.6f;
|
||||||
|
float MIN_STRENGTH = 0.05f;
|
||||||
|
// each joint gets a MuscleConstraint to its parent
|
||||||
|
for (int i = 1; i < numPoints; ++i) {
|
||||||
|
const JointState& state = jointStates.at(i);
|
||||||
|
int p = state.getParentIndex();
|
||||||
|
if (p == -1) {
|
||||||
|
continue;
|
||||||
|
}
|
||||||
|
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:
|
||||||
|
// long = weak and short = strong.
|
||||||
|
constraint->setIndices(p, i);
|
||||||
|
float boneLength = glm::length(state.getPositionInParentFrame());
|
||||||
|
|
||||||
|
float strength = MIN_STRENGTH + (MAX_STRENGTH - MIN_STRENGTH) * (maxBone - boneLength) / (maxBone - minBone);
|
||||||
|
if (!families.contains(i)) {
|
||||||
|
// Although muscles only pull on the children not parents, nevertheless those joints that have
|
||||||
|
// parents AND children are more stable than joints at the end such as fingers. For such joints we
|
||||||
|
// bestow maximum strength which helps reduce wiggle.
|
||||||
|
strength = MAX_MUSCLE_STRENGTH;
|
||||||
|
}
|
||||||
|
constraint->setStrength(strength);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
void SkeletonRagdoll::updateMuscles() {
|
||||||
|
QVector<JointState>& jointStates = _model->getJointStates();
|
||||||
|
int numConstraints = _muscleConstraints.size();
|
||||||
|
glm::quat rotation = _model->getRotation();
|
||||||
|
for (int i = 0; i < numConstraints; ++i) {
|
||||||
|
MuscleConstraint* constraint = _muscleConstraints[i];
|
||||||
|
int j = constraint->getParentIndex();
|
||||||
|
int k = constraint->getChildIndex();
|
||||||
|
assert(j != -1 && k != -1);
|
||||||
|
// ragdollPoints are in simulation-frame but jointStates are in model-frame
|
||||||
|
constraint->setChildOffset(rotation * (jointStates.at(k).getPosition() - jointStates.at(j).getPosition()));
|
||||||
|
}
|
||||||
|
}
|
42
interface/src/avatar/SkeletonRagdoll.h
Normal file
42
interface/src/avatar/SkeletonRagdoll.h
Normal file
|
@ -0,0 +1,42 @@
|
||||||
|
//
|
||||||
|
// SkeletonkRagdoll.h
|
||||||
|
// interface/src/avatar
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows 2014.08.14
|
||||||
|
// 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_SkeletonRagdoll_h
|
||||||
|
#define hifi_SkeletonRagdoll_h
|
||||||
|
|
||||||
|
#include <QVector>
|
||||||
|
|
||||||
|
#include <Ragdoll.h>
|
||||||
|
|
||||||
|
#include "../renderer/JointState.h"
|
||||||
|
|
||||||
|
class MuscleConstraint;
|
||||||
|
class Model;
|
||||||
|
|
||||||
|
class SkeletonRagdoll : public Ragdoll {
|
||||||
|
public:
|
||||||
|
|
||||||
|
SkeletonRagdoll(Model* model);
|
||||||
|
virtual ~SkeletonRagdoll();
|
||||||
|
|
||||||
|
void slamPointPositions();
|
||||||
|
virtual void stepForward(float deltaTime);
|
||||||
|
|
||||||
|
virtual void initPoints();
|
||||||
|
virtual void buildConstraints();
|
||||||
|
|
||||||
|
void updateMuscles();
|
||||||
|
private:
|
||||||
|
Model* _model;
|
||||||
|
QVector<MuscleConstraint*> _muscleConstraints;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_SkeletonRagdoll_h
|
|
@ -167,6 +167,9 @@ public:
|
||||||
const QVector<LocalLight>& getLocalLights() const { return _localLights; }
|
const QVector<LocalLight>& getLocalLights() const { return _localLights; }
|
||||||
|
|
||||||
void setShowTrueJointTransforms(bool show) { _showTrueJointTransforms = show; }
|
void setShowTrueJointTransforms(bool show) { _showTrueJointTransforms = show; }
|
||||||
|
|
||||||
|
QVector<JointState>& getJointStates() { return _jointStates; }
|
||||||
|
const QVector<JointState>& getJointStates() const { return _jointStates; }
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
QSharedPointer<NetworkGeometry> _geometry;
|
QSharedPointer<NetworkGeometry> _geometry;
|
||||||
|
|
|
@ -57,6 +57,9 @@ ApplicationOverlay::~ApplicationOverlay() {
|
||||||
const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f };
|
const float WHITE_TEXT[] = { 0.93f, 0.93f, 0.93f };
|
||||||
const float RETICLE_COLOR[] = { 0.0f, 198.0f / 255.0f, 244.0f / 255.0f };
|
const float RETICLE_COLOR[] = { 0.0f, 198.0f / 255.0f, 244.0f / 255.0f };
|
||||||
|
|
||||||
|
const float CONNECTION_STATUS_BORDER_COLOR[] = { 1.0f, 0.0f, 0.0f };
|
||||||
|
const float CONNECTION_STATUS_BORDER_LINE_WIDTH = 4.0f;
|
||||||
|
|
||||||
// Renders the overlays either to a texture or to the screen
|
// Renders the overlays either to a texture or to the screen
|
||||||
void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
||||||
|
|
||||||
|
@ -115,6 +118,8 @@ void ApplicationOverlay::renderOverlay(bool renderToTexture) {
|
||||||
|
|
||||||
renderPointers();
|
renderPointers();
|
||||||
|
|
||||||
|
renderDomainConnectionStatusBorder();
|
||||||
|
|
||||||
glPopMatrix();
|
glPopMatrix();
|
||||||
|
|
||||||
|
|
||||||
|
@ -1234,6 +1239,30 @@ void ApplicationOverlay::renderTexturedHemisphere() {
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void ApplicationOverlay::renderDomainConnectionStatusBorder() {
|
||||||
|
NodeList* nodeList = NodeList::getInstance();
|
||||||
|
|
||||||
|
if (nodeList && !nodeList->getDomainHandler().isConnected()) {
|
||||||
|
QGLWidget* glWidget = Application::getInstance()->getGLWidget();
|
||||||
|
int right = glWidget->width();
|
||||||
|
int bottom = glWidget->height();
|
||||||
|
|
||||||
|
glColor3f(CONNECTION_STATUS_BORDER_COLOR[0],
|
||||||
|
CONNECTION_STATUS_BORDER_COLOR[1],
|
||||||
|
CONNECTION_STATUS_BORDER_COLOR[2]);
|
||||||
|
glLineWidth(CONNECTION_STATUS_BORDER_LINE_WIDTH);
|
||||||
|
|
||||||
|
glBegin(GL_LINE_LOOP);
|
||||||
|
|
||||||
|
glVertex2i(0, 0);
|
||||||
|
glVertex2i(0, bottom);
|
||||||
|
glVertex2i(right, bottom);
|
||||||
|
glVertex2i(right, 0);
|
||||||
|
|
||||||
|
glEnd();
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
QOpenGLFramebufferObject* ApplicationOverlay::getFramebufferObject() {
|
QOpenGLFramebufferObject* ApplicationOverlay::getFramebufferObject() {
|
||||||
QSize size = Application::getInstance()->getGLWidget()->size();
|
QSize size = Application::getInstance()->getGLWidget()->size();
|
||||||
if (!_framebufferObject || _framebufferObject->size() != size) {
|
if (!_framebufferObject || _framebufferObject->size() != size) {
|
||||||
|
|
|
@ -56,6 +56,7 @@ private:
|
||||||
void renderAudioMeter();
|
void renderAudioMeter();
|
||||||
void renderStatsAndLogs();
|
void renderStatsAndLogs();
|
||||||
void renderTexturedHemisphere();
|
void renderTexturedHemisphere();
|
||||||
|
void renderDomainConnectionStatusBorder();
|
||||||
|
|
||||||
QOpenGLFramebufferObject* _framebufferObject;
|
QOpenGLFramebufferObject* _framebufferObject;
|
||||||
float _trailingAudioLoudness;
|
float _trailingAudioLoudness;
|
||||||
|
@ -76,4 +77,4 @@ private:
|
||||||
GLuint _crosshairTexture;
|
GLuint _crosshairTexture;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_ApplicationOverlay_h
|
#endif // hifi_ApplicationOverlay_h
|
||||||
|
|
|
@ -36,6 +36,7 @@ DomainHandler::DomainHandler(QObject* parent) :
|
||||||
void DomainHandler::clearConnectionInfo() {
|
void DomainHandler::clearConnectionInfo() {
|
||||||
_uuid = QUuid();
|
_uuid = QUuid();
|
||||||
_isConnected = false;
|
_isConnected = false;
|
||||||
|
emit disconnectedFromDomain();
|
||||||
|
|
||||||
if (_handshakeTimer) {
|
if (_handshakeTimer) {
|
||||||
_handshakeTimer->stop();
|
_handshakeTimer->stop();
|
||||||
|
@ -129,6 +130,8 @@ void DomainHandler::setIsConnected(bool isConnected) {
|
||||||
|
|
||||||
// we've connected to new domain - time to ask it for global settings
|
// we've connected to new domain - time to ask it for global settings
|
||||||
requestDomainSettings();
|
requestDomainSettings();
|
||||||
|
} else {
|
||||||
|
emit disconnectedFromDomain();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -196,4 +199,4 @@ void DomainHandler::parseDTLSRequirementPacket(const QByteArray& dtlsRequirement
|
||||||
_sockAddr.setPort(dtlsPort);
|
_sockAddr.setPort(dtlsPort);
|
||||||
|
|
||||||
// initializeDTLSSession();
|
// initializeDTLSSession();
|
||||||
}
|
}
|
||||||
|
|
|
@ -70,6 +70,7 @@ private slots:
|
||||||
signals:
|
signals:
|
||||||
void hostnameChanged(const QString& hostname);
|
void hostnameChanged(const QString& hostname);
|
||||||
void connectedToDomain(const QString& hostname);
|
void connectedToDomain(const QString& hostname);
|
||||||
|
void disconnectedFromDomain();
|
||||||
|
|
||||||
void settingsReceived(const QJsonObject& domainSettingsObject);
|
void settingsReceived(const QJsonObject& domainSettingsObject);
|
||||||
void settingsReceiveFail();
|
void settingsReceiveFail();
|
||||||
|
|
|
@ -88,25 +88,7 @@ ContactPoint::ContactPoint(const CollisionInfo& collision, quint32 frame) :
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
// virtual
|
|
||||||
float ContactPoint::enforce() {
|
float ContactPoint::enforce() {
|
||||||
for (int i = 0; i < _numPoints; ++i) {
|
|
||||||
glm::vec3& position = _points[i]->_position;
|
|
||||||
// TODO: use a fast distance approximation
|
|
||||||
float newDistance = glm::distance(_contactPoint, position);
|
|
||||||
float constrainedDistance = _distances[i];
|
|
||||||
// NOTE: these "distance" constraints only push OUT, don't pull IN.
|
|
||||||
if (newDistance > EPSILON && newDistance < constrainedDistance) {
|
|
||||||
glm::vec3 direction = (_contactPoint - position) / newDistance;
|
|
||||||
glm::vec3 center = 0.5f * (_contactPoint + position);
|
|
||||||
_contactPoint = center + (0.5f * constrainedDistance) * direction;
|
|
||||||
position = center - (0.5f * constrainedDistance) * direction;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
return 0.0f;
|
|
||||||
}
|
|
||||||
|
|
||||||
void ContactPoint::buildConstraints() {
|
|
||||||
glm::vec3 pointA = _shapeA->getTranslation() + _offsetA;
|
glm::vec3 pointA = _shapeA->getTranslation() + _offsetA;
|
||||||
glm::vec3 pointB = _shapeB->getTranslation() + _offsetB;
|
glm::vec3 pointB = _shapeB->getTranslation() + _offsetB;
|
||||||
glm::vec3 penetration = pointA - pointB;
|
glm::vec3 penetration = pointA - pointB;
|
||||||
|
@ -116,14 +98,6 @@ void ContactPoint::buildConstraints() {
|
||||||
// the contact point will be the average of the two points on the shapes
|
// the contact point will be the average of the two points on the shapes
|
||||||
_contactPoint = 0.5f * (pointA + pointB);
|
_contactPoint = 0.5f * (pointA + pointB);
|
||||||
|
|
||||||
// TODO: Andrew to compute more correct lagrangian weights that provide a more realistic response.
|
|
||||||
//
|
|
||||||
// HACK: since the weights are naively equal for all points (which is what the above TODO is about) we
|
|
||||||
// don't want to use the full-strength delta because otherwise there can be annoying oscillations. We
|
|
||||||
// reduce this problem by in the short-term by attenuating the delta that is applied, the tradeoff is
|
|
||||||
// that this makes it easier for limbs to tunnel through during collisions.
|
|
||||||
const float HACK_STRENGTH = 0.5f;
|
|
||||||
|
|
||||||
if (constraintViolation) {
|
if (constraintViolation) {
|
||||||
for (int i = 0; i < _numPoints; ++i) {
|
for (int i = 0; i < _numPoints; ++i) {
|
||||||
VerletPoint* point = _points[i];
|
VerletPoint* point = _points[i];
|
||||||
|
@ -146,13 +120,34 @@ void ContactPoint::buildConstraints() {
|
||||||
|
|
||||||
glm::vec3 targetPosition = point->_position + delta;
|
glm::vec3 targetPosition = point->_position + delta;
|
||||||
_distances[i] = glm::distance(_contactPoint, targetPosition);
|
_distances[i] = glm::distance(_contactPoint, targetPosition);
|
||||||
point->_position += HACK_STRENGTH * delta;
|
point->_position += delta;
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
for (int i = 0; i < _numPoints; ++i) {
|
for (int i = 0; i < _numPoints; ++i) {
|
||||||
_distances[i] = glm::length(glm::length(_offsets[i]));
|
_distances[i] = glm::length(glm::length(_offsets[i]));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
return 0.0f;
|
||||||
|
}
|
||||||
|
|
||||||
|
// virtual
|
||||||
|
void ContactPoint::applyFriction() {
|
||||||
|
// TODO: Andrew to re-implement this in a different way
|
||||||
|
/*
|
||||||
|
for (int i = 0; i < _numPoints; ++i) {
|
||||||
|
glm::vec3& position = _points[i]->_position;
|
||||||
|
// TODO: use a fast distance approximation
|
||||||
|
float newDistance = glm::distance(_contactPoint, position);
|
||||||
|
float constrainedDistance = _distances[i];
|
||||||
|
// NOTE: these "distance" constraints only push OUT, don't pull IN.
|
||||||
|
if (newDistance > EPSILON && newDistance < constrainedDistance) {
|
||||||
|
glm::vec3 direction = (_contactPoint - position) / newDistance;
|
||||||
|
glm::vec3 center = 0.5f * (_contactPoint + position);
|
||||||
|
_contactPoint = center + (0.5f * constrainedDistance) * direction;
|
||||||
|
position = center - (0.5f * constrainedDistance) * direction;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
*/
|
||||||
}
|
}
|
||||||
|
|
||||||
void ContactPoint::updateContact(const CollisionInfo& collision, quint32 frame) {
|
void ContactPoint::updateContact(const CollisionInfo& collision, quint32 frame) {
|
||||||
|
|
|
@ -26,8 +26,8 @@ public:
|
||||||
ContactPoint(const CollisionInfo& collision, quint32 frame);
|
ContactPoint(const CollisionInfo& collision, quint32 frame);
|
||||||
|
|
||||||
virtual float enforce();
|
virtual float enforce();
|
||||||
|
|
||||||
void buildConstraints();
|
void applyFriction();
|
||||||
void updateContact(const CollisionInfo& collision, quint32 frame);
|
void updateContact(const CollisionInfo& collision, quint32 frame);
|
||||||
quint32 getLastFrame() const { return _lastFrame; }
|
quint32 getLastFrame() const { return _lastFrame; }
|
||||||
|
|
||||||
|
|
|
@ -47,12 +47,12 @@ PhysicsSimulation::~PhysicsSimulation() {
|
||||||
void PhysicsSimulation::setRagdoll(Ragdoll* ragdoll) {
|
void PhysicsSimulation::setRagdoll(Ragdoll* ragdoll) {
|
||||||
if (_ragdoll != ragdoll) {
|
if (_ragdoll != ragdoll) {
|
||||||
if (_ragdoll) {
|
if (_ragdoll) {
|
||||||
_ragdoll->_ragdollSimulation = NULL;
|
_ragdoll->_simulation = NULL;
|
||||||
}
|
}
|
||||||
_ragdoll = ragdoll;
|
_ragdoll = ragdoll;
|
||||||
if (_ragdoll) {
|
if (_ragdoll) {
|
||||||
assert(!(_ragdoll->_ragdollSimulation));
|
assert(!(_ragdoll->_simulation));
|
||||||
_ragdoll->_ragdollSimulation = this;
|
_ragdoll->_simulation = this;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -144,7 +144,7 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
||||||
// list is full
|
// list is full
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
if (doll->_ragdollSimulation == this) {
|
if (doll->_simulation == this) {
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
if (doll == _otherRagdolls[i]) {
|
if (doll == _otherRagdolls[i]) {
|
||||||
// already in list
|
// already in list
|
||||||
|
@ -153,8 +153,8 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
// add to list
|
// add to list
|
||||||
assert(!(doll->_ragdollSimulation));
|
assert(!(doll->_simulation));
|
||||||
doll->_ragdollSimulation = this;
|
doll->_simulation = this;
|
||||||
_otherRagdolls.push_back(doll);
|
_otherRagdolls.push_back(doll);
|
||||||
|
|
||||||
// set the massScale of otherRagdolls artificially high
|
// set the massScale of otherRagdolls artificially high
|
||||||
|
@ -164,7 +164,7 @@ bool PhysicsSimulation::addRagdoll(Ragdoll* doll) {
|
||||||
|
|
||||||
void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
||||||
int numDolls = _otherRagdolls.size();
|
int numDolls = _otherRagdolls.size();
|
||||||
if (doll->_ragdollSimulation != this) {
|
if (doll->_simulation != this) {
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
|
@ -178,7 +178,7 @@ void PhysicsSimulation::removeRagdoll(Ragdoll* doll) {
|
||||||
_otherRagdolls.pop_back();
|
_otherRagdolls.pop_back();
|
||||||
_otherRagdolls[i] = lastDoll;
|
_otherRagdolls[i] = lastDoll;
|
||||||
}
|
}
|
||||||
doll->_ragdollSimulation = NULL;
|
doll->_simulation = NULL;
|
||||||
doll->setMassScale(1.0f);
|
doll->setMassScale(1.0f);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
@ -195,13 +195,13 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
quint64 expiry = startTime + maxUsec;
|
quint64 expiry = startTime + maxUsec;
|
||||||
|
|
||||||
moveRagdolls(deltaTime);
|
moveRagdolls(deltaTime);
|
||||||
buildContactConstraints();
|
enforceContacts();
|
||||||
int numDolls = _otherRagdolls.size();
|
int numDolls = _otherRagdolls.size();
|
||||||
{
|
{
|
||||||
PerformanceTimer perfTimer("enforce");
|
PerformanceTimer perfTimer("enforce");
|
||||||
_ragdoll->enforceRagdollConstraints();
|
_ragdoll->enforceConstraints();
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
_otherRagdolls[i]->enforceRagdollConstraints();
|
_otherRagdolls[i]->enforceConstraints();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -214,12 +214,12 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
|
|
||||||
{ // enforce constraints
|
{ // enforce constraints
|
||||||
PerformanceTimer perfTimer("enforce");
|
PerformanceTimer perfTimer("enforce");
|
||||||
error = _ragdoll->enforceRagdollConstraints();
|
error = _ragdoll->enforceConstraints();
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
error = glm::max(error, _otherRagdolls[i]->enforceRagdollConstraints());
|
error = glm::max(error, _otherRagdolls[i]->enforceConstraints());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
enforceContactConstraints();
|
applyContactFriction();
|
||||||
++iterations;
|
++iterations;
|
||||||
|
|
||||||
now = usecTimestampNow();
|
now = usecTimestampNow();
|
||||||
|
@ -230,10 +230,10 @@ void PhysicsSimulation::stepForward(float deltaTime, float minError, int maxIter
|
||||||
|
|
||||||
void PhysicsSimulation::moveRagdolls(float deltaTime) {
|
void PhysicsSimulation::moveRagdolls(float deltaTime) {
|
||||||
PerformanceTimer perfTimer("integrate");
|
PerformanceTimer perfTimer("integrate");
|
||||||
_ragdoll->stepRagdollForward(deltaTime);
|
_ragdoll->stepForward(deltaTime);
|
||||||
int numDolls = _otherRagdolls.size();
|
int numDolls = _otherRagdolls.size();
|
||||||
for (int i = 0; i < numDolls; ++i) {
|
for (int i = 0; i < numDolls; ++i) {
|
||||||
_otherRagdolls[i]->stepRagdollForward(deltaTime);
|
_otherRagdolls[i]->stepForward(deltaTime);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -288,16 +288,7 @@ void PhysicsSimulation::resolveCollisions() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void PhysicsSimulation::buildContactConstraints() {
|
void PhysicsSimulation::enforceContacts() {
|
||||||
PerformanceTimer perfTimer("contacts");
|
|
||||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
|
||||||
while (itr != _contacts.end()) {
|
|
||||||
itr.value().buildConstraints();
|
|
||||||
++itr;
|
|
||||||
}
|
|
||||||
}
|
|
||||||
|
|
||||||
void PhysicsSimulation::enforceContactConstraints() {
|
|
||||||
PerformanceTimer perfTimer("contacts");
|
PerformanceTimer perfTimer("contacts");
|
||||||
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||||
while (itr != _contacts.end()) {
|
while (itr != _contacts.end()) {
|
||||||
|
@ -306,6 +297,15 @@ void PhysicsSimulation::enforceContactConstraints() {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void PhysicsSimulation::applyContactFriction() {
|
||||||
|
PerformanceTimer perfTimer("contacts");
|
||||||
|
QMap<quint64, ContactPoint>::iterator itr = _contacts.begin();
|
||||||
|
while (itr != _contacts.end()) {
|
||||||
|
itr.value().applyFriction();
|
||||||
|
++itr;
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void PhysicsSimulation::updateContacts() {
|
void PhysicsSimulation::updateContacts() {
|
||||||
PerformanceTimer perfTimer("contacts");
|
PerformanceTimer perfTimer("contacts");
|
||||||
int numCollisions = _collisions.size();
|
int numCollisions = _collisions.size();
|
||||||
|
|
|
@ -56,8 +56,8 @@ protected:
|
||||||
void computeCollisions();
|
void computeCollisions();
|
||||||
void resolveCollisions();
|
void resolveCollisions();
|
||||||
|
|
||||||
void buildContactConstraints();
|
void enforceContacts();
|
||||||
void enforceContactConstraints();
|
void applyContactFriction();
|
||||||
void updateContacts();
|
void updateContacts();
|
||||||
void pruneContacts();
|
void pruneContacts();
|
||||||
|
|
||||||
|
|
|
@ -19,27 +19,27 @@
|
||||||
#include "PhysicsSimulation.h"
|
#include "PhysicsSimulation.h"
|
||||||
#include "SharedUtil.h" // for EPSILON
|
#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() {
|
Ragdoll::~Ragdoll() {
|
||||||
clearRagdollConstraintsAndPoints();
|
clearConstraintsAndPoints();
|
||||||
if (_ragdollSimulation) {
|
if (_simulation) {
|
||||||
_ragdollSimulation->removeRagdoll(this);
|
_simulation->removeRagdoll(this);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ragdoll::stepRagdollForward(float deltaTime) {
|
void Ragdoll::stepForward(float deltaTime) {
|
||||||
if (_ragdollSimulation) {
|
if (_simulation) {
|
||||||
updateSimulationTransforms(_ragdollTranslation - _ragdollSimulation->getTranslation(), _ragdollRotation);
|
updateSimulationTransforms(_translation - _simulation->getTranslation(), _rotation);
|
||||||
}
|
}
|
||||||
int numPoints = _ragdollPoints.size();
|
int numPoints = _points.size();
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
_ragdollPoints[i].integrateForward();
|
_points[i].integrateForward();
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ragdoll::clearRagdollConstraintsAndPoints() {
|
void Ragdoll::clearConstraintsAndPoints() {
|
||||||
int numConstraints = _boneConstraints.size();
|
int numConstraints = _boneConstraints.size();
|
||||||
for (int i = 0; i < numConstraints; ++i) {
|
for (int i = 0; i < numConstraints; ++i) {
|
||||||
delete _boneConstraints[i];
|
delete _boneConstraints[i];
|
||||||
|
@ -50,10 +50,10 @@ void Ragdoll::clearRagdollConstraintsAndPoints() {
|
||||||
delete _fixedConstraints[i];
|
delete _fixedConstraints[i];
|
||||||
}
|
}
|
||||||
_fixedConstraints.clear();
|
_fixedConstraints.clear();
|
||||||
_ragdollPoints.clear();
|
_points.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
float Ragdoll::enforceRagdollConstraints() {
|
float Ragdoll::enforceConstraints() {
|
||||||
float maxDistance = 0.0f;
|
float maxDistance = 0.0f;
|
||||||
// enforce the bone constraints first
|
// enforce the bone constraints first
|
||||||
int numConstraints = _boneConstraints.size();
|
int numConstraints = _boneConstraints.size();
|
||||||
|
@ -68,16 +68,16 @@ float Ragdoll::enforceRagdollConstraints() {
|
||||||
return maxDistance;
|
return maxDistance;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ragdoll::initRagdollTransform() {
|
void Ragdoll::initTransform() {
|
||||||
_ragdollTranslation = glm::vec3(0.0f);
|
_translation = glm::vec3(0.0f);
|
||||||
_ragdollRotation = glm::quat();
|
_rotation = glm::quat();
|
||||||
_translationInSimulationFrame = glm::vec3(0.0f);
|
_translationInSimulationFrame = glm::vec3(0.0f);
|
||||||
_rotationInSimulationFrame = glm::quat();
|
_rotationInSimulationFrame = glm::quat();
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ragdoll::setRagdollTransform(const glm::vec3& translation, const glm::quat& rotation) {
|
void Ragdoll::setTransform(const glm::vec3& translation, const glm::quat& rotation) {
|
||||||
_ragdollTranslation = translation;
|
_translation = translation;
|
||||||
_ragdollRotation = rotation;
|
_rotation = rotation;
|
||||||
}
|
}
|
||||||
|
|
||||||
void Ragdoll::updateSimulationTransforms(const glm::vec3& translation, const glm::quat& 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);
|
glm::quat deltaRotation = rotation * glm::inverse(_rotationInSimulationFrame);
|
||||||
|
|
||||||
// apply the deltas to all ragdollPoints
|
// apply the deltas to all ragdollPoints
|
||||||
int numPoints = _ragdollPoints.size();
|
int numPoints = _points.size();
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
_ragdollPoints[i].move(deltaPosition, deltaRotation, _translationInSimulationFrame);
|
_points[i].move(deltaPosition, deltaRotation, _translationInSimulationFrame);
|
||||||
}
|
}
|
||||||
|
|
||||||
// remember the current transform
|
// remember the current transform
|
||||||
|
@ -109,9 +109,9 @@ void Ragdoll::setMassScale(float scale) {
|
||||||
scale = glm::clamp(glm::abs(scale), MIN_SCALE, MAX_SCALE);
|
scale = glm::clamp(glm::abs(scale), MIN_SCALE, MAX_SCALE);
|
||||||
if (scale != _massScale) {
|
if (scale != _massScale) {
|
||||||
float rescale = scale / _massScale;
|
float rescale = scale / _massScale;
|
||||||
int numPoints = _ragdollPoints.size();
|
int numPoints = _points.size();
|
||||||
for (int i = 0; i < numPoints; ++i) {
|
for (int i = 0; i < numPoints; ++i) {
|
||||||
_ragdollPoints[i].setMass(rescale * _ragdollPoints[i].getMass());
|
_points[i].setMass(rescale * _points[i].getMass());
|
||||||
}
|
}
|
||||||
_massScale = scale;
|
_massScale = scale;
|
||||||
}
|
}
|
||||||
|
|
|
@ -33,44 +33,44 @@ public:
|
||||||
Ragdoll();
|
Ragdoll();
|
||||||
virtual ~Ragdoll();
|
virtual ~Ragdoll();
|
||||||
|
|
||||||
virtual void stepRagdollForward(float deltaTime);
|
virtual void stepForward(float deltaTime);
|
||||||
|
|
||||||
/// \return max distance of point movement
|
/// \return max distance of point movement
|
||||||
float enforceRagdollConstraints();
|
float enforceConstraints();
|
||||||
|
|
||||||
// both const and non-const getPoints()
|
// both const and non-const getPoints()
|
||||||
const QVector<VerletPoint>& getRagdollPoints() const { return _ragdollPoints; }
|
const QVector<VerletPoint>& getPoints() const { return _points; }
|
||||||
QVector<VerletPoint>& getRagdollPoints() { return _ragdollPoints; }
|
QVector<VerletPoint>& getPoints() { return _points; }
|
||||||
|
|
||||||
void initRagdollTransform();
|
void initTransform();
|
||||||
|
|
||||||
/// set the translation and rotation of the Ragdoll and adjust all VerletPoints.
|
/// 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; }
|
const glm::vec3& getTranslationInSimulationFrame() const { return _translationInSimulationFrame; }
|
||||||
|
|
||||||
void setMassScale(float scale);
|
void setMassScale(float scale);
|
||||||
float getMassScale() const { return _massScale; }
|
float getMassScale() const { return _massScale; }
|
||||||
|
|
||||||
protected:
|
void clearConstraintsAndPoints();
|
||||||
void clearRagdollConstraintsAndPoints();
|
virtual void initPoints() = 0;
|
||||||
virtual void initRagdollPoints() = 0;
|
virtual void buildConstraints() = 0;
|
||||||
virtual void buildRagdollConstraints() = 0;
|
|
||||||
|
|
||||||
|
protected:
|
||||||
float _massScale;
|
float _massScale;
|
||||||
glm::vec3 _ragdollTranslation; // world-frame
|
glm::vec3 _translation; // world-frame
|
||||||
glm::quat _ragdollRotation; // world-frame
|
glm::quat _rotation; // world-frame
|
||||||
glm::vec3 _translationInSimulationFrame;
|
glm::vec3 _translationInSimulationFrame;
|
||||||
glm::quat _rotationInSimulationFrame;
|
glm::quat _rotationInSimulationFrame;
|
||||||
|
|
||||||
QVector<VerletPoint> _ragdollPoints;
|
QVector<VerletPoint> _points;
|
||||||
QVector<DistanceConstraint*> _boneConstraints;
|
QVector<DistanceConstraint*> _boneConstraints;
|
||||||
QVector<FixedConstraint*> _fixedConstraints;
|
QVector<FixedConstraint*> _fixedConstraints;
|
||||||
private:
|
private:
|
||||||
void updateSimulationTransforms(const glm::vec3& translation, const glm::quat& rotation);
|
void updateSimulationTransforms(const glm::vec3& translation, const glm::quat& rotation);
|
||||||
|
|
||||||
friend class PhysicsSimulation;
|
friend class PhysicsSimulation;
|
||||||
PhysicsSimulation* _ragdollSimulation;
|
PhysicsSimulation* _simulation;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif // hifi_Ragdoll_h
|
#endif // hifi_Ragdoll_h
|
||||||
|
|
|
@ -16,12 +16,14 @@
|
||||||
#include <cerrno>
|
#include <cerrno>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include <MovingMinMaxAvg.h> // for MovingMinMaxAvg
|
#include <MovingMinMaxAvg.h>
|
||||||
#include <SequenceNumberStats.h>
|
#include <SequenceNumberStats.h>
|
||||||
#include <StdDev.h>
|
|
||||||
#include <SharedUtil.h> // for usecTimestampNow
|
#include <SharedUtil.h> // for usecTimestampNow
|
||||||
|
#include <SimpleMovingAverage.h>
|
||||||
|
#include <StdDev.h>
|
||||||
|
|
||||||
const quint64 MSEC_TO_USEC = 1000;
|
const quint64 MSEC_TO_USEC = 1000;
|
||||||
|
const quint64 LARGE_STATS_TIME = 500; // we don't expect stats calculation to take more than this many usecs
|
||||||
|
|
||||||
void runSend(const char* addressOption, int port, int gap, int size, int report);
|
void runSend(const char* addressOption, int port, int gap, int size, int report);
|
||||||
void runReceive(const char* addressOption, int port, int gap, int size, int report);
|
void runReceive(const char* addressOption, int port, int gap, int size, int report);
|
||||||
|
@ -77,25 +79,37 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
||||||
servaddr.sin_addr.s_addr = inet_addr(addressOption);
|
servaddr.sin_addr.s_addr = inet_addr(addressOption);
|
||||||
servaddr.sin_port = htons(port);
|
servaddr.sin_port = htons(port);
|
||||||
|
|
||||||
|
const int SAMPLES_FOR_SECOND = 1000000 / gap;
|
||||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
std::cout << "SAMPLES_FOR_SECOND:" << SAMPLES_FOR_SECOND << "\n";
|
||||||
|
const int INTERVALS_PER_30_SECONDS = 30;
|
||||||
|
std::cout << "INTERVALS_PER_30_SECONDS:" << INTERVALS_PER_30_SECONDS << "\n";
|
||||||
|
const int SAMPLES_FOR_30_SECONDS = 30 * SAMPLES_FOR_SECOND;
|
||||||
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
||||||
|
const int REPORTS_FOR_30_SECONDS = 30 * MSECS_PER_SECOND / report;
|
||||||
|
std::cout << "REPORTS_FOR_30_SECONDS:" << REPORTS_FOR_30_SECONDS << "\n";
|
||||||
|
|
||||||
const int SAMPLES_PER_REPORT = report * MSEC_TO_USEC / gap;
|
int intervalsPerReport = report / MSEC_TO_USEC;
|
||||||
std::cout << "SAMPLES_PER_REPORT:" << SAMPLES_PER_REPORT << "\n";
|
if (intervalsPerReport < 1) {
|
||||||
|
intervalsPerReport = 1;
|
||||||
|
}
|
||||||
|
std::cout << "intervalsPerReport:" << intervalsPerReport << "\n";
|
||||||
|
MovingMinMaxAvg<int> timeGaps(SAMPLES_FOR_SECOND, INTERVALS_PER_30_SECONDS);
|
||||||
|
MovingMinMaxAvg<int> timeGapsPerReport(SAMPLES_FOR_SECOND, intervalsPerReport);
|
||||||
|
|
||||||
char* outputBuffer = new char[size];
|
char* outputBuffer = new char[size];
|
||||||
memset(outputBuffer, 0, size);
|
memset(outputBuffer, 0, size);
|
||||||
|
|
||||||
quint16 outgoingSequenceNumber = 0;
|
quint16 outgoingSequenceNumber = 0;
|
||||||
|
|
||||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS);
|
|
||||||
MovingMinMaxAvg<int> timeGapsPerReport(1, SAMPLES_PER_REPORT);
|
|
||||||
|
|
||||||
StDev stDevReportInterval;
|
StDev stDevReportInterval;
|
||||||
StDev stDev30s;
|
StDev stDev30s;
|
||||||
StDev stDev;
|
StDev stDev;
|
||||||
|
|
||||||
|
SimpleMovingAverage averageNetworkTime(SAMPLES_FOR_30_SECONDS);
|
||||||
|
SimpleMovingAverage averageStatsCalcultionTime(SAMPLES_FOR_30_SECONDS);
|
||||||
|
float lastStatsCalculationTime = 0.0f; // we add out stats calculation time in the next calculation window
|
||||||
|
bool hasStatsCalculationTime = false;
|
||||||
|
|
||||||
quint64 last = usecTimestampNow();
|
quint64 last = usecTimestampNow();
|
||||||
quint64 lastReport = 0;
|
quint64 lastReport = 0;
|
||||||
|
@ -111,19 +125,37 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
||||||
// pack seq num
|
// pack seq num
|
||||||
memcpy(outputBuffer, &outgoingSequenceNumber, sizeof(quint16));
|
memcpy(outputBuffer, &outgoingSequenceNumber, sizeof(quint16));
|
||||||
|
|
||||||
|
quint64 networkStart = usecTimestampNow();
|
||||||
int n = sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
int n = sendto(sockfd, outputBuffer, size, 0, (struct sockaddr *)&servaddr, sizeof(servaddr));
|
||||||
|
quint64 networkEnd = usecTimestampNow();
|
||||||
|
float networkElapsed = (float)(networkEnd - networkStart);
|
||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
std::cout << "Send error: " << strerror(errno) << "\n";
|
std::cout << "Send error: " << strerror(errno) << "\n";
|
||||||
}
|
}
|
||||||
outgoingSequenceNumber++;
|
outgoingSequenceNumber++;
|
||||||
|
|
||||||
|
quint64 statsCalcultionStart = usecTimestampNow();
|
||||||
|
|
||||||
int gapDifferece = actualGap - gap;
|
int gapDifferece = actualGap - gap;
|
||||||
|
|
||||||
timeGaps.update(gapDifferece);
|
timeGaps.update(gapDifferece);
|
||||||
timeGapsPerReport.update(gapDifferece);
|
timeGapsPerReport.update(gapDifferece);
|
||||||
stDev.addValue(gapDifferece);
|
stDev.addValue(gapDifferece);
|
||||||
stDev30s.addValue(gapDifferece);
|
stDev30s.addValue(gapDifferece);
|
||||||
stDevReportInterval.addValue(gapDifferece);
|
stDevReportInterval.addValue(gapDifferece);
|
||||||
last = now;
|
last = now;
|
||||||
|
|
||||||
|
// track out network time and stats calculation times
|
||||||
|
averageNetworkTime.updateAverage(networkElapsed);
|
||||||
|
|
||||||
|
// for our stats calculation time, we actually delay the updating by one sample.
|
||||||
|
// we do this so that the calculation of the average timing for the stats calculation
|
||||||
|
// happen inside of the calculation processing. This ensures that tracking stats on
|
||||||
|
// stats calculation doesn't side effect the remaining running time.
|
||||||
|
if (hasStatsCalculationTime) {
|
||||||
|
averageStatsCalcultionTime.updateAverage(lastStatsCalculationTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (now - lastReport >= (report * MSEC_TO_USEC)) {
|
if (now - lastReport >= (report * MSEC_TO_USEC)) {
|
||||||
|
|
||||||
|
@ -144,6 +176,9 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
||||||
<< "max: " << timeGapsPerReport.getWindowMax() << " usecs, "
|
<< "max: " << timeGapsPerReport.getWindowMax() << " usecs, "
|
||||||
<< "avg: " << timeGapsPerReport.getWindowAverage() << " usecs, "
|
<< "avg: " << timeGapsPerReport.getWindowAverage() << " usecs, "
|
||||||
<< "stdev: " << stDevReportInterval.getStDev() << " usecs\n"
|
<< "stdev: " << stDevReportInterval.getStDev() << " usecs\n"
|
||||||
|
<< "Average Execution Times Last 30s:\n"
|
||||||
|
<< " network: " << averageNetworkTime.getAverage() << " usecs average\n"
|
||||||
|
<< " stats: " << averageStatsCalcultionTime.getAverage() << " usecs average"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
stDevReportInterval.reset();
|
stDevReportInterval.reset();
|
||||||
|
@ -153,6 +188,14 @@ void runSend(const char* addressOption, int port, int gap, int size, int report)
|
||||||
|
|
||||||
lastReport = now;
|
lastReport = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint64 statsCalcultionEnd = usecTimestampNow();
|
||||||
|
lastStatsCalculationTime = (float)(statsCalcultionEnd - statsCalcultionStart);
|
||||||
|
if (lastStatsCalculationTime > LARGE_STATS_TIME) {
|
||||||
|
qDebug() << "WARNING -- unexpectedly large lastStatsCalculationTime=" << lastStatsCalculationTime;
|
||||||
|
}
|
||||||
|
hasStatsCalculationTime = true;
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] outputBuffer;
|
delete[] outputBuffer;
|
||||||
|
@ -184,21 +227,26 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
myaddr.sin_port = htons(port);
|
myaddr.sin_port = htons(port);
|
||||||
|
|
||||||
|
|
||||||
const int SAMPLES_FOR_30_SECONDS = 30 * 1000000 / gap;
|
const int SAMPLES_FOR_SECOND = 1000000 / gap;
|
||||||
|
std::cout << "SAMPLES_FOR_SECOND:" << SAMPLES_FOR_SECOND << "\n";
|
||||||
|
const int INTERVALS_PER_30_SECONDS = 30;
|
||||||
|
std::cout << "INTERVALS_PER_30_SECONDS:" << INTERVALS_PER_30_SECONDS << "\n";
|
||||||
|
const int SAMPLES_FOR_30_SECONDS = 30 * SAMPLES_FOR_SECOND;
|
||||||
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
std::cout << "SAMPLES_FOR_30_SECONDS:" << SAMPLES_FOR_30_SECONDS << "\n";
|
||||||
|
|
||||||
const int SAMPLES_PER_REPORT = report * MSEC_TO_USEC / gap;
|
|
||||||
std::cout << "SAMPLES_PER_REPORT:" << SAMPLES_PER_REPORT << "\n";
|
|
||||||
|
|
||||||
const int REPORTS_FOR_30_SECONDS = 30 * MSECS_PER_SECOND / report;
|
const int REPORTS_FOR_30_SECONDS = 30 * MSECS_PER_SECOND / report;
|
||||||
std::cout << "REPORTS_FOR_30_SECONDS:" << REPORTS_FOR_30_SECONDS << "\n";
|
std::cout << "REPORTS_FOR_30_SECONDS:" << REPORTS_FOR_30_SECONDS << "\n";
|
||||||
|
|
||||||
|
int intervalsPerReport = report / MSEC_TO_USEC;
|
||||||
|
if (intervalsPerReport < 1) {
|
||||||
|
intervalsPerReport = 1;
|
||||||
|
}
|
||||||
|
std::cout << "intervalsPerReport:" << intervalsPerReport << "\n";
|
||||||
|
MovingMinMaxAvg<int> timeGaps(SAMPLES_FOR_SECOND, INTERVALS_PER_30_SECONDS);
|
||||||
|
MovingMinMaxAvg<int> timeGapsPerReport(SAMPLES_FOR_SECOND, intervalsPerReport);
|
||||||
|
|
||||||
char* inputBuffer = new char[size];
|
char* inputBuffer = new char[size];
|
||||||
memset(inputBuffer, 0, size);
|
memset(inputBuffer, 0, size);
|
||||||
|
|
||||||
MovingMinMaxAvg<int> timeGaps(1, SAMPLES_FOR_30_SECONDS);
|
|
||||||
MovingMinMaxAvg<int> timeGapsPerReport(1, SAMPLES_PER_REPORT);
|
|
||||||
|
|
||||||
SequenceNumberStats seqStats(REPORTS_FOR_30_SECONDS);
|
SequenceNumberStats seqStats(REPORTS_FOR_30_SECONDS);
|
||||||
|
|
||||||
|
@ -206,6 +254,11 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
StDev stDev30s;
|
StDev stDev30s;
|
||||||
StDev stDev;
|
StDev stDev;
|
||||||
|
|
||||||
|
SimpleMovingAverage averageNetworkTime(SAMPLES_FOR_30_SECONDS);
|
||||||
|
SimpleMovingAverage averageStatsCalcultionTime(SAMPLES_FOR_30_SECONDS);
|
||||||
|
float lastStatsCalculationTime = 0.0f; // we add out stats calculation time in the next calculation window
|
||||||
|
bool hasStatsCalculationTime = false;
|
||||||
|
|
||||||
if (bind(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
|
if (bind(sockfd, (struct sockaddr *)&myaddr, sizeof(myaddr)) < 0) {
|
||||||
std::cout << "bind failed\n";
|
std::cout << "bind failed\n";
|
||||||
return;
|
return;
|
||||||
|
@ -213,9 +266,14 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
|
|
||||||
quint64 last = 0; // first case
|
quint64 last = 0; // first case
|
||||||
quint64 lastReport = 0;
|
quint64 lastReport = 0;
|
||||||
|
|
||||||
while (true) {
|
while (true) {
|
||||||
|
|
||||||
|
quint64 networkStart = usecTimestampNow();
|
||||||
n = recvfrom(sockfd, inputBuffer, size, 0, NULL, NULL); // we don't care about where it came from
|
n = recvfrom(sockfd, inputBuffer, size, 0, NULL, NULL); // we don't care about where it came from
|
||||||
|
quint64 networkEnd = usecTimestampNow();
|
||||||
|
float networkElapsed = (float)(networkEnd - networkStart);
|
||||||
|
|
||||||
if (n < 0) {
|
if (n < 0) {
|
||||||
std::cout << "Receive error: " << strerror(errno) << "\n";
|
std::cout << "Receive error: " << strerror(errno) << "\n";
|
||||||
}
|
}
|
||||||
|
@ -228,8 +286,11 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
last = usecTimestampNow();
|
last = usecTimestampNow();
|
||||||
std::cout << "first packet received\n";
|
std::cout << "first packet received\n";
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
|
quint64 statsCalcultionStart = usecTimestampNow();
|
||||||
quint64 now = usecTimestampNow();
|
quint64 now = usecTimestampNow();
|
||||||
int actualGap = now - last;
|
int actualGap = now - last;
|
||||||
|
|
||||||
int gapDifferece = actualGap - gap;
|
int gapDifferece = actualGap - gap;
|
||||||
timeGaps.update(gapDifferece);
|
timeGaps.update(gapDifferece);
|
||||||
timeGapsPerReport.update(gapDifferece);
|
timeGapsPerReport.update(gapDifferece);
|
||||||
|
@ -237,6 +298,17 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
stDev30s.addValue(gapDifferece);
|
stDev30s.addValue(gapDifferece);
|
||||||
stDevReportInterval.addValue(gapDifferece);
|
stDevReportInterval.addValue(gapDifferece);
|
||||||
last = now;
|
last = now;
|
||||||
|
|
||||||
|
// track out network time and stats calculation times
|
||||||
|
averageNetworkTime.updateAverage(networkElapsed);
|
||||||
|
|
||||||
|
// for our stats calculation time, we actually delay the updating by one sample.
|
||||||
|
// we do this so that the calculation of the average timing for the stats calculation
|
||||||
|
// happen inside of the calculation processing. This ensures that tracking stats on
|
||||||
|
// stats calculation doesn't side effect the remaining running time.
|
||||||
|
if (hasStatsCalculationTime) {
|
||||||
|
averageStatsCalcultionTime.updateAverage(lastStatsCalculationTime);
|
||||||
|
}
|
||||||
|
|
||||||
if (now - lastReport >= (report * MSEC_TO_USEC)) {
|
if (now - lastReport >= (report * MSEC_TO_USEC)) {
|
||||||
|
|
||||||
|
@ -258,9 +330,12 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
<< "max: " << timeGapsPerReport.getWindowMax() << " usecs, "
|
<< "max: " << timeGapsPerReport.getWindowMax() << " usecs, "
|
||||||
<< "avg: " << timeGapsPerReport.getWindowAverage() << " usecs, "
|
<< "avg: " << timeGapsPerReport.getWindowAverage() << " usecs, "
|
||||||
<< "stdev: " << stDevReportInterval.getStDev() << " usecs\n"
|
<< "stdev: " << stDevReportInterval.getStDev() << " usecs\n"
|
||||||
|
<< "Average Execution Times Last 30s:\n"
|
||||||
|
<< " network: " << averageNetworkTime.getAverage() << " usecs average\n"
|
||||||
|
<< " stats: " << averageStatsCalcultionTime.getAverage() << " usecs average"
|
||||||
<< "\n";
|
<< "\n";
|
||||||
|
|
||||||
stDevReportInterval.reset();
|
stDevReportInterval.reset();
|
||||||
|
|
||||||
if (stDev30s.getSamples() > SAMPLES_FOR_30_SECONDS) {
|
if (stDev30s.getSamples() > SAMPLES_FOR_30_SECONDS) {
|
||||||
stDev30s.reset();
|
stDev30s.reset();
|
||||||
}
|
}
|
||||||
|
@ -282,6 +357,14 @@ void runReceive(const char* addressOption, int port, int gap, int size, int repo
|
||||||
|
|
||||||
lastReport = now;
|
lastReport = now;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
quint64 statsCalcultionEnd = usecTimestampNow();
|
||||||
|
|
||||||
|
lastStatsCalculationTime = (float)(statsCalcultionEnd - statsCalcultionStart);
|
||||||
|
if (lastStatsCalculationTime > LARGE_STATS_TIME) {
|
||||||
|
qDebug() << "WARNING -- unexpectedly large lastStatsCalculationTime=" << lastStatsCalculationTime;
|
||||||
|
}
|
||||||
|
hasStatsCalculationTime = true;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
delete[] inputBuffer;
|
delete[] inputBuffer;
|
||||||
|
|
Loading…
Reference in a new issue