From e82b07caf827af3c9c7a975ecc72ced33e319125 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 21 Jan 2015 11:26:08 -0600 Subject: [PATCH 1/7] Updated Windows build instructions --- BUILD_WIN.md | 29 +++++++++++++++++++++++++++++ 1 file changed, 29 insertions(+) diff --git a/BUILD_WIN.md b/BUILD_WIN.md index cf8308c552..883b30b085 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -132,6 +132,35 @@ This package contains only headers, so there's nothing to add to the PATH. Be careful with glm. For the folder other libraries would normally call 'include', the folder containing the headers, glm opts to use 'glm'. You will have a glm folder nested inside the top-level glm folder. +###Bullet + +Bullet 2.82 source can be downloaded [here](https://code.google.com/p/bullet/downloads/detail?name=bullet-2.82-r2704.zip). Bullet does not come with prebuilt libraries, you need to make those yourself. + +* Download the zip file and extract into a temporary folder +* Create a directory named cmakebuild. Bullet comes with a build\ directory by default, however, that directory is intended for use with premake, and considering premake doesn't support VS2013, I prefer to run the cmake build on its own directory. +* Make the following modifications to Bullet's source: + 1. In file: Extras\HACD\hacdICHull.cpp --- in line: 17 --- insert: #include + 2. In file: src\MiniCL\cl_MiniCL_Defs.h --- comment lines 364 to 372 + 3. In file: CMakeLists.txt set to ON the option USE_MSVC_RUNTIME_LIBRARY_DLL in line 27 + +Then create the Visual Studio solution and build the libraries - run the following commands from a Visual Studio 2013 command prompt, from within the cmakebuild directory created before: + +```shell +cmake .. -G "Visual Studio 12" +msbuild BULLET_PHYSICS.sln /p:Configuration=Debug +``` + +This will create Debug libraries in cmakebuild\lib\Debug you can replace Debug with Release in the msbuild command and that will generate Release libraries in cmakebuild\lib\Release. + +You now have Bullet libraries compiled, now you need to put them in the right place for hifi to find them: + +* Create a directory named bullet\ inside your %HIFI_LIB_DIR% +* Create two directores named lib\ and include\ inside bullet\ +* Copy all the contents inside src\ from the bullet unzip path into %HIFI_LIB_DIR%\bullet\include\ +* Copy all the contents inside cmakebuild\lib\ into %HIFI_LIB_DIR\bullet\lib + +*Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo " + ###Build High Fidelity using Visual Studio Follow the same build steps from the CMake section, but pass a different generator to CMake. From 93edd8203875fd0d27544449ecdedeede212c987 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 21 Jan 2015 11:28:50 -0600 Subject: [PATCH 2/7] Markdown fix --- BUILD_WIN.md | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/BUILD_WIN.md b/BUILD_WIN.md index 883b30b085..c12724a88f 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -159,7 +159,7 @@ You now have Bullet libraries compiled, now you need to put them in the right pl * Copy all the contents inside src\ from the bullet unzip path into %HIFI_LIB_DIR%\bullet\include\ * Copy all the contents inside cmakebuild\lib\ into %HIFI_LIB_DIR\bullet\lib -*Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo " +_Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo _ ###Build High Fidelity using Visual Studio Follow the same build steps from the CMake section, but pass a different generator to CMake. From a825f2a4953c51684734e6d778c122c5373d6015 Mon Sep 17 00:00:00 2001 From: Leonardo Murillo Date: Wed, 21 Jan 2015 11:31:24 -0600 Subject: [PATCH 3/7] Markdown fix --- BUILD_WIN.md | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/BUILD_WIN.md b/BUILD_WIN.md index c12724a88f..3ccc4881c1 100644 --- a/BUILD_WIN.md +++ b/BUILD_WIN.md @@ -139,7 +139,7 @@ Bullet 2.82 source can be downloaded [here](https://code.google.com/p/bullet/dow * Download the zip file and extract into a temporary folder * Create a directory named cmakebuild. Bullet comes with a build\ directory by default, however, that directory is intended for use with premake, and considering premake doesn't support VS2013, I prefer to run the cmake build on its own directory. * Make the following modifications to Bullet's source: - 1. In file: Extras\HACD\hacdICHull.cpp --- in line: 17 --- insert: #include + 1. In file: Extras\HACD\hacdICHull.cpp --- in line: 17 --- insert: #include <algorithm> 2. In file: src\MiniCL\cl_MiniCL_Defs.h --- comment lines 364 to 372 3. In file: CMakeLists.txt set to ON the option USE_MSVC_RUNTIME_LIBRARY_DLL in line 27 @@ -159,7 +159,7 @@ You now have Bullet libraries compiled, now you need to put them in the right pl * Copy all the contents inside src\ from the bullet unzip path into %HIFI_LIB_DIR%\bullet\include\ * Copy all the contents inside cmakebuild\lib\ into %HIFI_LIB_DIR\bullet\lib -_Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo _ +_Note that the INSTALL target should handle the copying of files into an install directory automatically, however, without modifications to Cmake, the install target didn't work right for me, please update this instructions if you get that working right - Leo <leo@highfidelity.io>_ ###Build High Fidelity using Visual Studio Follow the same build steps from the CMake section, but pass a different generator to CMake. From 2171427bbdff69e5861c55cdfa822f895b344746 Mon Sep 17 00:00:00 2001 From: Ryan Huffman Date: Wed, 21 Jan 2015 12:31:06 -0800 Subject: [PATCH 4/7] Update style.css to use pt instead of px for proper rendering on hidpi screens --- examples/html/style.css | 66 ++++++++++++++++++++--------------------- 1 file changed, 33 insertions(+), 33 deletions(-) diff --git a/examples/html/style.css b/examples/html/style.css index ad78d0234c..08ca32aba5 100644 --- a/examples/html/style.css +++ b/examples/html/style.css @@ -8,7 +8,7 @@ body { background-color: rgb(76, 76, 76); color: rgb(204, 204, 204); font-family: Arial; - font-size: 11px; + font-size: 8.25pt; -webkit-touch-callout: none; -webkit-user-select: none; @@ -31,25 +31,25 @@ body { .color-box { display: inline-block; - width: 20px; - height: 20px; - border: 1px solid black; - margin: 2px; + width: 15pt; + height: 15pt; + border: 0.75pt solid black; + margin: 1.5pt; cursor: pointer; } .color-box.highlight { - width: 18px; - height: 18px; - border: 2px solid black; + width: 13.5pt; + height: 13.5pt; + border: 1.5pt solid black; } .section-header { background: #AAA; - border-bottom: 1px solid #CCC; + border-bottom: 0.75pt solid #CCC; background-color: #333333; color: #999; - padding: 4px; + padding: 3pt; } .section-header label { @@ -61,7 +61,7 @@ body { .property-section { display: block; margin: 10 10; - height: 30px; + height: 22.5pt; } .property-section label { @@ -73,7 +73,7 @@ body { } .grid-section { - border-top: 1px solid #DDD; + border-top: 0.75pt solid #DDD; background-color: #efefef; } @@ -81,8 +81,8 @@ input[type=button] { cursor: pointer; background-color: #608e96; border-color: #608e96; - border-radius: 5px; - padding: 5px 10px; + border-radius: 3.75pt; + padding: 3.75pt 7.5pt; border: 0; color: #fff; font-weight: bold; @@ -90,8 +90,8 @@ input[type=button] { textarea, input { margin: 0; - padding: 2px; - border: 1px solid #999; + padding: 1.5pt; + border: 0.75pt solid #999; background-color: #eee; } @@ -112,13 +112,13 @@ input.coord { table#entity-table { border-collapse: collapse; font-family: Sans-Serif; - font-size: 10px; + font-size: 7.5pt; width: 100%; } #entity-table tr { cursor: pointer; - border-bottom: 1px solid rgb(63, 63, 63) + border-bottom: 0.75pt solid rgb(63, 63, 63) } #entity-table tr.selected { @@ -128,15 +128,15 @@ table#entity-table { #entity-table th { background-color: #333; color: #fff; - border: 0px black solid; + border: 0pt black solid; text-align: left; word-wrap: nowrap; white-space: nowrap; } #entity-table td { - font-size: 11px; - border: 0px black solid; + font-size: 8.25pt; + border: 0pt black solid; word-wrap: nowrap; white-space: nowrap; text-overflow: ellipsis; @@ -148,21 +148,21 @@ table#entity-table { } th#entity-type { - width: 60px; + width: 33.75pt; } div.input-area { display: inline-block; - font-size: 10px; + font-size: 7.5pt; } input { } #type { - font-size: 14px; + font-size: 10.5pt; } #type label { @@ -173,22 +173,22 @@ input { background-color: rgb(102, 102, 102); color: rgb(204, 204, 204); border: none; - font-size: 10px; + font-size: 7.5pt; } #properties-list input[type=button] { cursor: pointer; background-color: rgb(51, 102, 102); border-color: #608e96; - border-radius: 5px; - padding: 5px 10px; + border-radius: 3.75pt; + padding: 3.75pt 7.5pt; border: 0; color: rgb(204, 204, 204); } #properties-list .property { - padding: 8px 8px; - border-top: 1px solid rgb(63, 63, 63); + padding: 6pt 6pt; + border-top: 0.75pt solid rgb(63, 63, 63); min-height: 1em; } @@ -203,11 +203,11 @@ table#properties-list { } #properties-list > div { - margin: 4px 0; + margin: 3pt 0; } #properties-list { - border-bottom: 1px solid #e5e5e5; + border-bottom: 0.75pt solid #e5e5e5; } #properties-list .label { @@ -221,11 +221,11 @@ table#properties-list { } #properties-list .value > div{ - padding: 4px 0; + padding: 3pt 0; } col#col-label { - width: 130px; + width: 97.5pt; } div.outer { From 2751fab2c360892ac1b629de6d6b68d46b7c0abd Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:02:13 -0800 Subject: [PATCH 5/7] don't send collision events for inactive pairs also throttle collision events to 30/sec --- libraries/physics/src/PhysicsEngine.cpp | 30 ++++++++++++++++++++++--- libraries/physics/src/PhysicsEngine.h | 1 + 2 files changed, 28 insertions(+), 3 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 02304b3b8d..74b792e3c0 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -249,23 +249,47 @@ void PhysicsEngine::stepSimulation() { } void PhysicsEngine::computeCollisionEvents() { - // update all contacts + // update all contacts every frame int numManifolds = _collisionDispatcher->getNumManifolds(); for (int i = 0; i < numManifolds; ++i) { btPersistentManifold* contactManifold = _collisionDispatcher->getManifoldByIndexInternal(i); if (contactManifold->getNumContacts() > 0) { + // TODO: require scripts to register interest in callbacks for specific objects + // so we can filter out most collision events right here. const btCollisionObject* objectA = static_cast(contactManifold->getBody0()); const btCollisionObject* objectB = static_cast(contactManifold->getBody1()); + + if (!(objectA->isActive() || objectB->isActive())) { + // both objects are inactive so stop tracking this contact, + // which will eventually trigger a CONTACT_EVENT_TYPE_END + continue; + } void* a = objectA->getUserPointer(); void* b = objectB->getUserPointer(); if (a || b) { // the manifold has up to 4 distinct points, but only extract info from the first - _contactMap[ContactKey(a, b)].update(_numSubsteps, contactManifold->getContactPoint(0), _originOffset); + _contactMap[ContactKey(a, b)].update(_numContactFrames, contactManifold->getContactPoint(0), _originOffset); } } } + // We harvest collision callbacks every few frames, which contributes the following effects: + // + // (1) There is a maximum collision callback rate per pair: substep_rate / SUBSTEPS_PER_COLLIION_FRAME + // (2) END/START cycles shorter than SUBSTEPS_PER_COLLIION_FRAME will be filtered out + // (3) There is variable lag between when the contact actually starts and when it is reported, + // up to SUBSTEPS_PER_COLLIION_FRAME * time_per_substep + // + const uint32_t SUBSTEPS_PER_COLLISION_FRAME = 2; + if (_numSubsteps - _numContactFrames * SUBSTEPS_PER_COLLISION_FRAME < SUBSTEPS_PER_COLLISION_FRAME) { + // we don't harvest collision callbacks every frame + // this sets a maximum callback-per-contact rate + // and also filters out END/START events that happen on shorter timescales + return; + } + + ++_numContactFrames; // scan known contacts and trigger events ContactMap::iterator contactItr = _contactMap.begin(); while (contactItr != _contactMap.end()) { @@ -289,7 +313,7 @@ void PhysicsEngine::computeCollisionEvents() { } // TODO: enable scripts to filter based on contact event type - ContactEventType type = contactItr->second.computeType(_numSubsteps); + ContactEventType type = contactItr->second.computeType(_numContactFrames); if (type == CONTACT_EVENT_TYPE_END) { ContactMap::iterator iterToDelete = contactItr; ++contactItr; diff --git a/libraries/physics/src/PhysicsEngine.h b/libraries/physics/src/PhysicsEngine.h index 73a02607e8..d333eef010 100644 --- a/libraries/physics/src/PhysicsEngine.h +++ b/libraries/physics/src/PhysicsEngine.h @@ -110,6 +110,7 @@ private: EntityEditPacketSender* _entityPacketSender = NULL; ContactMap _contactMap; + uint32_t _numContactFrames = 0; }; #endif // hifi_PhysicsEngine_h From b2e79a0157ad5786314783acf1ea5be8e0804583 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:06:19 -0800 Subject: [PATCH 6/7] don't process results when no simulation --- libraries/physics/src/PhysicsEngine.cpp | 32 +++++++++++++------------ 1 file changed, 17 insertions(+), 15 deletions(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 74b792e3c0..55920cf315 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -231,21 +231,23 @@ void PhysicsEngine::stepSimulation() { _numSubsteps += (uint32_t)numSubsteps; unlock(); - // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. - // - // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree - // to avoid deadlock -- the _entityTree may try to lock its EntitySimulation (from which this - // PhysicsEngine derives) when updating/adding/deleting entities so we need to wait for our own - // lock on the tree before we re-lock ourselves. - // - // TODO: untangle these lock sequences. - _entityTree->lockForWrite(); - lock(); - _dynamicsWorld->synchronizeMotionStates(); - unlock(); - _entityTree->unlock(); - - computeCollisionEvents(); + if (_numSubsteps > 0) { + // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. + // + // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree + // to avoid deadlock -- the _entityTree may try to lock its EntitySimulation (from which this + // PhysicsEngine derives) when updating/adding/deleting entities so we need to wait for our own + // lock on the tree before we re-lock ourselves. + // + // TODO: untangle these lock sequences. + _entityTree->lockForWrite(); + lock(); + _dynamicsWorld->synchronizeMotionStates(); + unlock(); + _entityTree->unlock(); + + computeCollisionEvents(); + } } void PhysicsEngine::computeCollisionEvents() { From 77c436299135daac4e28a479305cfc012b3928ec Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Wed, 21 Jan 2015 18:14:24 -0800 Subject: [PATCH 7/7] fix typo --- libraries/physics/src/PhysicsEngine.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/libraries/physics/src/PhysicsEngine.cpp b/libraries/physics/src/PhysicsEngine.cpp index 55920cf315..7f2b139058 100644 --- a/libraries/physics/src/PhysicsEngine.cpp +++ b/libraries/physics/src/PhysicsEngine.cpp @@ -231,7 +231,7 @@ void PhysicsEngine::stepSimulation() { _numSubsteps += (uint32_t)numSubsteps; unlock(); - if (_numSubsteps > 0) { + if (numSubsteps > 0) { // This is step (3) which is done outside of stepSimulation() so we can lock _entityTree. // // Unfortunately we have to unlock the simulation (above) before we try to lock the _entityTree