mirror of
https://github.com/overte-org/overte.git
synced 2025-08-07 18:30:42 +02:00
Add simulationID to Model Shape and CollisionInfo
This commit is contained in:
parent
5a76a9b4b1
commit
3c51ce76fc
5 changed files with 48 additions and 4 deletions
|
@ -37,6 +37,7 @@ Model::Model(QObject* parent) :
|
|||
_scaleToFit(false),
|
||||
_scaleToFitLargestDimension(0.0f),
|
||||
_scaledToFit(false),
|
||||
_simulationIndex(-1),
|
||||
_snapModelToCenter(false),
|
||||
_snappedToCenter(false),
|
||||
_rootIndex(-1),
|
||||
|
@ -774,6 +775,34 @@ AnimationHandlePointer Model::createAnimationHandle() {
|
|||
return handle;
|
||||
}
|
||||
|
||||
quint8 BITS_FOR_SHAPE_INDEX = 15;
|
||||
int MAX_SIMULATION_ID = 1 << (31 - BITS_FOR_SHAPE_INDEX);
|
||||
|
||||
void Model::setSimulationIndex(int index) {
|
||||
_simulationIndex = index;
|
||||
|
||||
if (_simulationIndex < 0 || _simulationIndex > MAX_SIMULATION_ID) {
|
||||
// clear simulation ID's of all the shapes
|
||||
for (int i = 0; i < _jointShapes.size(); i++) {
|
||||
Shape* shape = _jointShapes[i];
|
||||
if (shape) {
|
||||
shape->setSimulationID(-1);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
// update the simulation ID's of the shapes
|
||||
// upper bits store this Model's index...
|
||||
int shiftedIndex = _simulationIndex << BITS_FOR_SHAPE_INDEX;
|
||||
for (int i = 0; i < _jointShapes.size(); i++) {
|
||||
Shape* shape = _jointShapes[i];
|
||||
if (shape) {
|
||||
// ... lower bits are for the shape's index
|
||||
shape->setSimulationID(shiftedIndex + i);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
void Model::clearShapes() {
|
||||
for (int i = 0; i < _jointShapes.size(); ++i) {
|
||||
delete _jointShapes[i];
|
||||
|
|
|
@ -134,9 +134,10 @@ public:
|
|||
QStringList getJointNames() const;
|
||||
|
||||
AnimationHandlePointer createAnimationHandle();
|
||||
|
||||
|
||||
const QList<AnimationHandlePointer>& getRunningAnimations() const { return _runningAnimations; }
|
||||
|
||||
|
||||
void setSimulationIndex(int index);
|
||||
void clearShapes();
|
||||
void rebuildShapes();
|
||||
void resetShapePositions(); // DEBUG method
|
||||
|
@ -177,6 +178,8 @@ protected:
|
|||
bool _scaleToFit; /// If you set scaleToFit, we will calculate scale based on MeshExtents
|
||||
float _scaleToFitLargestDimension; /// this is the dimension that scale to fit will use
|
||||
bool _scaledToFit; /// have we scaled to fit
|
||||
|
||||
int _simulationIndex; // set by SimulationEngine (if any)
|
||||
|
||||
bool _snapModelToCenter; /// is the model's offset automatically adjusted to center around 0,0,0 in model space
|
||||
bool _snappedToCenter; /// are we currently snapped to center
|
||||
|
|
|
@ -47,6 +47,8 @@ void CollisionList::clear() {
|
|||
//collision._intData = 0;
|
||||
//collision._floatDAta = 0.0f;
|
||||
//collision._vecData = glm::vec3(0.0f);
|
||||
//collision._shapeA = -1;
|
||||
//collision._shapeB = -1;
|
||||
//collision._damping;
|
||||
//collision._elasticity;
|
||||
//collision._contactPoint;
|
||||
|
|
|
@ -33,6 +33,8 @@ public:
|
|||
CollisionInfo()
|
||||
: _data(NULL),
|
||||
_intData(0),
|
||||
_shapeA(-1),
|
||||
_shapeB(-1),
|
||||
_damping(0.f),
|
||||
_elasticity(1.f),
|
||||
_contactPoint(0.f),
|
||||
|
@ -43,6 +45,8 @@ public:
|
|||
CollisionInfo(qint32 type)
|
||||
: _data(NULL),
|
||||
_intData(0),
|
||||
_shapeA(-1),
|
||||
_shapeB(-1),
|
||||
_damping(0.f),
|
||||
_elasticity(1.f),
|
||||
_contactPoint(0.f),
|
||||
|
@ -58,6 +62,9 @@ public:
|
|||
float _floatData;
|
||||
glm::vec3 _vecData;
|
||||
|
||||
int _shapeA; // ID of shapeA in its SimulationEngine
|
||||
int _shapeB; // ID of shapeB in its SimulationEngine
|
||||
|
||||
float _damping; // range [0,1] of friction coeficient
|
||||
float _elasticity; // range [0,1] of energy conservation
|
||||
glm::vec3 _contactPoint; // world-frame point on BodyA that is deepest into BodyB
|
||||
|
|
|
@ -23,11 +23,10 @@ public:
|
|||
SPHERE_SHAPE,
|
||||
CAPSULE_SHAPE,
|
||||
PLANE_SHAPE,
|
||||
BOX_SHAPE,
|
||||
LIST_SHAPE
|
||||
};
|
||||
|
||||
Shape() : _type(UNKNOWN_SHAPE), _boundingRadius(0.f), _position(0.f), _rotation() { }
|
||||
Shape() : _type(UNKNOWN_SHAPE), _simulationID(-1), _boundingRadius(0.f), _position(0.f), _rotation() { }
|
||||
virtual ~Shape() {}
|
||||
|
||||
int getType() const { return _type; }
|
||||
|
@ -38,6 +37,9 @@ public:
|
|||
virtual void setPosition(const glm::vec3& position) { _position = position; }
|
||||
virtual void setRotation(const glm::quat& rotation) { _rotation = rotation; }
|
||||
|
||||
void setSimulationID(int id) { _simulationID = id; }
|
||||
int getSimulationID() const { return _simulationID; }
|
||||
|
||||
protected:
|
||||
// these ctors are protected (used by derived classes only)
|
||||
Shape(Type type) : _type(type), _boundingRadius(0.f), _position(0.f), _rotation() {}
|
||||
|
@ -51,6 +53,7 @@ protected:
|
|||
void setBoundingRadius(float radius) { _boundingRadius = radius; }
|
||||
|
||||
int _type;
|
||||
int _simulationID; // shape's simulation ID in SimulationEngine
|
||||
float _boundingRadius;
|
||||
glm::vec3 _position;
|
||||
glm::quat _rotation;
|
||||
|
|
Loading…
Reference in a new issue