mirror of
https://github.com/overte-org/overte.git
synced 2025-08-06 11:17:32 +02:00
stubbery for EntityMotionState
This commit is contained in:
parent
8e90cca290
commit
1097e7f1f2
5 changed files with 189 additions and 33 deletions
68
libraries/physics/src/EntityMotionState.cpp
Normal file
68
libraries/physics/src/EntityMotionState.cpp
Normal file
|
@ -0,0 +1,68 @@
|
||||||
|
//
|
||||||
|
// EntityMotionState.cpp
|
||||||
|
// libraries/physcis/src
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows 2014.11.05
|
||||||
|
// 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
|
||||||
|
//
|
||||||
|
|
||||||
|
#ifdef USE_BULLET_PHYSICS
|
||||||
|
|
||||||
|
#include "EntityMotionState.h"
|
||||||
|
|
||||||
|
EntityMotionState::EntityMotionState() : _motionType(MOTION_TYPE_STATIC),
|
||||||
|
_inertiaDiagLocal(1.0f, 1.0f, 1.0f), _mass(1.0f),
|
||||||
|
_shape(NULL), _object(NULL) {
|
||||||
|
}
|
||||||
|
|
||||||
|
/*
|
||||||
|
void EntityMotionState::getWorldTransform (btTransform &worldTrans) const {
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityMotionState::setWorldTransform (const btTransform &worldTrans) {
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityMotionState::computeMassProperties() {
|
||||||
|
}
|
||||||
|
|
||||||
|
void EntityMotionState::getShapeInfo(ShapeInfo& info) {
|
||||||
|
}
|
||||||
|
*/
|
||||||
|
|
||||||
|
bool EntityMotionState::makeStatic() {
|
||||||
|
if (_motionType == MOTION_TYPE_STATIC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!_object) {
|
||||||
|
_motionType = MOTION_TYPE_STATIC;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EntityMotionState::makeDynamic() {
|
||||||
|
if (_motionType == MOTION_TYPE_DYNAMIC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!_object) {
|
||||||
|
_motionType = MOTION_TYPE_DYNAMIC;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool EntityMotionState::makeKinematic() {
|
||||||
|
if (_motionType == MOTION_TYPE_KINEMATIC) {
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
if (!_object) {
|
||||||
|
_motionType = MOTION_TYPE_KINEMATIC;
|
||||||
|
return true;
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
#endif // USE_BULLET_PHYSICS
|
57
libraries/physics/src/EntityMotionState.h
Normal file
57
libraries/physics/src/EntityMotionState.h
Normal file
|
@ -0,0 +1,57 @@
|
||||||
|
//
|
||||||
|
// EntityMotionState.h
|
||||||
|
// libraries/physcis/src
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows 2014.11.05
|
||||||
|
// 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_EntityMotionState_h
|
||||||
|
#define hifi_EntityMotionState_h
|
||||||
|
|
||||||
|
#ifdef USE_BULLET_PHYSICS
|
||||||
|
|
||||||
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
|
#include "ShapeInfo.h"
|
||||||
|
#include "UUIDHashKey.h"
|
||||||
|
|
||||||
|
enum MotionType {
|
||||||
|
MOTION_TYPE_STATIC, // no motion
|
||||||
|
MOTION_TYPE_DYNAMIC, // motion according to physical laws
|
||||||
|
MOTION_TYPE_KINEMATIC // keyframed motion
|
||||||
|
};
|
||||||
|
|
||||||
|
class EntityMotionState : public btMotionState {
|
||||||
|
public:
|
||||||
|
EntityMotionState();
|
||||||
|
|
||||||
|
//// these override methods of the btMotionState base class
|
||||||
|
//virtual void getWorldTransform (btTransform &worldTrans) const;
|
||||||
|
//virtual void setWorldTransform (const btTransform &worldTrans);
|
||||||
|
|
||||||
|
virtual void computeMassProperties() = 0;
|
||||||
|
virtual void getShapeInfo(ShapeInfo& info) = 0;
|
||||||
|
|
||||||
|
bool makeStatic();
|
||||||
|
bool makeDynamic();
|
||||||
|
bool makeKinematic();
|
||||||
|
|
||||||
|
MotionType getMotionType() const { return _motionType; }
|
||||||
|
|
||||||
|
private:
|
||||||
|
friend class PhysicsWorld;
|
||||||
|
|
||||||
|
//EntityItem* _entity;
|
||||||
|
MotionType _motionType;
|
||||||
|
btVector3 _inertiaDiagLocal;
|
||||||
|
float _mass;
|
||||||
|
btCollisionShape* _shape;
|
||||||
|
btCollisionObject* _object;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // USE_BULLET_PHYSICS
|
||||||
|
#endif // hifi_EntityMotionState_h
|
|
@ -22,9 +22,6 @@ void PhysicsWorld::init() {
|
||||||
_dynamicsWorld = new btDiscreteDynamicsWorld(_collisionDispatcher, _broadphaseFilter, _constraintSolver, _collisionConfig);
|
_dynamicsWorld = new btDiscreteDynamicsWorld(_collisionDispatcher, _broadphaseFilter, _constraintSolver, _collisionConfig);
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \return true if Voxel added
|
|
||||||
/// \param position the minimum corner of the voxel
|
|
||||||
/// \param scale the length of the voxel side
|
|
||||||
bool PhysicsWorld::addVoxel(const glm::vec3& position, float scale) {
|
bool PhysicsWorld::addVoxel(const glm::vec3& position, float scale) {
|
||||||
glm::vec3 halfExtents = glm::vec3(0.5f * scale);
|
glm::vec3 halfExtents = glm::vec3(0.5f * scale);
|
||||||
glm::vec3 center = position + halfExtents;
|
glm::vec3 center = position + halfExtents;
|
||||||
|
@ -55,9 +52,6 @@ bool PhysicsWorld::addVoxel(const glm::vec3& position, float scale) {
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
/// \return true if Voxel removed
|
|
||||||
/// \param position the minimum corner of the voxel
|
|
||||||
/// \param scale the length of voxel side
|
|
||||||
bool PhysicsWorld::removeVoxel(const glm::vec3& position, float scale) {
|
bool PhysicsWorld::removeVoxel(const glm::vec3& position, float scale) {
|
||||||
glm::vec3 halfExtents = glm::vec3(0.5f * scale);
|
glm::vec3 halfExtents = glm::vec3(0.5f * scale);
|
||||||
glm::vec3 center = position + halfExtents;
|
glm::vec3 center = position + halfExtents;
|
||||||
|
@ -81,3 +75,24 @@ bool PhysicsWorld::removeVoxel(const glm::vec3& position, float scale) {
|
||||||
}
|
}
|
||||||
return false;
|
return false;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
bool PhysicsWorld::addEntity(const QUuid& id, EntityMotionState* motionState) {
|
||||||
|
assert(motionState);
|
||||||
|
UUIDHashKey key(id);
|
||||||
|
EntityMotionState** statePtr = _entities.find(key);
|
||||||
|
if (!statePtr) {
|
||||||
|
// BOOKMARK: Andrew to implement this
|
||||||
|
} else {
|
||||||
|
assert(*statePtr == motionState);
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
||||||
|
bool PhysicsWorld::removeEntity(const QUuid& id) {
|
||||||
|
UUIDHashKey key(id);
|
||||||
|
EntityMotionState** statePtr = _entities.find(key);
|
||||||
|
if (statePtr) {
|
||||||
|
// BOOKMARK: Andrew to implement this
|
||||||
|
}
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
|
|
@ -16,37 +16,13 @@
|
||||||
|
|
||||||
#include <btBulletDynamicsCommon.h>
|
#include <btBulletDynamicsCommon.h>
|
||||||
|
|
||||||
#include "ShapeManager.h"
|
|
||||||
#include "BulletUtil.h"
|
#include "BulletUtil.h"
|
||||||
|
#include "EntityMotionState.h"
|
||||||
#include "PositionHashKey.h"
|
#include "PositionHashKey.h"
|
||||||
|
#include "ShapeManager.h"
|
||||||
|
#include "UUIDHashKey.h"
|
||||||
#include "VoxelObject.h"
|
#include "VoxelObject.h"
|
||||||
|
|
||||||
#ifdef COLLIDABLE
|
|
||||||
enum MotionType {
|
|
||||||
MOTION_TYPE_STATIC,
|
|
||||||
MOTION_TYPE_DYNAMIC,
|
|
||||||
MOTION_TYPE_KINEMATIC
|
|
||||||
};
|
|
||||||
|
|
||||||
class EntityObject {
|
|
||||||
public:
|
|
||||||
EntityObject();
|
|
||||||
|
|
||||||
bool makeStatic();
|
|
||||||
bool makeDynamic();
|
|
||||||
bool makeKinematic();
|
|
||||||
|
|
||||||
MotionType getMotionType() const { return _motionType; }
|
|
||||||
|
|
||||||
private:
|
|
||||||
btCollisionObject* _object;
|
|
||||||
btMotionState* _motionState;
|
|
||||||
MotionType _motionType;
|
|
||||||
btVector3 _inertiaDiagLocal;
|
|
||||||
float _mass;
|
|
||||||
};
|
|
||||||
#endif // COLLIDABLE
|
|
||||||
|
|
||||||
class PhysicsWorld {
|
class PhysicsWorld {
|
||||||
public:
|
public:
|
||||||
|
|
||||||
|
@ -67,6 +43,14 @@ public:
|
||||||
/// \param scale the length of the voxel side
|
/// \param scale the length of the voxel side
|
||||||
bool removeVoxel(const glm::vec3& position, float scale);
|
bool removeVoxel(const glm::vec3& position, float scale);
|
||||||
|
|
||||||
|
/// \return true if Entity added
|
||||||
|
/// \param info information about collision shapes to create
|
||||||
|
bool addEntity(const QUuid& id, EntityMotionState* motionState);
|
||||||
|
|
||||||
|
/// \return true if Entity removed
|
||||||
|
/// \param id UUID of the entity
|
||||||
|
bool removeEntity(const QUuid& id);
|
||||||
|
|
||||||
protected:
|
protected:
|
||||||
btDefaultCollisionConfiguration* _collisionConfig;
|
btDefaultCollisionConfiguration* _collisionConfig;
|
||||||
btCollisionDispatcher* _collisionDispatcher;
|
btCollisionDispatcher* _collisionDispatcher;
|
||||||
|
@ -78,6 +62,7 @@ protected:
|
||||||
|
|
||||||
private:
|
private:
|
||||||
btHashMap<PositionHashKey, VoxelObject> _voxels;
|
btHashMap<PositionHashKey, VoxelObject> _voxels;
|
||||||
|
btHashMap<UUIDHashKey, EntityMotionState*> _entities;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
31
libraries/physics/src/UUIDHashKey.h
Normal file
31
libraries/physics/src/UUIDHashKey.h
Normal file
|
@ -0,0 +1,31 @@
|
||||||
|
//
|
||||||
|
// UUIDHashKey.h
|
||||||
|
// libraries/physcis/src
|
||||||
|
//
|
||||||
|
// Created by Andrew Meadows 2014.11.05
|
||||||
|
// 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_UUIDHashKey_h
|
||||||
|
#define hifi_UUIDHashKey_h
|
||||||
|
|
||||||
|
#include <QUuid>
|
||||||
|
|
||||||
|
class UUIDHashKey {
|
||||||
|
public:
|
||||||
|
UUIDHashKey(const QUuid& id) : _hash(0), _id(id) { _hash = (int)(qHash(id)); }
|
||||||
|
|
||||||
|
bool equals(const UUIDHashKey& other) const {
|
||||||
|
return _hash == other._hash && _id == other._id;
|
||||||
|
}
|
||||||
|
|
||||||
|
unsigned int getHash() const { return (unsigned int)_hash; }
|
||||||
|
protected:
|
||||||
|
int _hash;
|
||||||
|
QUuid _id;
|
||||||
|
};
|
||||||
|
|
||||||
|
#endif // hifi_UUIDHashKey_h
|
Loading…
Reference in a new issue