overte-JulianGro/libraries/physics/src/PhysicsEngine.h
2015-01-16 10:34:52 -08:00

106 lines
3.2 KiB
C++

//
// PhysicsEngine.h
// libraries/physcis/src
//
// Created by Andrew Meadows 2014.10.29
// 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_PhysicsEngine_h
#define hifi_PhysicsEngine_h
#include <stdint.h>
const float PHYSICS_ENGINE_FIXED_SUBSTEP = 1.0f / 60.0f;
#ifdef USE_BULLET_PHYSICS
#include <QSet>
#include <btBulletDynamicsCommon.h>
#include <EntityItem.h>
#include <EntitySimulation.h>
#include "BulletUtil.h"
#include "EntityMotionState.h"
#include "ShapeManager.h"
#include "ThreadSafeDynamicsWorld.h"
const float HALF_SIMULATION_EXTENT = 512.0f; // meters
class ObjectMotionState;
class PhysicsEngine : public EntitySimulation {
public:
static uint32_t getFrameCount();
PhysicsEngine(const glm::vec3& offset);
~PhysicsEngine();
// overrides for EntitySimulation
void updateEntitiesInternal(const quint64& now);
void addEntityInternal(EntityItem* entity);
void removeEntityInternal(EntityItem* entity);
void entityChangedInternal(EntityItem* entity);
void sortEntitiesThatMovedInternal();
void clearEntitiesInternal();
virtual void init(EntityEditPacketSender* packetSender);
void stepSimulation();
/// \param offset position of simulation origin in domain-frame
void setOriginOffset(const glm::vec3& offset) { _originOffset = offset; }
/// \return position of simulation origin in domain-frame
const glm::vec3& getOriginOffset() const { return _originOffset; }
/// \param motionState pointer to Object's MotionState
/// \return true if Object added
bool addObject(ObjectMotionState* motionState);
/// \param motionState pointer to Object's MotionState
/// \return true if Object removed
bool removeObject(ObjectMotionState* motionState);
/// process queue of changed from external sources
void relayIncomingChangesToSimulation();
/// \return duration of fixed simulation substep
float getFixedSubStep() const;
protected:
void updateObjectHard(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags);
void updateObjectEasy(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags);
btClock _clock;
btDefaultCollisionConfiguration* _collisionConfig;
btCollisionDispatcher* _collisionDispatcher;
btBroadphaseInterface* _broadphaseFilter;
btSequentialImpulseConstraintSolver* _constraintSolver;
ThreadSafeDynamicsWorld* _dynamicsWorld;
ShapeManager _shapeManager;
private:
glm::vec3 _originOffset;
// EntitySimulation stuff
QSet<EntityMotionState*> _entityMotionStates; // all entities that we track
QSet<ObjectMotionState*> _incomingChanges; // entities with pending physics changes by script or packet
QSet<ObjectMotionState*> _outgoingPackets; // MotionStates with pending changes that need to be sent over wire
EntityEditPacketSender* _entityPacketSender;
};
#else // USE_BULLET_PHYSICS
// PhysicsEngine stubbery until Bullet is required
class PhysicsEngine {
public:
static uint32_t getFrameCount();
};
#endif // USE_BULLET_PHYSICS
#endif // hifi_PhysicsEngine_h