From 4c3cdf5b7a9df61ca0c3c42815879215379ec2ba Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Tue, 28 Oct 2014 13:51:45 -0700 Subject: [PATCH] move stuff out of shared and into physics library --- assignment-client/CMakeLists.txt | 1 + interface/CMakeLists.txt | 2 +- interface/src/avatar/SkeletonModel.cpp | 10 ++-- libraries/avatars/CMakeLists.txt | 4 +- libraries/entities/CMakeLists.txt | 2 +- libraries/entities/src/EntityItem.h | 1 + libraries/fbx/src/FBXReader.cpp | 11 ++-- libraries/fbx/src/FBXReader.h | 10 ++-- libraries/octree/CMakeLists.txt | 4 +- libraries/octree/src/Octree.h | 2 - libraries/physics/CMakeLists.txt | 19 +++++++ .../{shared => physics}/src/AACubeShape.cpp | 2 +- .../{shared => physics}/src/AACubeShape.h | 0 .../{shared => physics}/src/CapsuleShape.cpp | 6 +-- .../{shared => physics}/src/CapsuleShape.h | 4 +- .../{shared => physics}/src/CollisionInfo.cpp | 5 +- .../{shared => physics}/src/CollisionInfo.h | 0 .../{shared => physics}/src/Constraint.h | 0 libraries/physics/src/ContactConstraint.cpp | 53 +++++++++++++++++++ libraries/physics/src/ContactConstraint.h | 39 ++++++++++++++ .../{shared => physics}/src/ContactPoint.cpp | 3 +- .../{shared => physics}/src/ContactPoint.h | 0 .../src/DistanceConstraint.cpp | 3 +- .../src/DistanceConstraint.h | 0 .../src/FixedConstraint.cpp | 0 .../{shared => physics}/src/FixedConstraint.h | 0 .../{shared => physics}/src/ListShape.cpp | 0 libraries/{shared => physics}/src/ListShape.h | 0 .../{shared => physics}/src/PhysicsEntity.cpp | 0 .../{shared => physics}/src/PhysicsEntity.h | 0 .../src/PhysicsSimulation.cpp | 6 +-- .../src/PhysicsSimulation.h | 0 .../{shared => physics}/src/PlaneShape.cpp | 5 +- .../{shared => physics}/src/PlaneShape.h | 0 libraries/{shared => physics}/src/Ragdoll.cpp | 3 +- libraries/{shared => physics}/src/Ragdoll.h | 2 +- .../src/RayIntersectionInfo.h | 0 libraries/{shared => physics}/src/Shape.h | 0 .../{shared => physics}/src/ShapeCollider.cpp | 5 +- .../{shared => physics}/src/ShapeCollider.h | 3 +- .../{shared => physics}/src/SphereShape.cpp | 0 .../{shared => physics}/src/SphereShape.h | 3 +- .../src/VerletCapsuleShape.cpp | 5 +- .../src/VerletCapsuleShape.h | 0 .../{shared => physics}/src/VerletPoint.cpp | 0 .../{shared => physics}/src/VerletPoint.h | 0 .../src/VerletSphereShape.cpp | 0 .../src/VerletSphereShape.h | 0 libraries/script-engine/CMakeLists.txt | 2 +- libraries/shared/src/AngularConstraint.cpp | 3 +- libraries/shared/src/RegisteredMetaTypes.cpp | 12 +++-- libraries/shared/src/RegisteredMetaTypes.h | 20 ++++--- tests/octree/CMakeLists.txt | 2 +- tests/physics/CMakeLists.txt | 4 +- 54 files changed, 193 insertions(+), 63 deletions(-) create mode 100644 libraries/physics/CMakeLists.txt rename libraries/{shared => physics}/src/AACubeShape.cpp (98%) rename libraries/{shared => physics}/src/AACubeShape.h (100%) rename libraries/{shared => physics}/src/CapsuleShape.cpp (99%) rename libraries/{shared => physics}/src/CapsuleShape.h (98%) rename libraries/{shared => physics}/src/CollisionInfo.cpp (99%) rename libraries/{shared => physics}/src/CollisionInfo.h (100%) rename libraries/{shared => physics}/src/Constraint.h (100%) create mode 100644 libraries/physics/src/ContactConstraint.cpp create mode 100644 libraries/physics/src/ContactConstraint.h rename libraries/{shared => physics}/src/ContactPoint.cpp (99%) rename libraries/{shared => physics}/src/ContactPoint.h (100%) rename libraries/{shared => physics}/src/DistanceConstraint.cpp (97%) rename libraries/{shared => physics}/src/DistanceConstraint.h (100%) rename libraries/{shared => physics}/src/FixedConstraint.cpp (100%) rename libraries/{shared => physics}/src/FixedConstraint.h (100%) rename libraries/{shared => physics}/src/ListShape.cpp (100%) rename libraries/{shared => physics}/src/ListShape.h (100%) rename libraries/{shared => physics}/src/PhysicsEntity.cpp (100%) rename libraries/{shared => physics}/src/PhysicsEntity.h (100%) rename libraries/{shared => physics}/src/PhysicsSimulation.cpp (99%) rename libraries/{shared => physics}/src/PhysicsSimulation.h (100%) rename libraries/{shared => physics}/src/PlaneShape.cpp (98%) rename libraries/{shared => physics}/src/PlaneShape.h (100%) rename libraries/{shared => physics}/src/Ragdoll.cpp (99%) rename libraries/{shared => physics}/src/Ragdoll.h (100%) rename libraries/{shared => physics}/src/RayIntersectionInfo.h (100%) rename libraries/{shared => physics}/src/Shape.h (100%) rename libraries/{shared => physics}/src/ShapeCollider.cpp (99%) rename libraries/{shared => physics}/src/ShapeCollider.h (99%) rename libraries/{shared => physics}/src/SphereShape.cpp (100%) rename libraries/{shared => physics}/src/SphereShape.h (98%) rename libraries/{shared => physics}/src/VerletCapsuleShape.cpp (99%) rename libraries/{shared => physics}/src/VerletCapsuleShape.h (100%) rename libraries/{shared => physics}/src/VerletPoint.cpp (100%) rename libraries/{shared => physics}/src/VerletPoint.h (100%) rename libraries/{shared => physics}/src/VerletSphereShape.cpp (100%) rename libraries/{shared => physics}/src/VerletSphereShape.h (100%) diff --git a/assignment-client/CMakeLists.txt b/assignment-client/CMakeLists.txt index 4f01fce125..69ad1cd815 100644 --- a/assignment-client/CMakeLists.txt +++ b/assignment-client/CMakeLists.txt @@ -8,6 +8,7 @@ include_glm() link_hifi_libraries( audio avatars octree voxels fbx entities metavoxels networking animation shared script-engine embedded-webserver + physics ) if (UNIX) diff --git a/interface/CMakeLists.txt b/interface/CMakeLists.txt index cdd9337210..64093e91ac 100644 --- a/interface/CMakeLists.txt +++ b/interface/CMakeLists.txt @@ -101,7 +101,7 @@ endif() add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) # link required hifi libraries -link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine) +link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine physics) # find any optional and required libraries find_package(ZLIB REQUIRED) diff --git a/interface/src/avatar/SkeletonModel.cpp b/interface/src/avatar/SkeletonModel.cpp index d0f1d75ed6..e760813fe5 100644 --- a/interface/src/avatar/SkeletonModel.cpp +++ b/interface/src/avatar/SkeletonModel.cpp @@ -655,19 +655,19 @@ void SkeletonModel::buildShapes() { Shape::Type type = joint.shapeType; int parentIndex = joint.parentIndex; if (parentIndex == -1 || radius < EPSILON) { - type = UNKNOWN_SHAPE; - } else if (type == CAPSULE_SHAPE && halfHeight < EPSILON) { + type = SHAPE_TYPE_UNKNOWN; + } else if (type == SHAPE_TYPE_CAPSULE && halfHeight < EPSILON) { // this shape is forced to be a sphere - type = SPHERE_SHAPE; + type = SHAPE_TYPE_SPHERE; } Shape* shape = NULL; - if (type == SPHERE_SHAPE) { + if (type == SHAPE_TYPE_SPHERE) { shape = new VerletSphereShape(radius, &(points[i])); shape->setEntity(this); float mass = massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()); points[i].setMass(mass); totalMass += mass; - } else if (type == CAPSULE_SHAPE) { + } else if (type == SHAPE_TYPE_CAPSULE) { assert(parentIndex != -1); shape = new VerletCapsuleShape(radius, &(points[parentIndex]), &(points[i])); shape->setEntity(this); diff --git a/libraries/avatars/CMakeLists.txt b/libraries/avatars/CMakeLists.txt index 1d287ee7a2..42b3cf7d3c 100644 --- a/libraries/avatars/CMakeLists.txt +++ b/libraries/avatars/CMakeLists.txt @@ -5,8 +5,8 @@ setup_hifi_library(Network Script) include_glm() -link_hifi_libraries(shared octree voxels networking) +link_hifi_libraries(shared octree voxels networking physics) include_hifi_library_headers(fbx) # call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +link_shared_dependencies() diff --git a/libraries/entities/CMakeLists.txt b/libraries/entities/CMakeLists.txt index 40d71a032d..e48baa7615 100644 --- a/libraries/entities/CMakeLists.txt +++ b/libraries/entities/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Network Script) include_glm() -link_hifi_libraries(shared octree fbx networking animation) +link_hifi_libraries(shared octree fbx networking animation physics) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index b533db3015..d41bd4a179 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -18,6 +18,7 @@ #include #include // for Animation, AnimationCache, and AnimationPointer classes +#include #include // for EncodeBitstreamParams class #include // for OctreeElement::AppendState #include diff --git a/libraries/fbx/src/FBXReader.cpp b/libraries/fbx/src/FBXReader.cpp index 2a51a83ab8..692aea2d6b 100644 --- a/libraries/fbx/src/FBXReader.cpp +++ b/libraries/fbx/src/FBXReader.cpp @@ -25,7 +25,6 @@ #include #include #include -#include #include @@ -1534,7 +1533,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) joint.inverseBindRotation = joint.inverseDefaultRotation; joint.name = model.name; joint.shapePosition = glm::vec3(0.f); - joint.shapeType = UNKNOWN_SHAPE; + joint.shapeType = SHAPE_TYPE_UNKNOWN; foreach (const QString& childID, childMap.values(modelID)) { QString type = typeFlags.value(childID); @@ -1911,10 +1910,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) if (collideLikeCapsule) { joint.shapeRotation = rotationBetween(defaultCapsuleAxis, jointShapeInfo.boneBegin); joint.shapePosition = 0.5f * jointShapeInfo.boneBegin; - joint.shapeType = CAPSULE_SHAPE; + joint.shapeType = SHAPE_TYPE_CAPSULE; } else { // collide the joint like a sphere - joint.shapeType = SPHERE_SHAPE; + joint.shapeType = SHAPE_TYPE_SPHERE; if (jointShapeInfo.numVertices > 0) { jointShapeInfo.averageVertex /= (float)jointShapeInfo.numVertices; joint.shapePosition = jointShapeInfo.averageVertex; @@ -1934,8 +1933,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping) if (distanceFromEnd > joint.distanceToParent && distanceFromBegin > joint.distanceToParent) { // The shape is further from both joint endpoints than the endpoints are from each other // which probably means the model has a bad transform somewhere. We disable this shape - // by setting its type to UNKNOWN_SHAPE. - joint.shapeType = UNKNOWN_SHAPE; + // by setting its type to SHAPE_TYPE_UNKNOWN. + joint.shapeType = SHAPE_TYPE_UNKNOWN; } } } diff --git a/libraries/fbx/src/FBXReader.h b/libraries/fbx/src/FBXReader.h index 49b0534438..229d51e216 100644 --- a/libraries/fbx/src/FBXReader.h +++ b/libraries/fbx/src/FBXReader.h @@ -19,8 +19,6 @@ #include #include -#include - #include #include @@ -55,6 +53,12 @@ public: QVector normals; }; +enum ShapeType { + SHAPE_TYPE_SPHERE = 0, + SHAPE_TYPE_CAPSULE = 1, + SHAPE_TYPE_UNKNOWN = 2 +}; + /// A single joint (transformation node) extracted from an FBX document. class FBXJoint { public: @@ -79,7 +83,7 @@ public: QString name; glm::vec3 shapePosition; // in joint frame glm::quat shapeRotation; // in joint frame - Shape::Type shapeType; + ShapeType shapeType; bool isSkeletonJoint; }; diff --git a/libraries/octree/CMakeLists.txt b/libraries/octree/CMakeLists.txt index c302a082be..9aea2fdea1 100644 --- a/libraries/octree/CMakeLists.txt +++ b/libraries/octree/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library() include_glm() -link_hifi_libraries(shared networking) +link_hifi_libraries(shared networking physics) # find ZLIB find_package(ZLIB REQUIRED) @@ -16,4 +16,4 @@ include_directories(SYSTEM "${ZLIB_INCLUDE_DIRS}") list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${ZLIB_LIBRARIES}") # call macro to link our dependencies and bubble them up via a property on our target -link_shared_dependencies() \ No newline at end of file +link_shared_dependencies() diff --git a/libraries/octree/src/Octree.h b/libraries/octree/src/Octree.h index e07d2e2688..da0e483e1e 100644 --- a/libraries/octree/src/Octree.h +++ b/libraries/octree/src/Octree.h @@ -31,8 +31,6 @@ class Shape; #include "OctreePacketData.h" #include "OctreeSceneStats.h" -#include - #include #include #include diff --git a/libraries/physics/CMakeLists.txt b/libraries/physics/CMakeLists.txt new file mode 100644 index 0000000000..5270f08730 --- /dev/null +++ b/libraries/physics/CMakeLists.txt @@ -0,0 +1,19 @@ +set(TARGET_NAME physics) + +# use setup_hifi_library macro to setup our project and link appropriate Qt modules +setup_hifi_library() + +include_glm() + +link_hifi_libraries(shared) + +## find BULLET +#find_package(BULLET REQUIRED) +# +#include_directories(SYSTEM "${BULLET_INCLUDE_DIRS}") +# +## append BULLET to our list of libraries to link +#list(APPEND ${TARGET_NAME}_LIBRARIES_TO_LINK "${BULLET_LIBRARIES}") + +# call macro to link our dependencies and bubble them up via a property on our target +link_shared_dependencies() diff --git a/libraries/shared/src/AACubeShape.cpp b/libraries/physics/src/AACubeShape.cpp similarity index 98% rename from libraries/shared/src/AACubeShape.cpp rename to libraries/physics/src/AACubeShape.cpp index 30197d6bfd..fa1a45b809 100644 --- a/libraries/shared/src/AACubeShape.cpp +++ b/libraries/physics/src/AACubeShape.cpp @@ -13,7 +13,7 @@ #include #include "AACubeShape.h" -#include "SharedUtil.h" // for SQUARE_ROOT_OF_3 +#include // for SQUARE_ROOT_OF_3 glm::vec3 faceNormals[3] = { glm::vec3(1.0f, 0.0f, 0.0f), glm::vec3(0.0f, 1.0f, 0.0f), glm::vec3(0.0f, 0.0f, 1.0f) }; diff --git a/libraries/shared/src/AACubeShape.h b/libraries/physics/src/AACubeShape.h similarity index 100% rename from libraries/shared/src/AACubeShape.h rename to libraries/physics/src/AACubeShape.h diff --git a/libraries/shared/src/CapsuleShape.cpp b/libraries/physics/src/CapsuleShape.cpp similarity index 99% rename from libraries/shared/src/CapsuleShape.cpp rename to libraries/physics/src/CapsuleShape.cpp index 5bb118d36e..778798c15b 100644 --- a/libraries/shared/src/CapsuleShape.cpp +++ b/libraries/physics/src/CapsuleShape.cpp @@ -12,10 +12,10 @@ #include #include -#include "CapsuleShape.h" +#include +#include -#include "GeometryUtil.h" -#include "SharedUtil.h" +#include "CapsuleShape.h" CapsuleShape::CapsuleShape() : Shape(CAPSULE_SHAPE), _radius(0.0f), _halfHeight(0.0f) {} diff --git a/libraries/shared/src/CapsuleShape.h b/libraries/physics/src/CapsuleShape.h similarity index 98% rename from libraries/shared/src/CapsuleShape.h rename to libraries/physics/src/CapsuleShape.h index 6e889f6566..ede6993b40 100644 --- a/libraries/shared/src/CapsuleShape.h +++ b/libraries/physics/src/CapsuleShape.h @@ -12,9 +12,9 @@ #ifndef hifi_CapsuleShape_h #define hifi_CapsuleShape_h -#include "Shape.h" +#include -#include "SharedUtil.h" +#include "Shape.h" // default axis of CapsuleShape is Y-axis const glm::vec3 DEFAULT_CAPSULE_AXIS(0.0f, 1.0f, 0.0f); diff --git a/libraries/shared/src/CollisionInfo.cpp b/libraries/physics/src/CollisionInfo.cpp similarity index 99% rename from libraries/shared/src/CollisionInfo.cpp rename to libraries/physics/src/CollisionInfo.cpp index 9dc321fa44..a652f3ce41 100644 --- a/libraries/shared/src/CollisionInfo.cpp +++ b/libraries/physics/src/CollisionInfo.cpp @@ -9,10 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // -#include "CollisionInfo.h" +#include + +#include "CollisionInfo.h" #include "Shape.h" -#include "SharedUtil.h" CollisionInfo::CollisionInfo() : _data(NULL), diff --git a/libraries/shared/src/CollisionInfo.h b/libraries/physics/src/CollisionInfo.h similarity index 100% rename from libraries/shared/src/CollisionInfo.h rename to libraries/physics/src/CollisionInfo.h diff --git a/libraries/shared/src/Constraint.h b/libraries/physics/src/Constraint.h similarity index 100% rename from libraries/shared/src/Constraint.h rename to libraries/physics/src/Constraint.h diff --git a/libraries/physics/src/ContactConstraint.cpp b/libraries/physics/src/ContactConstraint.cpp new file mode 100644 index 0000000000..9d1a92bb21 --- /dev/null +++ b/libraries/physics/src/ContactConstraint.cpp @@ -0,0 +1,53 @@ +// +// ContactConstraint.cpp +// interface/src/avatar +// +// Created by Andrew Meadows 2014.07.24 +// 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 "ContactConstraint.h" +#include "VerletPoint.h" + + +ContactConstraint::ContactConstraint(VerletPoint* pointA, VerletPoint* pointB) + : _pointA(pointA), _pointB(pointB), _strength(1.0f) { + assert(_pointA != NULL && _pointB != NULL); + _offset = _pointB->_position - _pointA->_position; +} + +float ContactConstraint::enforce() { + _pointB->_position += _strength * (_pointA->_position + _offset - _pointB->_position); + return 0.0f; +} + +float ContactConstraint::enforceWithNormal(const glm::vec3& normal) { + glm::vec3 delta = _pointA->_position + _offset - _pointB->_position; + + // split delta into parallel (pDelta) and perpendicular (qDelta) components + glm::vec3 pDelta = glm::dot(delta, normal) * normal; + glm::vec3 qDelta = delta - pDelta; + + // use the relative sizes of the components to decide how much perpenducular delta to use + // (i.e. dynamic friction) + float lpDelta = glm::length(pDelta); + float lqDelta = glm::length(qDelta); + float qFactor = lqDelta > lpDelta ? (lpDelta / lqDelta - 1.0f) : 0.0f; + // recombine the two components to get the final delta + delta = pDelta + qFactor * qDelta; + + // attenuate strength by how much _offset is perpendicular to normal + float distance = glm::length(_offset); + float strength = _strength * ((distance > EPSILON) ? glm::abs(glm::dot(_offset, normal)) / distance : 1.0f); + + // move _pointB + _pointB->_position += strength * delta; + + return strength * glm::length(delta); +} + diff --git a/libraries/physics/src/ContactConstraint.h b/libraries/physics/src/ContactConstraint.h new file mode 100644 index 0000000000..41be2f769d --- /dev/null +++ b/libraries/physics/src/ContactConstraint.h @@ -0,0 +1,39 @@ +// +// ContactConstraint.h +// interface/src/avatar +// +// Created by Andrew Meadows 2014.07.24 +// 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_ContactConstraint_h +#define hifi_ContactConstraint_h + +#include + +#include "Constraint.h" +#include "VerletPoint.h" + +class ContactConstraint : public Constraint { +public: + ContactConstraint(VerletPoint* pointA, VerletPoint* pointB); + + float enforce(); + float enforceWithNormal(const glm::vec3& normal); + + glm::vec3 getTargetPointA() const { return _pointB->_position - _offset; } + + void setOffset(const glm::vec3& offset) { _offset = offset; } + void setStrength(float strength) { _strength = glm::clamp(strength, 0.0f, 1.0f); } + float getStrength() const { return _strength; } +private: + VerletPoint* _pointA; + VerletPoint* _pointB; + glm::vec3 _offset; // from pointA toward pointB + float _strength; // a value in range [0,1] +}; + +#endif // hifi_ContactConstraint_h diff --git a/libraries/shared/src/ContactPoint.cpp b/libraries/physics/src/ContactPoint.cpp similarity index 99% rename from libraries/shared/src/ContactPoint.cpp rename to libraries/physics/src/ContactPoint.cpp index 02cf896594..b9ad87aa8f 100644 --- a/libraries/shared/src/ContactPoint.cpp +++ b/libraries/physics/src/ContactPoint.cpp @@ -9,9 +9,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "ContactPoint.h" #include "Shape.h" -#include "SharedUtil.h" // This parameter helps keep the actual point of contact slightly inside each shape // which allows the collisions to happen almost every frame for more frequent updates. diff --git a/libraries/shared/src/ContactPoint.h b/libraries/physics/src/ContactPoint.h similarity index 100% rename from libraries/shared/src/ContactPoint.h rename to libraries/physics/src/ContactPoint.h diff --git a/libraries/shared/src/DistanceConstraint.cpp b/libraries/physics/src/DistanceConstraint.cpp similarity index 97% rename from libraries/shared/src/DistanceConstraint.cpp rename to libraries/physics/src/DistanceConstraint.cpp index 50fa09d307..94dbfeba24 100644 --- a/libraries/shared/src/DistanceConstraint.cpp +++ b/libraries/physics/src/DistanceConstraint.cpp @@ -9,8 +9,9 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include // for EPSILON + #include "DistanceConstraint.h" -#include "SharedUtil.h" // for EPSILON #include "VerletPoint.h" DistanceConstraint::DistanceConstraint(VerletPoint* startPoint, VerletPoint* endPoint) : _distance(-1.0f) { diff --git a/libraries/shared/src/DistanceConstraint.h b/libraries/physics/src/DistanceConstraint.h similarity index 100% rename from libraries/shared/src/DistanceConstraint.h rename to libraries/physics/src/DistanceConstraint.h diff --git a/libraries/shared/src/FixedConstraint.cpp b/libraries/physics/src/FixedConstraint.cpp similarity index 100% rename from libraries/shared/src/FixedConstraint.cpp rename to libraries/physics/src/FixedConstraint.cpp diff --git a/libraries/shared/src/FixedConstraint.h b/libraries/physics/src/FixedConstraint.h similarity index 100% rename from libraries/shared/src/FixedConstraint.h rename to libraries/physics/src/FixedConstraint.h diff --git a/libraries/shared/src/ListShape.cpp b/libraries/physics/src/ListShape.cpp similarity index 100% rename from libraries/shared/src/ListShape.cpp rename to libraries/physics/src/ListShape.cpp diff --git a/libraries/shared/src/ListShape.h b/libraries/physics/src/ListShape.h similarity index 100% rename from libraries/shared/src/ListShape.h rename to libraries/physics/src/ListShape.h diff --git a/libraries/shared/src/PhysicsEntity.cpp b/libraries/physics/src/PhysicsEntity.cpp similarity index 100% rename from libraries/shared/src/PhysicsEntity.cpp rename to libraries/physics/src/PhysicsEntity.cpp diff --git a/libraries/shared/src/PhysicsEntity.h b/libraries/physics/src/PhysicsEntity.h similarity index 100% rename from libraries/shared/src/PhysicsEntity.h rename to libraries/physics/src/PhysicsEntity.h diff --git a/libraries/shared/src/PhysicsSimulation.cpp b/libraries/physics/src/PhysicsSimulation.cpp similarity index 99% rename from libraries/shared/src/PhysicsSimulation.cpp rename to libraries/physics/src/PhysicsSimulation.cpp index ee5ea9b2b8..72a1eeebfd 100644 --- a/libraries/shared/src/PhysicsSimulation.cpp +++ b/libraries/physics/src/PhysicsSimulation.cpp @@ -11,14 +11,14 @@ #include -#include "PhysicsSimulation.h" +#include +#include -#include "PerfStat.h" +#include "PhysicsSimulation.h" #include "PhysicsEntity.h" #include "Ragdoll.h" #include "Shape.h" #include "ShapeCollider.h" -#include "SharedUtil.h" int MAX_DOLLS_PER_SIMULATION = 16; int MAX_ENTITIES_PER_SIMULATION = 64; diff --git a/libraries/shared/src/PhysicsSimulation.h b/libraries/physics/src/PhysicsSimulation.h similarity index 100% rename from libraries/shared/src/PhysicsSimulation.h rename to libraries/physics/src/PhysicsSimulation.h diff --git a/libraries/shared/src/PlaneShape.cpp b/libraries/physics/src/PlaneShape.cpp similarity index 98% rename from libraries/shared/src/PlaneShape.cpp rename to libraries/physics/src/PlaneShape.cpp index 845b58728a..1a4122f3aa 100644 --- a/libraries/shared/src/PlaneShape.cpp +++ b/libraries/physics/src/PlaneShape.cpp @@ -9,9 +9,10 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include +#include + #include "PlaneShape.h" -#include "SharedUtil.h" -#include "GLMHelpers.h" const glm::vec3 UNROTATED_NORMAL(0.0f, 1.0f, 0.0f); diff --git a/libraries/shared/src/PlaneShape.h b/libraries/physics/src/PlaneShape.h similarity index 100% rename from libraries/shared/src/PlaneShape.h rename to libraries/physics/src/PlaneShape.h diff --git a/libraries/shared/src/Ragdoll.cpp b/libraries/physics/src/Ragdoll.cpp similarity index 99% rename from libraries/shared/src/Ragdoll.cpp rename to libraries/physics/src/Ragdoll.cpp index c0f0eb4b27..3eecef2333 100644 --- a/libraries/shared/src/Ragdoll.cpp +++ b/libraries/physics/src/Ragdoll.cpp @@ -11,13 +11,14 @@ #include +#include // for EPSILON + #include "Ragdoll.h" #include "Constraint.h" #include "DistanceConstraint.h" #include "FixedConstraint.h" #include "PhysicsSimulation.h" -#include "SharedUtil.h" // for EPSILON Ragdoll::Ragdoll() : _massScale(1.0f), _translation(0.0f), _translationInSimulationFrame(0.0f), _rootIndex(0), _accumulatedMovement(0.0f), _simulation(NULL) { diff --git a/libraries/shared/src/Ragdoll.h b/libraries/physics/src/Ragdoll.h similarity index 100% rename from libraries/shared/src/Ragdoll.h rename to libraries/physics/src/Ragdoll.h index 5234397833..5447b6769e 100644 --- a/libraries/shared/src/Ragdoll.h +++ b/libraries/physics/src/Ragdoll.h @@ -14,10 +14,10 @@ #include #include -#include "VerletPoint.h" #include +#include "VerletPoint.h" //#include "PhysicsSimulation.h" class DistanceConstraint; diff --git a/libraries/shared/src/RayIntersectionInfo.h b/libraries/physics/src/RayIntersectionInfo.h similarity index 100% rename from libraries/shared/src/RayIntersectionInfo.h rename to libraries/physics/src/RayIntersectionInfo.h diff --git a/libraries/shared/src/Shape.h b/libraries/physics/src/Shape.h similarity index 100% rename from libraries/shared/src/Shape.h rename to libraries/physics/src/Shape.h diff --git a/libraries/shared/src/ShapeCollider.cpp b/libraries/physics/src/ShapeCollider.cpp similarity index 99% rename from libraries/shared/src/ShapeCollider.cpp rename to libraries/physics/src/ShapeCollider.cpp index 3f79fa081a..2f8ea88553 100644 --- a/libraries/shared/src/ShapeCollider.cpp +++ b/libraries/physics/src/ShapeCollider.cpp @@ -11,16 +11,17 @@ #include +#include +#include + #include "ShapeCollider.h" #include "AACubeShape.h" #include "CapsuleShape.h" -#include "GeometryUtil.h" #include "ListShape.h" #include "PlaneShape.h" #include "SphereShape.h" -#include "StreamUtils.h" // NOTE: // diff --git a/libraries/shared/src/ShapeCollider.h b/libraries/physics/src/ShapeCollider.h similarity index 99% rename from libraries/shared/src/ShapeCollider.h rename to libraries/physics/src/ShapeCollider.h index 618a5ba115..7414665ca7 100644 --- a/libraries/shared/src/ShapeCollider.h +++ b/libraries/physics/src/ShapeCollider.h @@ -14,9 +14,10 @@ #include +#include + #include "CollisionInfo.h" #include "RayIntersectionInfo.h" -#include "SharedUtil.h" class Shape; class SphereShape; diff --git a/libraries/shared/src/SphereShape.cpp b/libraries/physics/src/SphereShape.cpp similarity index 100% rename from libraries/shared/src/SphereShape.cpp rename to libraries/physics/src/SphereShape.cpp diff --git a/libraries/shared/src/SphereShape.h b/libraries/physics/src/SphereShape.h similarity index 98% rename from libraries/shared/src/SphereShape.h rename to libraries/physics/src/SphereShape.h index 59a53c97d6..72f46c1168 100644 --- a/libraries/shared/src/SphereShape.h +++ b/libraries/physics/src/SphereShape.h @@ -12,9 +12,10 @@ #ifndef hifi_SphereShape_h #define hifi_SphereShape_h +#include + #include "Shape.h" -#include "SharedUtil.h" class SphereShape : public Shape { public: diff --git a/libraries/shared/src/VerletCapsuleShape.cpp b/libraries/physics/src/VerletCapsuleShape.cpp similarity index 99% rename from libraries/shared/src/VerletCapsuleShape.cpp rename to libraries/physics/src/VerletCapsuleShape.cpp index ce324a781a..78e3f6763b 100644 --- a/libraries/shared/src/VerletCapsuleShape.cpp +++ b/libraries/physics/src/VerletCapsuleShape.cpp @@ -9,10 +9,11 @@ // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // +#include + #include "VerletCapsuleShape.h" -#include "Ragdoll.h" // for VerletPoint -#include "SharedUtil.h" +#include "VerletPoint.h" VerletCapsuleShape::VerletCapsuleShape(VerletPoint* startPoint, VerletPoint* endPoint) : CapsuleShape(), _startPoint(startPoint), _endPoint(endPoint), _startLagrangeCoef(0.5f), _endLagrangeCoef(0.5f) { diff --git a/libraries/shared/src/VerletCapsuleShape.h b/libraries/physics/src/VerletCapsuleShape.h similarity index 100% rename from libraries/shared/src/VerletCapsuleShape.h rename to libraries/physics/src/VerletCapsuleShape.h diff --git a/libraries/shared/src/VerletPoint.cpp b/libraries/physics/src/VerletPoint.cpp similarity index 100% rename from libraries/shared/src/VerletPoint.cpp rename to libraries/physics/src/VerletPoint.cpp diff --git a/libraries/shared/src/VerletPoint.h b/libraries/physics/src/VerletPoint.h similarity index 100% rename from libraries/shared/src/VerletPoint.h rename to libraries/physics/src/VerletPoint.h diff --git a/libraries/shared/src/VerletSphereShape.cpp b/libraries/physics/src/VerletSphereShape.cpp similarity index 100% rename from libraries/shared/src/VerletSphereShape.cpp rename to libraries/physics/src/VerletSphereShape.cpp diff --git a/libraries/shared/src/VerletSphereShape.h b/libraries/physics/src/VerletSphereShape.h similarity index 100% rename from libraries/shared/src/VerletSphereShape.h rename to libraries/physics/src/VerletSphereShape.h diff --git a/libraries/script-engine/CMakeLists.txt b/libraries/script-engine/CMakeLists.txt index 166ee8c50e..3b3a63549d 100644 --- a/libraries/script-engine/CMakeLists.txt +++ b/libraries/script-engine/CMakeLists.txt @@ -5,7 +5,7 @@ setup_hifi_library(Gui Network Script Widgets) include_glm() -link_hifi_libraries(shared octree voxels fbx entities animation audio) +link_hifi_libraries(shared octree voxels fbx entities animation audio physics) # call macro to link our dependencies and bubble them up via a property on our target link_shared_dependencies() diff --git a/libraries/shared/src/AngularConstraint.cpp b/libraries/shared/src/AngularConstraint.cpp index b39823ee3b..369885c91d 100644 --- a/libraries/shared/src/AngularConstraint.cpp +++ b/libraries/shared/src/AngularConstraint.cpp @@ -11,9 +11,8 @@ #include -#include "GLMHelpers.h" - #include "AngularConstraint.h" +#include "GLMHelpers.h" // helper function /// \param angle radian angle to be clamped within angleMin and angleMax diff --git a/libraries/shared/src/RegisteredMetaTypes.cpp b/libraries/shared/src/RegisteredMetaTypes.cpp index 7dafde9e43..5867e2ef43 100644 --- a/libraries/shared/src/RegisteredMetaTypes.cpp +++ b/libraries/shared/src/RegisteredMetaTypes.cpp @@ -13,6 +13,8 @@ #include #include +#include + #include "RegisteredMetaTypes.h" static int vec4MetaTypeId = qRegisterMetaType(); @@ -21,7 +23,7 @@ static int vec2MetaTypeId = qRegisterMetaType(); static int quatMetaTypeId = qRegisterMetaType(); static int xColorMetaTypeId = qRegisterMetaType(); static int pickRayMetaTypeId = qRegisterMetaType(); -static int collisionMetaTypeId = qRegisterMetaType(); +static int collisionMetaTypeId = qRegisterMetaType(); void registerMetaTypes(QScriptEngine* engine) { qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue); @@ -163,14 +165,14 @@ void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay) { } } -QScriptValue collisionToScriptValue(QScriptEngine* engine, const CollisionInfo& collision) { +QScriptValue collisionToScriptValue(QScriptEngine* engine, const Collision& collision) { QScriptValue obj = engine->newObject(); - obj.setProperty("penetration", vec3toScriptValue(engine, collision._penetration)); - obj.setProperty("contactPoint", vec3toScriptValue(engine, collision._contactPoint)); + obj.setProperty("penetration", vec3toScriptValue(engine, collision.penetration)); + obj.setProperty("contactPoint", vec3toScriptValue(engine, collision.contactPoint)); return obj; } -void collisionFromScriptValue(const QScriptValue &object, CollisionInfo& collision) { +void collisionFromScriptValue(const QScriptValue &object, Collision& collision) { // TODO: implement this when we know what it means to accept collision events from JS } diff --git a/libraries/shared/src/RegisteredMetaTypes.h b/libraries/shared/src/RegisteredMetaTypes.h index a1c6fdf710..7fe662740a 100644 --- a/libraries/shared/src/RegisteredMetaTypes.h +++ b/libraries/shared/src/RegisteredMetaTypes.h @@ -12,11 +12,11 @@ #ifndef hifi_RegisteredMetaTypes_h #define hifi_RegisteredMetaTypes_h -#include - #include -#include "CollisionInfo.h" +#include +#include + #include "SharedUtil.h" class QColor; @@ -53,7 +53,7 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url); class PickRay { public: - PickRay() : origin(0), direction(0) { }; + PickRay() : origin(0.0f), direction(0.0f) { } glm::vec3 origin; glm::vec3 direction; }; @@ -61,9 +61,15 @@ Q_DECLARE_METATYPE(PickRay) QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay); void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay); -Q_DECLARE_METATYPE(CollisionInfo) -QScriptValue collisionToScriptValue(QScriptEngine* engine, const CollisionInfo& collision); -void collisionFromScriptValue(const QScriptValue &object, CollisionInfo& collision); +class Collision { +public: + Collision() : contactPoint(0.0f), penetration(0.0f) { } + glm::vec3 contactPoint; + glm::vec3 penetration; +}; +Q_DECLARE_METATYPE(Collision) +QScriptValue collisionToScriptValue(QScriptEngine* engine, const Collision& collision); +void collisionFromScriptValue(const QScriptValue &object, Collision& collision); //Q_DECLARE_METATYPE(QUuid) // don't need to do this for QUuid since it's already a meta type QScriptValue quuidToScriptValue(QScriptEngine* engine, const QUuid& uuid); diff --git a/tests/octree/CMakeLists.txt b/tests/octree/CMakeLists.txt index e19a7c87e6..7139d4edb6 100644 --- a/tests/octree/CMakeLists.txt +++ b/tests/octree/CMakeLists.txt @@ -5,6 +5,6 @@ setup_hifi_project(Script Network) include_glm() # link in the shared libraries -link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine) +link_hifi_libraries(shared octree voxels fbx metavoxels networking entities avatars audio animation script-engine physics) link_shared_dependencies() diff --git a/tests/physics/CMakeLists.txt b/tests/physics/CMakeLists.txt index 96aaf48860..d47b979459 100644 --- a/tests/physics/CMakeLists.txt +++ b/tests/physics/CMakeLists.txt @@ -5,6 +5,6 @@ setup_hifi_project() include_glm() # link in the shared libraries -link_hifi_libraries(shared) +link_hifi_libraries(shared physics) -link_shared_dependencies() \ No newline at end of file +link_shared_dependencies()