Using pre-computed Model shapes for collisions

...instead of generating collision shapes on the fly
This commit is contained in:
Andrew Meadows 2014-02-27 17:52:35 -08:00
parent 50a5924574
commit b8c1bab4ae
3 changed files with 11 additions and 0 deletions

View file

@ -525,6 +525,10 @@ bool Model::findSphereCollisions(const glm::vec3& sphereCenter, float sphereRadi
}
}
if (ShapeCollider::shapeShape(&sphere, _shapes[i], collisions)) {
CollisionInfo* collision = collisions.getLastCollision();
collision->_type = MODEL_COLLISION;
collision->_data = (void*)(this);
collision->_flags = i;
collided = true;
}
outerContinue: ;

View file

@ -24,6 +24,10 @@ CollisionInfo* CollisionList::getCollision(int index) {
return (index > -1 && index < _size) ? &(_collisions[index]) : NULL;
}
CollisionInfo* CollisionList::getLastCollision() {
return (_size > 0) ? &(_collisions[_size - 1]) : NULL;
}
void CollisionList::clear() {
for (int i = 0; i < _size; ++i) {
// we only clear the important stuff

View file

@ -80,6 +80,9 @@ public:
/// \return pointer to collision by index. NULL if index out of bounds.
CollisionInfo* getCollision(int index);
/// \return pointer to last collision on the list. NULL if list is empty
CollisionInfo* getLastCollision();
/// \return true if list is full
bool isFull() const { return _size == _maxSize; }