Merge pull request #3679 from AndrewMeadows/inertia

move code out of "shared" and into new "physics" lib
This commit is contained in:
Brad Hefta-Gaub 2014-10-28 15:25:38 -07:00
commit c39c716755
54 changed files with 193 additions and 63 deletions

View file

@ -8,6 +8,7 @@ include_glm()
link_hifi_libraries( link_hifi_libraries(
audio avatars octree voxels fbx entities metavoxels audio avatars octree voxels fbx entities metavoxels
networking animation shared script-engine embedded-webserver networking animation shared script-engine embedded-webserver
physics
) )
if (UNIX) if (UNIX)

View file

@ -101,7 +101,7 @@ endif()
add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM}) add_executable(${TARGET_NAME} MACOSX_BUNDLE ${INTERFACE_SRCS} ${QM})
# link required hifi libraries # 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 any optional and required libraries
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)

View file

@ -655,19 +655,19 @@ void SkeletonModel::buildShapes() {
Shape::Type type = joint.shapeType; Shape::Type type = joint.shapeType;
int parentIndex = joint.parentIndex; int parentIndex = joint.parentIndex;
if (parentIndex == -1 || radius < EPSILON) { if (parentIndex == -1 || radius < EPSILON) {
type = UNKNOWN_SHAPE; type = SHAPE_TYPE_UNKNOWN;
} else if (type == CAPSULE_SHAPE && halfHeight < EPSILON) { } else if (type == SHAPE_TYPE_CAPSULE && halfHeight < EPSILON) {
// this shape is forced to be a sphere // this shape is forced to be a sphere
type = SPHERE_SHAPE; type = SHAPE_TYPE_SPHERE;
} }
Shape* shape = NULL; Shape* shape = NULL;
if (type == SPHERE_SHAPE) { if (type == SHAPE_TYPE_SPHERE) {
shape = new VerletSphereShape(radius, &(points[i])); shape = new VerletSphereShape(radius, &(points[i]));
shape->setEntity(this); shape->setEntity(this);
float mass = massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume()); float mass = massScale * glm::max(MIN_JOINT_MASS, DENSITY_OF_WATER * shape->getVolume());
points[i].setMass(mass); points[i].setMass(mass);
totalMass += mass; totalMass += mass;
} else if (type == CAPSULE_SHAPE) { } else if (type == SHAPE_TYPE_CAPSULE) {
assert(parentIndex != -1); assert(parentIndex != -1);
shape = new VerletCapsuleShape(radius, &(points[parentIndex]), &(points[i])); shape = new VerletCapsuleShape(radius, &(points[parentIndex]), &(points[i]));
shape->setEntity(this); shape->setEntity(this);

View file

@ -5,7 +5,7 @@ setup_hifi_library(Network Script)
include_glm() include_glm()
link_hifi_libraries(shared octree voxels networking) link_hifi_libraries(shared octree voxels networking physics)
include_hifi_library_headers(fbx) include_hifi_library_headers(fbx)
# call macro to link our dependencies and bubble them up via a property on our target # call macro to link our dependencies and bubble them up via a property on our target

View file

@ -5,7 +5,7 @@ setup_hifi_library(Network Script)
include_glm() 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 # call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies() link_shared_dependencies()

View file

@ -18,6 +18,7 @@
#include <AACubeShape.h> #include <AACubeShape.h>
#include <AnimationCache.h> // for Animation, AnimationCache, and AnimationPointer classes #include <AnimationCache.h> // for Animation, AnimationCache, and AnimationPointer classes
#include <CollisionInfo.h>
#include <Octree.h> // for EncodeBitstreamParams class #include <Octree.h> // for EncodeBitstreamParams class
#include <OctreeElement.h> // for OctreeElement::AppendState #include <OctreeElement.h> // for OctreeElement::AppendState
#include <OctreePacketData.h> #include <OctreePacketData.h>

View file

@ -25,7 +25,6 @@
#include <GeometryUtil.h> #include <GeometryUtil.h>
#include <GLMHelpers.h> #include <GLMHelpers.h>
#include <OctalCode.h> #include <OctalCode.h>
#include <Shape.h>
#include <VoxelTree.h> #include <VoxelTree.h>
@ -1534,7 +1533,7 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
joint.inverseBindRotation = joint.inverseDefaultRotation; joint.inverseBindRotation = joint.inverseDefaultRotation;
joint.name = model.name; joint.name = model.name;
joint.shapePosition = glm::vec3(0.f); joint.shapePosition = glm::vec3(0.f);
joint.shapeType = UNKNOWN_SHAPE; joint.shapeType = SHAPE_TYPE_UNKNOWN;
foreach (const QString& childID, childMap.values(modelID)) { foreach (const QString& childID, childMap.values(modelID)) {
QString type = typeFlags.value(childID); QString type = typeFlags.value(childID);
@ -1911,10 +1910,10 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
if (collideLikeCapsule) { if (collideLikeCapsule) {
joint.shapeRotation = rotationBetween(defaultCapsuleAxis, jointShapeInfo.boneBegin); joint.shapeRotation = rotationBetween(defaultCapsuleAxis, jointShapeInfo.boneBegin);
joint.shapePosition = 0.5f * jointShapeInfo.boneBegin; joint.shapePosition = 0.5f * jointShapeInfo.boneBegin;
joint.shapeType = CAPSULE_SHAPE; joint.shapeType = SHAPE_TYPE_CAPSULE;
} else { } else {
// collide the joint like a sphere // collide the joint like a sphere
joint.shapeType = SPHERE_SHAPE; joint.shapeType = SHAPE_TYPE_SPHERE;
if (jointShapeInfo.numVertices > 0) { if (jointShapeInfo.numVertices > 0) {
jointShapeInfo.averageVertex /= (float)jointShapeInfo.numVertices; jointShapeInfo.averageVertex /= (float)jointShapeInfo.numVertices;
joint.shapePosition = jointShapeInfo.averageVertex; joint.shapePosition = jointShapeInfo.averageVertex;
@ -1934,8 +1933,8 @@ FBXGeometry extractFBXGeometry(const FBXNode& node, const QVariantHash& mapping)
if (distanceFromEnd > joint.distanceToParent && distanceFromBegin > joint.distanceToParent) { if (distanceFromEnd > joint.distanceToParent && distanceFromBegin > joint.distanceToParent) {
// The shape is further from both joint endpoints than the endpoints are from each other // 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 // which probably means the model has a bad transform somewhere. We disable this shape
// by setting its type to UNKNOWN_SHAPE. // by setting its type to SHAPE_TYPE_UNKNOWN.
joint.shapeType = UNKNOWN_SHAPE; joint.shapeType = SHAPE_TYPE_UNKNOWN;
} }
} }
} }

View file

@ -19,8 +19,6 @@
#include <QVector> #include <QVector>
#include <Extents.h> #include <Extents.h>
#include <Shape.h>
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp> #include <glm/gtc/quaternion.hpp>
@ -55,6 +53,12 @@ public:
QVector<glm::vec3> normals; QVector<glm::vec3> 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. /// A single joint (transformation node) extracted from an FBX document.
class FBXJoint { class FBXJoint {
public: public:
@ -79,7 +83,7 @@ public:
QString name; QString name;
glm::vec3 shapePosition; // in joint frame glm::vec3 shapePosition; // in joint frame
glm::quat shapeRotation; // in joint frame glm::quat shapeRotation; // in joint frame
Shape::Type shapeType; ShapeType shapeType;
bool isSkeletonJoint; bool isSkeletonJoint;
}; };

View file

@ -5,7 +5,7 @@ setup_hifi_library()
include_glm() include_glm()
link_hifi_libraries(shared networking) link_hifi_libraries(shared networking physics)
# find ZLIB # find ZLIB
find_package(ZLIB REQUIRED) find_package(ZLIB REQUIRED)

View file

@ -31,8 +31,6 @@ class Shape;
#include "OctreePacketData.h" #include "OctreePacketData.h"
#include "OctreeSceneStats.h" #include "OctreeSceneStats.h"
#include <CollisionInfo.h>
#include <QHash> #include <QHash>
#include <QObject> #include <QObject>
#include <QReadWriteLock> #include <QReadWriteLock>

View file

@ -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()

View file

@ -13,7 +13,7 @@
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
#include "AACubeShape.h" #include "AACubeShape.h"
#include "SharedUtil.h" // for SQUARE_ROOT_OF_3 #include <SharedUtil.h> // 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) }; 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) };

View file

@ -12,10 +12,10 @@
#include <iostream> #include <iostream>
#include <glm/gtx/vector_angle.hpp> #include <glm/gtx/vector_angle.hpp>
#include "CapsuleShape.h" #include <GeometryUtil.h>
#include <SharedUtil.h>
#include "GeometryUtil.h" #include "CapsuleShape.h"
#include "SharedUtil.h"
CapsuleShape::CapsuleShape() : Shape(CAPSULE_SHAPE), _radius(0.0f), _halfHeight(0.0f) {} CapsuleShape::CapsuleShape() : Shape(CAPSULE_SHAPE), _radius(0.0f), _halfHeight(0.0f) {}

View file

@ -12,9 +12,9 @@
#ifndef hifi_CapsuleShape_h #ifndef hifi_CapsuleShape_h
#define hifi_CapsuleShape_h #define hifi_CapsuleShape_h
#include "Shape.h" #include <SharedUtil.h>
#include "SharedUtil.h" #include "Shape.h"
// default axis of CapsuleShape is Y-axis // default axis of CapsuleShape is Y-axis
const glm::vec3 DEFAULT_CAPSULE_AXIS(0.0f, 1.0f, 0.0f); const glm::vec3 DEFAULT_CAPSULE_AXIS(0.0f, 1.0f, 0.0f);

View file

@ -9,10 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include "CollisionInfo.h"
#include <SharedUtil.h>
#include "CollisionInfo.h"
#include "Shape.h" #include "Shape.h"
#include "SharedUtil.h"
CollisionInfo::CollisionInfo() : CollisionInfo::CollisionInfo() :
_data(NULL), _data(NULL),

View file

@ -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 <SharedUtil.h>
#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);
}

View file

@ -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 <glm/glm.hpp>
#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

View file

@ -9,9 +9,10 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <SharedUtil.h>
#include "ContactPoint.h" #include "ContactPoint.h"
#include "Shape.h" #include "Shape.h"
#include "SharedUtil.h"
// This parameter helps keep the actual point of contact slightly inside each shape // 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. // which allows the collisions to happen almost every frame for more frequent updates.

View file

@ -9,8 +9,9 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <SharedUtil.h> // for EPSILON
#include "DistanceConstraint.h" #include "DistanceConstraint.h"
#include "SharedUtil.h" // for EPSILON
#include "VerletPoint.h" #include "VerletPoint.h"
DistanceConstraint::DistanceConstraint(VerletPoint* startPoint, VerletPoint* endPoint) : _distance(-1.0f) { DistanceConstraint::DistanceConstraint(VerletPoint* startPoint, VerletPoint* endPoint) : _distance(-1.0f) {

View file

@ -11,14 +11,14 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include "PhysicsSimulation.h" #include <PerfStat.h>
#include <SharedUtil.h>
#include "PerfStat.h" #include "PhysicsSimulation.h"
#include "PhysicsEntity.h" #include "PhysicsEntity.h"
#include "Ragdoll.h" #include "Ragdoll.h"
#include "Shape.h" #include "Shape.h"
#include "ShapeCollider.h" #include "ShapeCollider.h"
#include "SharedUtil.h"
int MAX_DOLLS_PER_SIMULATION = 16; int MAX_DOLLS_PER_SIMULATION = 16;
int MAX_ENTITIES_PER_SIMULATION = 64; int MAX_ENTITIES_PER_SIMULATION = 64;

View file

@ -9,9 +9,10 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <SharedUtil.h>
#include <GLMHelpers.h>
#include "PlaneShape.h" #include "PlaneShape.h"
#include "SharedUtil.h"
#include "GLMHelpers.h"
const glm::vec3 UNROTATED_NORMAL(0.0f, 1.0f, 0.0f); const glm::vec3 UNROTATED_NORMAL(0.0f, 1.0f, 0.0f);

View file

@ -11,13 +11,14 @@
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
#include <SharedUtil.h> // for EPSILON
#include "Ragdoll.h" #include "Ragdoll.h"
#include "Constraint.h" #include "Constraint.h"
#include "DistanceConstraint.h" #include "DistanceConstraint.h"
#include "FixedConstraint.h" #include "FixedConstraint.h"
#include "PhysicsSimulation.h" #include "PhysicsSimulation.h"
#include "SharedUtil.h" // for EPSILON
Ragdoll::Ragdoll() : _massScale(1.0f), _translation(0.0f), _translationInSimulationFrame(0.0f), Ragdoll::Ragdoll() : _massScale(1.0f), _translation(0.0f), _translationInSimulationFrame(0.0f),
_rootIndex(0), _accumulatedMovement(0.0f), _simulation(NULL) { _rootIndex(0), _accumulatedMovement(0.0f), _simulation(NULL) {

View file

@ -14,10 +14,10 @@
#include <glm/glm.hpp> #include <glm/glm.hpp>
#include <glm/gtx/quaternion.hpp> #include <glm/gtx/quaternion.hpp>
#include "VerletPoint.h"
#include <QVector> #include <QVector>
#include "VerletPoint.h"
//#include "PhysicsSimulation.h" //#include "PhysicsSimulation.h"
class DistanceConstraint; class DistanceConstraint;

View file

@ -11,16 +11,17 @@
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
#include <GeometryUtil.h>
#include <StreamUtils.h>
#include "ShapeCollider.h" #include "ShapeCollider.h"
#include "AACubeShape.h" #include "AACubeShape.h"
#include "CapsuleShape.h" #include "CapsuleShape.h"
#include "GeometryUtil.h"
#include "ListShape.h" #include "ListShape.h"
#include "PlaneShape.h" #include "PlaneShape.h"
#include "SphereShape.h" #include "SphereShape.h"
#include "StreamUtils.h"
// NOTE: // NOTE:
// //

View file

@ -14,9 +14,10 @@
#include <QVector> #include <QVector>
#include <SharedUtil.h>
#include "CollisionInfo.h" #include "CollisionInfo.h"
#include "RayIntersectionInfo.h" #include "RayIntersectionInfo.h"
#include "SharedUtil.h"
class Shape; class Shape;
class SphereShape; class SphereShape;

View file

@ -12,9 +12,10 @@
#ifndef hifi_SphereShape_h #ifndef hifi_SphereShape_h
#define hifi_SphereShape_h #define hifi_SphereShape_h
#include <SharedUtil.h>
#include "Shape.h" #include "Shape.h"
#include "SharedUtil.h"
class SphereShape : public Shape { class SphereShape : public Shape {
public: public:

View file

@ -9,10 +9,11 @@
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html // See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
// //
#include <SharedUtil.h>
#include "VerletCapsuleShape.h" #include "VerletCapsuleShape.h"
#include "Ragdoll.h" // for VerletPoint #include "VerletPoint.h"
#include "SharedUtil.h"
VerletCapsuleShape::VerletCapsuleShape(VerletPoint* startPoint, VerletPoint* endPoint) : VerletCapsuleShape::VerletCapsuleShape(VerletPoint* startPoint, VerletPoint* endPoint) :
CapsuleShape(), _startPoint(startPoint), _endPoint(endPoint), _startLagrangeCoef(0.5f), _endLagrangeCoef(0.5f) { CapsuleShape(), _startPoint(startPoint), _endPoint(endPoint), _startLagrangeCoef(0.5f), _endLagrangeCoef(0.5f) {

View file

@ -5,7 +5,7 @@ setup_hifi_library(Gui Network Script Widgets)
include_glm() 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 # call macro to link our dependencies and bubble them up via a property on our target
link_shared_dependencies() link_shared_dependencies()

View file

@ -11,9 +11,8 @@
#include <glm/gtx/norm.hpp> #include <glm/gtx/norm.hpp>
#include "GLMHelpers.h"
#include "AngularConstraint.h" #include "AngularConstraint.h"
#include "GLMHelpers.h"
// helper function // helper function
/// \param angle radian angle to be clamped within angleMin and angleMax /// \param angle radian angle to be clamped within angleMin and angleMax

View file

@ -13,6 +13,8 @@
#include <QUrl> #include <QUrl>
#include <QUuid> #include <QUuid>
#include <glm/gtc/quaternion.hpp>
#include "RegisteredMetaTypes.h" #include "RegisteredMetaTypes.h"
static int vec4MetaTypeId = qRegisterMetaType<glm::vec4>(); static int vec4MetaTypeId = qRegisterMetaType<glm::vec4>();
@ -21,7 +23,7 @@ static int vec2MetaTypeId = qRegisterMetaType<glm::vec2>();
static int quatMetaTypeId = qRegisterMetaType<glm::quat>(); static int quatMetaTypeId = qRegisterMetaType<glm::quat>();
static int xColorMetaTypeId = qRegisterMetaType<xColor>(); static int xColorMetaTypeId = qRegisterMetaType<xColor>();
static int pickRayMetaTypeId = qRegisterMetaType<PickRay>(); static int pickRayMetaTypeId = qRegisterMetaType<PickRay>();
static int collisionMetaTypeId = qRegisterMetaType<CollisionInfo>(); static int collisionMetaTypeId = qRegisterMetaType<Collision>();
void registerMetaTypes(QScriptEngine* engine) { void registerMetaTypes(QScriptEngine* engine) {
qScriptRegisterMetaType(engine, vec4toScriptValue, vec4FromScriptValue); 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(); QScriptValue obj = engine->newObject();
obj.setProperty("penetration", vec3toScriptValue(engine, collision._penetration)); obj.setProperty("penetration", vec3toScriptValue(engine, collision.penetration));
obj.setProperty("contactPoint", vec3toScriptValue(engine, collision._contactPoint)); obj.setProperty("contactPoint", vec3toScriptValue(engine, collision.contactPoint));
return obj; 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 // TODO: implement this when we know what it means to accept collision events from JS
} }

View file

@ -12,11 +12,11 @@
#ifndef hifi_RegisteredMetaTypes_h #ifndef hifi_RegisteredMetaTypes_h
#define hifi_RegisteredMetaTypes_h #define hifi_RegisteredMetaTypes_h
#include <glm/glm.hpp>
#include <QtScript/QScriptEngine> #include <QtScript/QScriptEngine>
#include "CollisionInfo.h" #include <glm/glm.hpp>
#include <glm/gtc/quaternion.hpp>
#include "SharedUtil.h" #include "SharedUtil.h"
class QColor; class QColor;
@ -53,7 +53,7 @@ void qURLFromScriptValue(const QScriptValue& object, QUrl& url);
class PickRay { class PickRay {
public: public:
PickRay() : origin(0), direction(0) { }; PickRay() : origin(0.0f), direction(0.0f) { }
glm::vec3 origin; glm::vec3 origin;
glm::vec3 direction; glm::vec3 direction;
}; };
@ -61,9 +61,15 @@ Q_DECLARE_METATYPE(PickRay)
QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay); QScriptValue pickRayToScriptValue(QScriptEngine* engine, const PickRay& pickRay);
void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay); void pickRayFromScriptValue(const QScriptValue& object, PickRay& pickRay);
Q_DECLARE_METATYPE(CollisionInfo) class Collision {
QScriptValue collisionToScriptValue(QScriptEngine* engine, const CollisionInfo& collision); public:
void collisionFromScriptValue(const QScriptValue &object, CollisionInfo& collision); 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 //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); QScriptValue quuidToScriptValue(QScriptEngine* engine, const QUuid& uuid);

View file

@ -5,6 +5,6 @@ setup_hifi_project(Script Network)
include_glm() include_glm()
# link in the shared libraries # 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() link_shared_dependencies()

View file

@ -5,6 +5,6 @@ setup_hifi_project()
include_glm() include_glm()
# link in the shared libraries # link in the shared libraries
link_hifi_libraries(shared) link_hifi_libraries(shared physics)
link_shared_dependencies() link_shared_dependencies()