Bullet is now required dependency

This commit is contained in:
Andrew Meadows 2015-01-15 10:27:43 -08:00
parent 8455258fd4
commit ff171a5782
21 changed files with 9 additions and 155 deletions

View file

@ -8,11 +8,6 @@
#
macro(INCLUDE_BULLET)
find_package(Bullet)
if (BULLET_FOUND)
include_directories("${BULLET_INCLUDE_DIRS}")
if (APPLE OR UNIX)
set(CMAKE_CXX_FLAGS "${CMAKE_CXX_FLAGS} -DUSE_BULLET_PHYSICS -isystem ${BULLET_INCLUDE_DIRS}")
endif ()
endif (BULLET_FOUND)
find_package(Bullet REQUIRED)
include_directories("${BULLET_INCLUDE_DIRS}")
endmacro(INCLUDE_BULLET)

View file

@ -189,9 +189,7 @@ Application::Application(int& argc, char** argv, QElapsedTimer &startup_time) :
_frameCount(0),
_fps(60.0f),
_justStarted(true),
#ifdef USE_BULLET_PHYSICS
_physicsEngine(glm::vec3(0.0f)),
#endif // USE_BULLET_PHYSICS
_entities(true, this, this),
_entityCollisionSystem(),
_entityClipboardRenderer(false, this, this),
@ -1726,12 +1724,10 @@ void Application::init() {
// save settings when avatar changes
connect(_myAvatar, &MyAvatar::transformChanged, this, &Application::bumpSettings);
#ifdef USE_BULLET_PHYSICS
EntityTree* tree = _entities.getTree();
_physicsEngine.setEntityTree(tree);
tree->setSimulation(&_physicsEngine);
_physicsEngine.init(&_entityEditSender);
#endif // USE_BULLET_PHYSICS
// make sure our texture cache knows about window size changes
DependencyManager::get<TextureCache>()->associateWithWidget(glCanvas.data());
@ -2042,12 +2038,10 @@ void Application::update(float deltaTime) {
updateDialogs(deltaTime); // update various stats dialogs if present
updateCursor(deltaTime); // Handle cursor updates
#ifdef USE_BULLET_PHYSICS
{
PerformanceTimer perfTimer("physics");
_physicsEngine.stepSimulation();
}
#endif // USE_BULLET_PHYSICS
if (!_aboutToQuit) {
PerformanceTimer perfTimer("entities");
@ -3659,7 +3653,6 @@ void Application::openUrl(const QUrl& url) {
void Application::updateMyAvatarTransform() {
bumpSettings();
#ifdef USE_BULLET_PHYSICS
const float SIMULATION_OFFSET_QUANTIZATION = 16.0f; // meters
glm::vec3 avatarPosition = _myAvatar->getPosition();
glm::vec3 physicsWorldOffset = _physicsEngine.getOriginOffset();
@ -3673,7 +3666,6 @@ void Application::updateMyAvatarTransform() {
// TODO: Andrew to replace this with method that actually moves existing object positions in PhysicsEngine
_physicsEngine.setOriginOffset(newOriginOffset);
}
#endif // USE_BULLET_PHYSICS
}
void Application::domainSettingsReceived(const QJsonObject& domainSettingsObject) {

View file

@ -33,6 +33,7 @@
#include <NodeList.h>
#include <OctreeQuery.h>
#include <PacketHeaders.h>
#include <PhysicsEngine.h>
#include <ScriptEngine.h>
#include <TextureCache.h>
#include <ViewFrustum.h>
@ -454,9 +455,7 @@ private:
bool _justStarted;
Stars _stars;
#ifdef USE_BULLET_PHYSICS
PhysicsEngine _physicsEngine;
#endif // USE_BULLET_PHYSICS
EntityTreeRenderer _entities;
EntityCollisionSystem _entityCollisionSystem;

View file

@ -691,15 +691,7 @@ void EntityItem::simulate(const quint64& now) {
}
}
#ifdef USE_BULLET_PHYSICS
// When Bullet is available we assume that "zero velocity" means "at rest"
// because of collision conditions this simulation does not know about
// so we don't fall in for the non-zero gravity case here.
if (hasVelocity()) {
#else // !USE_BULLET_PHYSICS
if (hasVelocity() || hasGravity()) {
#endif // USE_BULLET_PHYSICS
// linear damping
glm::vec3 velocity = getVelocity();
if (_damping > 0.0f) {
@ -734,12 +726,10 @@ void EntityItem::simulate(const quint64& now) {
if (position.y <= getDistanceToBottomOfEntity()) {
velocity = velocity * glm::vec3(1,-1,1);
#ifndef USE_BULLET_PHYSICS
// if we've slowed considerably, then just stop moving, but only if no BULLET
if (glm::length(velocity) <= ENTITY_ITEM_EPSILON_VELOCITY_LENGTH) {
velocity = ENTITY_ITEM_ZERO_VEC3;
}
#endif // !USE_BULLET_PHYSICS
position.y = getDistanceToBottomOfEntity();
}
@ -756,15 +746,6 @@ void EntityItem::simulate(const quint64& now) {
}
}
#ifdef USE_BULLET_PHYSICS
// When Bullet is available we assume that it will tell us when velocities go to zero...
#else // !USE_BULLET_PHYSICS
// ... otherwise we help things come to rest by clamping small velocities.
if (glm::length(velocity) <= ENTITY_ITEM_EPSILON_VELOCITY_LENGTH) {
velocity = ENTITY_ITEM_ZERO_VEC3;
}
#endif // USE_BULLET_PHYSICS
// NOTE: the simulation should NOT set any DirtyFlags on this entity
setPosition(position); // this will automatically recalculate our collision shape
setVelocity(velocity);
@ -781,13 +762,7 @@ void EntityItem::simulate(const quint64& now) {
}
bool EntityItem::isMoving() const {
#ifdef USE_BULLET_PHYSICS
// When Bullet is available we assume that "zero velocity" means "at rest"
// because of collision conditions this simulation does not know about.
return hasVelocity() || hasAngularVelocity();
#else // !USE_BULLET_PHYSICS
return hasVelocity() || (hasGravity() && !isRestingOnSurface()) || hasAngularVelocity();
#endif //USE_BULLET_PHYSICS
}
bool EntityItem::lifetimeHasExpired() const {

View file

@ -12,8 +12,6 @@
#ifndef hifi_BulletUtil_h
#define hifi_BulletUtil_h
#ifdef USE_BULLET_PHYSICS
#include <btBulletDynamicsCommon.h>
#include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
@ -34,5 +32,4 @@ inline btQuaternion glmToBullet(const glm::quat& g) {
return btQuaternion(g.x, g.y, g.z, g.w);
}
#endif // USE_BULLET_PHYSICS
#endif // hifi_BulletUtil_h

View file

@ -12,9 +12,7 @@
#include <EntityItem.h>
#include <EntityEditPacketSender.h>
#ifdef USE_BULLET_PHYSICS
#include "BulletUtil.h"
#endif // USE_BULLET_PHYSICS
#include "EntityMotionState.h"
QSet<EntityItem*>* _outgoingEntityList;
@ -49,7 +47,6 @@ MotionType EntityMotionState::computeMotionType() const {
return _entity->getCollisionsWillMove() ? MOTION_TYPE_DYNAMIC : MOTION_TYPE_STATIC;
}
#ifdef USE_BULLET_PHYSICS
// This callback is invoked by the physics simulation in two cases:
// (1) when the RigidBody is first added to the world
// (irregardless of MotionType: STATIC, DYNAMIC, or KINEMATIC)
@ -77,10 +74,8 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) {
_outgoingPacketFlags = DIRTY_PHYSICS_FLAGS;
EntityMotionState::enqueueOutgoingEntity(_entity);
}
#endif // USE_BULLET_PHYSICS
void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) {
#ifdef USE_BULLET_PHYSICS
if (flags & (EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY)) {
if (flags & EntityItem::DIRTY_POSITION) {
_sentPosition = _entity->getPositionInMeters() - ObjectMotionState::getWorldOffset();
@ -116,11 +111,9 @@ void EntityMotionState::updateObjectEasy(uint32_t flags, uint32_t frame) {
_body->updateInertiaTensor();
}
_body->activate();
#endif // USE_BULLET_PHYSICS
};
void EntityMotionState::updateObjectVelocities() {
#ifdef USE_BULLET_PHYSICS
if (_body) {
_sentVelocity = _entity->getVelocityInMeters();
setVelocity(_sentVelocity);
@ -134,7 +127,6 @@ void EntityMotionState::updateObjectVelocities() {
_body->setActivationState(ACTIVE_TAG);
}
#endif // USE_BULLET_PHYSICS
}
void EntityMotionState::computeShapeInfo(ShapeInfo& shapeInfo) {
@ -146,7 +138,6 @@ float EntityMotionState::computeMass(const ShapeInfo& shapeInfo) const {
}
void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_t frame) {
#ifdef USE_BULLET_PHYSICS
if (_outgoingPacketFlags) {
EntityItemProperties properties = _entity->getProperties();
@ -213,5 +204,4 @@ void EntityMotionState::sendUpdate(OctreeEditPacketSender* packetSender, uint32_
_outgoingPacketFlags = DIRTY_PHYSICS_FLAGS;
_sentFrame = frame;
}
#endif // USE_BULLET_PHYSICS
}

View file

@ -15,14 +15,6 @@
#include <AACube.h>
#include "ObjectMotionState.h"
#ifndef USE_BULLET_PHYSICS
// ObjectMotionState stubbery
class ObjectMotionState {
public:
// so that this stub implementation is not completely empty we give the class a data member
bool _stubData;
};
#endif // USE_BULLET_PHYSICS
class EntityItem;
@ -45,13 +37,11 @@ public:
/// \return MOTION_TYPE_DYNAMIC or MOTION_TYPE_STATIC based on params set in EntityItem
MotionType computeMotionType() const;
#ifdef USE_BULLET_PHYSICS
// this relays incoming position/rotation to the RigidBody
void getWorldTransform(btTransform& worldTrans) const;
// this relays outgoing position/rotation to the EntityItem
void setWorldTransform(const btTransform& worldTrans);
#endif // USE_BULLET_PHYSICS
// these relay incoming values to the RigidBody
void updateObjectEasy(uint32_t flags, uint32_t frame);

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifdef USE_BULLET_PHYSICS
#include <math.h>
#include "BulletUtil.h"
@ -174,5 +172,3 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame) {
glm::quat actualRotation = bulletToGLM(worldTrans.getRotation());
return (fabsf(glm::dot(actualRotation, _sentRotation)) < MIN_ROTATION_DOT);
}
#endif // USE_BULLET_PHYSICS

View file

@ -12,8 +12,13 @@
#ifndef hifi_ObjectMotionState_h
#define hifi_ObjectMotionState_h
#include <btBulletDynamicsCommon.h>
#include <glm/glm.hpp>
#include <EntityItem.h>
#include "ShapeInfo.h"
enum MotionType {
MOTION_TYPE_STATIC, // no motion
MOTION_TYPE_DYNAMIC, // motion according to physical laws
@ -33,13 +38,6 @@ const uint32_t DIRTY_PHYSICS_FLAGS = HARD_DIRTY_PHYSICS_FLAGS | EASY_DIRTY_PHYSI
// These are the outgoing flags that the PhysicsEngine can affect:
const uint32_t OUTGOING_DIRTY_PHYSICS_FLAGS = EntityItem::DIRTY_POSITION | EntityItem::DIRTY_VELOCITY;
#ifdef USE_BULLET_PHYSICS
#include <btBulletDynamicsCommon.h>
#include <glm/glm.hpp>
#include <EntityItem.h> // for EntityItem::DIRTY_FOO bitmasks
#include "ShapeInfo.h"
class OctreeEditPacketSender;
@ -112,5 +110,4 @@ protected:
glm::vec3 _sentAcceleration;
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_ObjectMotionState_h

View file

@ -10,7 +10,6 @@
//
#include "PhysicsEngine.h"
#ifdef USE_BULLET_PHYSICS
#include "ShapeInfoUtil.h"
#include "ThreadSafeDynamicsWorld.h"
@ -400,5 +399,3 @@ void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motio
body->activate();
}
#endif // USE_BULLET_PHYSICS

View file

@ -14,8 +14,6 @@
typedef unsigned int uint32_t;
#ifdef USE_BULLET_PHYSICS
#include <QSet>
#include <btBulletDynamicsCommon.h>
@ -94,11 +92,7 @@ private:
EntityEditPacketSender* _entityPacketSender;
uint32_t _frameCount;
btScalar _infinity = BT_INFINITY; // HACK: eliminates unused variable warning from Bullet headers
};
#else // USE_BULLET_PHYSICS
// PhysicsEngine stubbery until Bullet is required
class PhysicsEngine {
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_PhysicsEngine_h

View file

@ -21,10 +21,6 @@
#include <CollisionInfo.h>
#include <RayIntersectionInfo.h>
#ifdef USE_BULLET_PHYSICS
#include "PhysicsEngine.h"
#endif // USE_BULLET_PHYSICS
class Shape;
class PhysicsSimulation;

View file

@ -15,9 +15,6 @@
#include "ShapeInfoUtil.h"
#include "BulletUtil.h"
#ifdef USE_BULLET_PHYSICS
int ShapeInfoUtil::toBulletShapeType(int shapeInfoType) {
int bulletShapeType = INVALID_SHAPE_PROXYTYPE;
switch(shapeInfoType) {
@ -168,5 +165,3 @@ DoubleHashKey ShapeInfoUtil::computeHash(const ShapeInfo& info) {
key._hash2 = (int)hash;
return key;
}
#endif // USE_BULLET_PHYSICS

View file

@ -12,8 +12,6 @@
#ifndef hifi_ShapeInfoUtil_h
#define hifi_ShapeInfoUtil_h
#ifdef USE_BULLET_PHYSICS
#include <btBulletDynamicsCommon.h>
#include <glm/glm.hpp>
@ -35,5 +33,4 @@ namespace ShapeInfoUtil {
int fromBulletShapeType(int bulletShapeType);
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_ShapeInfoUtil_h

View file

@ -9,8 +9,6 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
#ifdef USE_BULLET_PHYSICS
#include <glm/gtx/norm.hpp>
#include "ShapeInfoUtil.h"
@ -104,6 +102,3 @@ int ShapeManager::getNumReferences(const ShapeInfo& info) const {
}
return -1;
}
#endif // USE_BULLET_PHYSICS

View file

@ -12,8 +12,6 @@
#ifndef hifi_ShapeManager_h
#define hifi_ShapeManager_h
#ifdef USE_BULLET_PHYSICS
#include <btBulletDynamicsCommon.h>
#include <LinearMath/btHashMap.h>
@ -52,5 +50,4 @@ private:
btAlignedObjectArray<DoubleHashKey> _pendingGarbage;
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_ShapeManager_h

View file

@ -17,7 +17,6 @@
#include "ThreadSafeDynamicsWorld.h"
#ifdef USE_BULLET_PHYSICS
ThreadSafeDynamicsWorld::ThreadSafeDynamicsWorld(
btDispatcher* dispatcher,
btBroadphaseInterface* pairCache,
@ -82,4 +81,3 @@ int ThreadSafeDynamicsWorld::stepSimulation( btScalar timeStep, int maxSubSteps,
return subSteps;
}
#endif // USE_BULLET_PHYSICS

View file

@ -18,7 +18,6 @@
#ifndef hifi_ThreadSafeDynamicsWorld_h
#define hifi_ThreadSafeDynamicsWorld_h
#ifdef USE_BULLET_PHYSICS
#include <BulletDynamics/Dynamics/btDiscreteDynamicsWorld.h>
ATTRIBUTE_ALIGNED16(class) ThreadSafeDynamicsWorld : public btDiscreteDynamicsWorld {
@ -40,13 +39,4 @@ public:
float getLocalTimeAccumulation() const { return m_localTime; }
};
#else // USE_BULLET_PHYSICS
// stubbery for ThreadSafeDynamicsWorld when Bullet not available
class ThreadSafeDynamicsWorld {
public:
ThreadSafeDynamicsWorld() {}
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_ThreadSafeDynamicsWorld_h

View file

@ -16,7 +16,6 @@
#include "BulletUtilTests.h"
#ifdef USE_BULLET_PHYSICS
void BulletUtilTests::fromBulletToGLM() {
btVector3 bV(1.23f, 4.56f, 7.89f);
glm::vec3 gV = bulletToGLM(bV);
@ -101,14 +100,3 @@ void BulletUtilTests::runAllTests() {
fromBulletToGLM();
fromGLMToBullet();
}
#else // USE_BULLET_PHYSICS
void BulletUtilTests::fromBulletToGLM() {
}
void BulletUtilTests::fromGLMToBullet() {
}
void BulletUtilTests::runAllTests() {
}
#endif // USE_BULLET_PHYSICS

View file

@ -11,10 +11,8 @@
#include <iostream>
#ifdef USE_BULLET_PHYSICS
#include <btBulletDynamicsCommon.h>
#include <LinearMath/btHashMap.h>
#endif // USE_BULLET_PHYSICS
#include <DoubleHashKey.h>
#include <ShapeInfo.h>
@ -24,7 +22,6 @@
#include "ShapeInfoTests.h"
void ShapeInfoTests::testHashFunctions() {
#ifdef USE_BULLET_PHYSICS
int maxTests = 10000000;
ShapeInfo info;
btHashMap<btHashInt, int> hashes;
@ -135,11 +132,9 @@ void ShapeInfoTests::testHashFunctions() {
for (int i = 0; i < 32; ++i) {
std::cout << "bit 0x" << std::hex << masks[i] << std::dec << " = " << bits[i] << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeInfoTests::testBoxShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
glm::vec3 halfExtents(1.23f, 4.56f, 7.89f);
info.setBox(halfExtents);
@ -165,11 +160,9 @@ void ShapeInfoTests::testBoxShape() {
}
delete shape;
#endif // USE_BULLET_PHYSICS
}
void ShapeInfoTests::testSphereShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
info.setSphere(radius);
@ -191,11 +184,9 @@ void ShapeInfoTests::testSphereShape() {
}
delete shape;
#endif // USE_BULLET_PHYSICS
}
void ShapeInfoTests::testCylinderShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
float height = 4.56f;
@ -218,11 +209,9 @@ void ShapeInfoTests::testCylinderShape() {
}
delete shape;
#endif // USE_BULLET_PHYSICS
}
void ShapeInfoTests::testCapsuleShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
float height = 4.56f;
@ -245,7 +234,6 @@ void ShapeInfoTests::testCapsuleShape() {
}
delete shape;
#endif // USE_BULLET_PHYSICS
}
void ShapeInfoTests::runAllTests() {

View file

@ -17,7 +17,6 @@
#include "ShapeManagerTests.h"
void ShapeManagerTests::testShapeAccounting() {
#ifdef USE_BULLET_PHYSICS
ShapeManager shapeManager;
ShapeInfo info;
info.setBox(glm::vec3(1.0f, 1.0f, 1.0f));
@ -118,11 +117,9 @@ void ShapeManagerTests::testShapeAccounting() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: expected refcount = 1 for shape but found refcount = " << numReferences << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::addManyShapes() {
#ifdef USE_BULLET_PHYSICS
ShapeManager shapeManager;
int numSizes = 100;
@ -152,11 +149,9 @@ void ShapeManagerTests::addManyShapes() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: expected numShapes = " << numSizes << " but found numShapes = " << numShapes << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::addBoxShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
glm::vec3 halfExtents(1.23f, 4.56f, 7.89f);
info.setBox(halfExtents);
@ -172,11 +167,9 @@ void ShapeManagerTests::addBoxShape() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: Box ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::addSphereShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
info.setSphere(radius);
@ -192,11 +185,9 @@ void ShapeManagerTests::addSphereShape() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: Sphere ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::addCylinderShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
float height = 4.56f;
@ -213,11 +204,9 @@ void ShapeManagerTests::addCylinderShape() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: Cylinder ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::addCapsuleShape() {
#ifdef USE_BULLET_PHYSICS
ShapeInfo info;
float radius = 1.23f;
float height = 4.56f;
@ -234,7 +223,6 @@ void ShapeManagerTests::addCapsuleShape() {
std::cout << __FILE__ << ":" << __LINE__
<< " ERROR: Capsule ShapeInfo --> shape --> ShapeInfo --> shape did not work" << std::endl;
}
#endif // USE_BULLET_PHYSICS
}
void ShapeManagerTests::runAllTests() {