add SimulationEngine, MyAvatar has one.

This commit is contained in:
Andrew Meadows 2014-06-12 18:15:20 -07:00
parent 5be470bcbc
commit fb7f5707c8
4 changed files with 126 additions and 1 deletions

View file

@ -76,7 +76,8 @@ MyAvatar::MyAvatar() :
_lastFloorContactPoint(0.0f),
_lookAtTargetAvatar(),
_shouldRender(true),
_billboardValid(false)
_billboardValid(false),
_simulationEngine()
{
for (int i = 0; i < MAX_DRIVE_KEYS; i++) {
_driveKeys[i] = 0.0f;

View file

@ -14,6 +14,8 @@
#include <QSettings>
#include <SimulationEngine.h>
#include "Avatar.h"
enum AvatarHandState
@ -172,6 +174,7 @@ private:
float _oculusYawOffset;
QList<AnimationHandlePointer> _animationHandles;
SimulationEngine _simulationEngine;
// private methods
float computeDistanceToFloor(const glm::vec3& startPoint);

View file

@ -0,0 +1,77 @@
//
// SimulationEngine.cpp
// interface/src/avatar
//
// Created by Andrew Meadows 2014.06.06
// 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 <glm/glm.hpp>
#include "SimulationEngine.h"
int MAX_DOLLS_PER_ENGINE = 32;
int MAX_COLLISIONS_PER_ENGINE = 256;
const int NUM_SHAPE_BITS = 6;
const int SHAPE_INDEX_MASK = (1 << (NUM_SHAPE_BITS + 1)) - 1;
SimulationEngine::SimulationEngine() : _collisionList(MAX_COLLISIONS_PER_ENGINE) {
}
SimulationEngine::~SimulationEngine() {
_dolls.clear();
}
bool SimulationEngine::addRagDoll(RagDoll* doll) {
int numDolls = _dolls.size();
if (numDolls < MAX_DOLLS_PER_ENGINE) {
for (int i = 0; i < numDolls; ++i) {
if (doll == _dolls[i]) {
// already in list
return true;
}
}
_dolls.push_back(doll);
return true;
}
return false;
}
void SimulationEngine::removeRagDoll(RagDoll* doll) {
int numDolls = _dolls.size();
for (int i = 0; i < numDolls; ++i) {
if (doll == _dolls[i]) {
if (i == numDolls - 1) {
// remove it
_dolls.pop_back();
} else {
// swap the last for this one
RagDoll* lastDoll = _dolls[numDolls - 1];
_dolls.pop_back();
_dolls[i] = lastDoll;
}
break;
}
}
}
float SimulationEngine::enforceConstraints() {
float maxMovement = 0.0f;
int numDolls = _dolls.size();
for (int i = 0; i < numDolls; ++i) {
maxMovement = glm::max(maxMovement, _dolls[i]->enforceConstraints());
}
return maxMovement;
}
int SimulationEngine::computeCollisions() {
return 0.0f;
}
void SimulationEngine::processCollisions() {
}

View file

@ -0,0 +1,44 @@
//
// SimulationEngine.h
// interface/src/avatar
//
// Created by Andrew Meadows 2014.06.06
// 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_SimulationEngine_h
#define hifi_SimulationEngine_h
#include <QVector>
#include "CollisionInfo.h"
#include "RagDoll.h"
class SimulationEngine {
public:
SimulationEngine();
~SimulationEngine();
/// \return true if doll was added to, or already in the list
bool addRagDoll(RagDoll* doll);
void removeRagDoll(RagDoll* doll);
/// \return distance of largest movement
float enforceConstraints();
/// \return number of collisions
int computeCollisions();
void processCollisions();
private:
CollisionList _collisionList;
QVector<RagDoll*> _dolls;
};
#endif // hifi_SimulationEngine_h