diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index f6700455a6..edff3f8291 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -24,7 +24,6 @@ PhysicsEngine::PhysicsEngine(const glm::vec3& offset) _constraintSolver(NULL), _dynamicsWorld(NULL), _originOffset(offset), - _voxels(), _entityPacketSender(NULL), _frameCount(0) { } @@ -221,62 +220,6 @@ void PhysicsEngine::stepSimulation() { _frameCount += (uint32_t)numSubSteps; } -bool PhysicsEngine::addVoxel(const glm::vec3& position, float scale) { - glm::vec3 halfExtents = glm::vec3(0.5f * scale); - glm::vec3 trueCenter = position + halfExtents; - PositionHashKey key(trueCenter); - VoxelObject* proxy = _voxels.find(key); - if (!proxy) { - // create a shape - ShapeInfo info; - info.setBox(halfExtents); - btCollisionShape* shape = _shapeManager.getShape(info); - - // NOTE: the shape creation will fail when the size of the voxel is out of range - if (shape) { - // create a collisionObject - btCollisionObject* object = new btCollisionObject(); - object->setCollisionShape(shape); - btTransform transform; - transform.setIdentity(); - // we shift the center into the simulation's frame - glm::vec3 shiftedCenter = (position - _originOffset) + halfExtents; - transform.setOrigin(btVector3(shiftedCenter.x, shiftedCenter.y, shiftedCenter.z)); - object->setWorldTransform(transform); - - // add to map and world - _voxels.insert(key, VoxelObject(trueCenter, object)); - _dynamicsWorld->addCollisionObject(object); - return true; - } - } - return false; -} - -bool PhysicsEngine::removeVoxel(const glm::vec3& position, float scale) { - glm::vec3 halfExtents = glm::vec3(0.5f * scale); - glm::vec3 trueCenter = position + halfExtents; - PositionHashKey key(trueCenter); - VoxelObject* proxy = _voxels.find(key); - if (proxy) { - // remove from world - assert(proxy->_object); - _dynamicsWorld->removeCollisionObject(proxy->_object); - - // release shape - ShapeInfo info; - info.setBox(halfExtents); - bool released = _shapeManager.releaseShape(info); - assert(released); - - // delete object and remove from voxel map - delete proxy->_object; - _voxels.remove(key); - return true; - } - return false; -} - // Bullet collision flags are as follows: // CF_STATIC_OBJECT= 1, // CF_KINEMATIC_OBJECT= 2, diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 5d506fced6..e93495e1d2 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -24,10 +24,8 @@ typedef unsigned int uint32_t; #include "BulletUtil.h" #include "EntityMotionState.h" -#include "PositionHashKey.h" #include "ShapeManager.h" #include "ThreadSafeDynamicsWorld.h" -#include "VoxelObject.h" const float HALF_SIMULATION_EXTENT = 512.0f; // meters @@ -56,16 +54,6 @@ public: /// \return position of simulation origin in domain-frame const glm::vec3& getOriginOffset() const { return _originOffset; } - /// \param position the minimum corner of the voxel - /// \param scale the length of the voxel side - /// \return true if Voxel added - bool addVoxel(const glm::vec3& position, float scale); - - /// \param position the minimum corner of the voxel - /// \param scale the length of the voxel side - /// \return true if Voxel removed - bool removeVoxel(const glm::vec3& position, float scale); - /// \param motionState pointer to Object's MotionState /// \return true if Object added bool addObject(ObjectMotionState* motionState); @@ -103,7 +91,6 @@ protected: private: glm::vec3 _originOffset; - btHashMap _voxels; // EntitySimulation stuff QSet _entityMotionStates; // all entities that we track diff --git a/libraries/physics/src/PositionHashKey.cpp b/libraries/physics/src/PositionHashKey.cpp deleted file mode 100644 index 91f8261fba..0000000000 --- a/libraries/physics/src/PositionHashKey.cpp +++ /dev/null @@ -1,37 +0,0 @@ -// -// PositionHashKey.cpp -// libraries/physcis/src -// -// Created by Andrew Meadows 2014.11.05 -// 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 - -#include "PositionHashKey.h" - -// static -int computeHash(const glm::vec3& center) { - // NOTE: 0.49f is used to bump the float up almost half a millimeter - // so the cast to int produces a round() effect rather than a floor() - int hash = DoubleHashKey::hashFunction((int)(center.x * MILLIMETERS_PER_METER + copysignf(1.0f, center.x) * 0.49f), 0); - hash ^= DoubleHashKey::hashFunction((int)(center.y * MILLIMETERS_PER_METER + copysignf(1.0f, center.y) * 0.49f), 1); - return hash ^ DoubleHashKey::hashFunction((int)(center.z * MILLIMETERS_PER_METER + copysignf(1.0f, center.z) * 0.49f), 2); -} - -// static -int computeHash2(const glm::vec3& center) { - // NOTE: 0.49f is used to bump the float up almost half a millimeter - // so the cast to int produces a round() effect rather than a floor() - int hash = DoubleHashKey::hashFunction2((int)(center.x * MILLIMETERS_PER_METER + copysignf(1.0f, center.x) * 0.49f)); - hash ^= DoubleHashKey::hashFunction2((int)(center.y * MILLIMETERS_PER_METER + copysignf(1.0f, center.y) * 0.49f)); - return hash ^ DoubleHashKey::hashFunction2((int)(center.z * MILLIMETERS_PER_METER + copysignf(1.0f, center.z) * 0.49f)); -} - -PositionHashKey::PositionHashKey(glm::vec3 center) : DoubleHashKey() { - _hash = computeHash(center); - _hash2 = computeHash2(center); -} diff --git a/libraries/physics/src/PositionHashKey.h b/libraries/physics/src/PositionHashKey.h deleted file mode 100644 index 1065034fa8..0000000000 --- a/libraries/physics/src/PositionHashKey.h +++ /dev/null @@ -1,26 +0,0 @@ -// -// PositionHashKey.h -// libraries/physcis/src -// -// Created by Andrew Meadows 2014.11.05 -// 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_PositionHashKey_h -#define hifi_PositionHashKey_h - -#include - -#include - -#include "DoubleHashKey.h" - -class PositionHashKey : public DoubleHashKey { -public: - PositionHashKey(glm::vec3 center); -}; - -#endif // hifi_PositionHashKey_h diff --git a/libraries/physics/src/VoxelObject.h b/libraries/physics/src/VoxelObject.h deleted file mode 100644 index 1372f761c7..0000000000 --- a/libraries/physics/src/VoxelObject.h +++ /dev/null @@ -1,31 +0,0 @@ -// -// VoxelObject.h -// libraries/physcis/src -// -// Created by Andrew Meadows 2014.11.05 -// 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_VoxelObject_h -#define hifi_VoxelObject_h - -#ifdef USE_BULLET_PHYSICS - -#include -#include - -// VoxelObject is a simple wrapper for tracking a Voxel in a PhysicsEngine -class VoxelObject { -public: - VoxelObject(const glm::vec3& center, btCollisionObject* object) : _object(object), _center(center) { - assert(object != NULL); - } - btCollisionObject* _object; - glm::vec3 _center; -}; - -#endif // USE_BULLET_PHYSICS -#endif // hifi_VoxelObject_h