mirror of
https://github.com/overte-org/overte.git
synced 2025-08-04 12:35:19 +02:00
add SimulationEngine, MyAvatar has one.
This commit is contained in:
parent
5be470bcbc
commit
fb7f5707c8
4 changed files with 126 additions and 1 deletions
|
@ -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;
|
||||
|
|
|
@ -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);
|
||||
|
|
77
libraries/shared/src/SimulationEngine.cpp
Normal file
77
libraries/shared/src/SimulationEngine.cpp
Normal 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() {
|
||||
}
|
||||
|
44
libraries/shared/src/SimulationEngine.h
Normal file
44
libraries/shared/src/SimulationEngine.h
Normal 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
|
Loading…
Reference in a new issue