From 1cd93b9ec8508d295a0f4eeaea808dd7e7e88077 Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Tue, 5 May 2015 13:14:22 -0700 Subject: [PATCH] pull andrew's branch, add back in visual indicator of an entity being active in bullet --- libraries/entities-renderer/CMakeLists.txt | 7 +++- .../src/RenderableDebugableEntityItem.cpp | 35 +++++++++++++++++-- .../src/RenderableDebugableEntityItem.h | 1 + libraries/entities/src/EntityItem.cpp | 22 +++++++----- libraries/entities/src/EntityTree.cpp | 3 +- libraries/physics/src/EntityMotionState.cpp | 3 +- libraries/physics/src/PhysicsEngine.cpp | 13 +++++++ libraries/physics/src/PhysicsEngine.h | 2 ++ 8 files changed, 71 insertions(+), 15 deletions(-) diff --git a/libraries/entities-renderer/CMakeLists.txt b/libraries/entities-renderer/CMakeLists.txt index c0880ed15d..6c7fa04a21 100644 --- a/libraries/entities-renderer/CMakeLists.txt +++ b/libraries/entities-renderer/CMakeLists.txt @@ -7,4 +7,9 @@ add_dependency_external_projects(glm) find_package(GLM REQUIRED) target_include_directories(${TARGET_NAME} PUBLIC ${GLM_INCLUDE_DIRS}) -link_hifi_libraries(shared gpu script-engine render-utils) \ No newline at end of file +add_dependency_external_projects(bullet) +find_package(Bullet REQUIRED) +target_include_directories(${TARGET_NAME} SYSTEM PRIVATE ${BULLET_INCLUDE_DIRS}) +target_link_libraries(${TARGET_NAME} ${BULLET_LIBRARIES}) + +link_hifi_libraries(shared gpu script-engine render-utils) diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp index 94b554b96a..0410d78e80 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.cpp @@ -14,6 +14,7 @@ #include #include #include +#include #include "RenderableDebugableEntityItem.h" @@ -23,7 +24,6 @@ void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, Render glm::vec3 center = entity->getCenter(); glm::vec3 dimensions = entity->getDimensions(); glm::quat rotation = entity->getRotation(); - glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); glPushMatrix(); glTranslatef(position.x, position.y, position.z); @@ -34,14 +34,41 @@ void RenderableDebugableEntityItem::renderBoundingBox(EntityItem* entity, Render glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); glScalef(dimensions.x, dimensions.y, dimensions.z); if (puffedOut) { - DependencyManager::get()->renderWireCube(1.2f, greenColor); + glm::vec4 redColor(1.0f, 0.0f, 0.0f, 1.0f); + DependencyManager::get()->renderWireCube(1.2f, redColor); } else { + glm::vec4 greenColor(0.0f, 1.0f, 0.0f, 1.0f); DependencyManager::get()->renderWireCube(1.0f, greenColor); } glPopMatrix(); glPopMatrix(); } +void RenderableDebugableEntityItem::renderHoverDot(EntityItem* entity, RenderArgs* args) { + glm::vec3 position = entity->getPosition(); + glm::vec3 center = entity->getCenter(); + glm::vec3 dimensions = entity->getDimensions(); + glm::quat rotation = entity->getRotation(); + glm::vec4 blueColor(0.0f, 0.0f, 1.0f, 1.0f); + float radius = 0.05f; + + glPushMatrix(); + glTranslatef(position.x, position.y + dimensions.y + radius, position.z); + glm::vec3 axis = glm::axis(rotation); + glRotatef(glm::degrees(glm::angle(rotation)), axis.x, axis.y, axis.z); + + glPushMatrix(); + glm::vec3 positionToCenter = center - position; + glTranslatef(positionToCenter.x, positionToCenter.y, positionToCenter.z); + + glScalef(radius, radius, radius); + + const int SLICES = 8; + const int STACKS = 8; + DependencyManager::get()->renderSolidSphere(0.5f, SLICES, STACKS, blueColor); + glPopMatrix(); + glPopMatrix(); +} void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) { bool debugSimulationOwnership = args->_debugFlags & RenderArgs::RENDER_DEBUG_SIMULATION_OWNERSHIP; @@ -52,4 +79,8 @@ void RenderableDebugableEntityItem::render(EntityItem* entity, RenderArgs* args) renderBoundingBox(entity, args, true); } } + + if (PhysicsEngine::physicsInfoIsActive(entity->getPhysicsInfo())) { + renderHoverDot(entity, args); + } } diff --git a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h index 9a8344c96d..f3550cb116 100644 --- a/libraries/entities-renderer/src/RenderableDebugableEntityItem.h +++ b/libraries/entities-renderer/src/RenderableDebugableEntityItem.h @@ -17,6 +17,7 @@ class RenderableDebugableEntityItem { public: static void renderBoundingBox(EntityItem* entity, RenderArgs* args, bool puffedOut); + static void renderHoverDot(EntityItem* entity, RenderArgs* args); static void render(EntityItem* entity, RenderArgs* args); }; diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index d2cb6f4626..c5083d5cf8 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -313,10 +313,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates. glm::vec3 savePosition = _position; glm::quat saveRotation = _rotation; - glm::vec3 saveVelocity = _velocity; - glm::vec3 saveAngularVelocity = _angularVelocity; - glm::vec3 saveGravity = _gravity; - glm::vec3 saveAcceleration = _acceleration; + // glm::vec3 saveVelocity = _velocity; + // glm::vec3 saveAngularVelocity = _angularVelocity; + // glm::vec3 saveGravity = _gravity; + // glm::vec3 saveAcceleration = _acceleration; // Header bytes @@ -401,8 +401,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef if (lastEditedFromBufferAdjusted > now) { lastEditedFromBufferAdjusted = now; } - + +#if 0 // XXX bool fromSameServerEdit = (lastEditedFromBuffer == _lastEditedFromRemoteInRemoteTime); +#endif #ifdef WANT_DEBUG qCDebug(entities) << "data from server **************** "; @@ -419,6 +421,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef bool ignoreServerPacket = false; // assume we'll use this server packet +#if 0 // XXX Trying to eliminate this code as a possible source of deviation between interfaces // If this packet is from the same server edit as the last packet we accepted from the server // we probably want to use it. if (fromSameServerEdit) { @@ -435,6 +438,7 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef ignoreServerPacket = true; } } +#endif if (ignoreServerPacket) { overwriteLocalData = false; @@ -618,10 +622,10 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef // this node, so our version has to be newer than what the packet contained. _position = savePosition; _rotation = saveRotation; - _velocity = saveVelocity; - _angularVelocity = saveAngularVelocity; - _gravity = saveGravity; - _acceleration = saveAcceleration; + // _velocity = saveVelocity; + // _angularVelocity = saveAngularVelocity; + // _gravity = saveGravity; + // _acceleration = saveAcceleration; } return bytesRead; diff --git a/libraries/entities/src/EntityTree.cpp b/libraries/entities/src/EntityTree.cpp index c90fa6df87..dbbbbc0cd2 100644 --- a/libraries/entities/src/EntityTree.cpp +++ b/libraries/entities/src/EntityTree.cpp @@ -145,8 +145,7 @@ bool EntityTree::updateEntityWithElement(EntityItem* entity, const EntityItemPro // squash the physics-related changes. properties.setSimulatorIDChanged(false); properties.setPositionChanged(false); - properties.setVelocityChanged(false); - properties.setAccelerationChanged(false); + properties.setRotationChanged(false); } else { qCDebug(entities) << "allowing simulatorID change"; } diff --git a/libraries/physics/src/EntityMotionState.cpp b/libraries/physics/src/EntityMotionState.cpp index 52d0577a6e..dc095590da 100644 --- a/libraries/physics/src/EntityMotionState.cpp +++ b/libraries/physics/src/EntityMotionState.cpp @@ -111,7 +111,8 @@ void EntityMotionState::setWorldTransform(const btTransform& worldTrans) { _movingStepsWithoutSimulationOwner = 0; } - if (_movingStepsWithoutSimulationOwner > 4) { // XXX maybe meters from our characterController ? + if (_movingStepsWithoutSimulationOwner > 100) { // XXX maybe meters from our characterController ? + qDebug() << "XXX XXX XXX -- claiming something I saw moving"; setShouldClaimSimulationOwnership(true); } diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index dca922d0f3..3f699692c6 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -405,3 +405,16 @@ void PhysicsEngine::setCharacterController(DynamicCharacterController* character } } +bool PhysicsEngine::physicsInfoIsActive(void* physicsInfo) { + if (!physicsInfo) { + return false; + } + + ObjectMotionState* motionState = static_cast(physicsInfo); + btRigidBody* body = motionState->getRigidBody(); + if (!body) { + return false; + } + + return body->isActive(); +} diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index a5a1d4ac10..9341bfb855 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -92,6 +92,8 @@ public: void dumpNextStats() { _dumpNextStats = true; } + static bool physicsInfoIsActive(void* physicsInfo); + private: void removeContacts(ObjectMotionState* motionState);