namechange CustomMotionState to ObjectMotionState

This commit is contained in:
Andrew Meadows 2014-12-03 11:12:04 -08:00
parent 8d49b694cc
commit 3c67400e13
5 changed files with 38 additions and 38 deletions

View file

@ -15,10 +15,10 @@
#include <AACube.h> #include <AACube.h>
#ifdef USE_BULLET_PHYSICS #ifdef USE_BULLET_PHYSICS
#include "CustomMotionState.h" #include "ObjectMotionState.h"
#else // USE_BULLET_PHYSICS #else // USE_BULLET_PHYSICS
// CustomMotionState stubbery // ObjectMotionState stubbery
class CustomMotionState { class ObjectMotionState {
public: public:
bool _foo; bool _foo;
}; };
@ -26,7 +26,7 @@ public:
class EntityItem; class EntityItem;
class EntityMotionState : public CustomMotionState { class EntityMotionState : public ObjectMotionState {
public: public:
static void setWorldOffset(const glm::vec3& offset); static void setWorldOffset(const glm::vec3& offset);
static const glm::vec3& getWorldOffset(); static const glm::vec3& getWorldOffset();

View file

@ -1,5 +1,5 @@
// //
// CustomMotionState.cpp // ObjectMotionState.cpp
// libraries/physcis/src // libraries/physcis/src
// //
// Created by Andrew Meadows 2014.11.05 // Created by Andrew Meadows 2014.11.05
@ -14,7 +14,7 @@
#include <math.h> #include <math.h>
#include "BulletUtil.h" #include "BulletUtil.h"
#include "CustomMotionState.h" #include "ObjectMotionState.h"
const float MIN_DENSITY = 200.0f; const float MIN_DENSITY = 200.0f;
const float DEFAULT_DENSITY = 1000.0f; const float DEFAULT_DENSITY = 1000.0f;
@ -29,7 +29,7 @@ const float MAX_FRICTION = 10.0f;
const float DEFAULT_RESTITUTION = 0.0f; const float DEFAULT_RESTITUTION = 0.0f;
CustomMotionState::CustomMotionState() : ObjectMotionState::ObjectMotionState() :
_density(DEFAULT_DENSITY), _density(DEFAULT_DENSITY),
_volume(DEFAULT_VOLUME), _volume(DEFAULT_VOLUME),
_friction(DEFAULT_FRICTION), _friction(DEFAULT_FRICTION),
@ -39,50 +39,50 @@ CustomMotionState::CustomMotionState() :
_body(NULL) { _body(NULL) {
} }
CustomMotionState::~CustomMotionState() { ObjectMotionState::~ObjectMotionState() {
// NOTE: you MUST remove this MotionState from the world before you call the dtor. // NOTE: you MUST remove this MotionState from the world before you call the dtor.
assert(_body == NULL); assert(_body == NULL);
} }
void CustomMotionState::setDensity(float density) { void ObjectMotionState::setDensity(float density) {
_density = btMax(btMin(fabsf(density), MAX_DENSITY), MIN_DENSITY); _density = btMax(btMin(fabsf(density), MAX_DENSITY), MIN_DENSITY);
} }
void CustomMotionState::setFriction(float friction) { void ObjectMotionState::setFriction(float friction) {
_friction = btMax(btMin(fabsf(friction), MAX_FRICTION), 0.0f); _friction = btMax(btMin(fabsf(friction), MAX_FRICTION), 0.0f);
} }
void CustomMotionState::setRestitution(float restitution) { void ObjectMotionState::setRestitution(float restitution) {
_restitution = btMax(btMin(fabsf(restitution), 1.0f), 0.0f); _restitution = btMax(btMin(fabsf(restitution), 1.0f), 0.0f);
} }
void CustomMotionState::setVolume(float volume) { void ObjectMotionState::setVolume(float volume) {
_volume = btMax(btMin(fabsf(volume), MAX_VOLUME), MIN_VOLUME); _volume = btMax(btMin(fabsf(volume), MAX_VOLUME), MIN_VOLUME);
} }
void CustomMotionState::setVelocity(const glm::vec3& velocity) const { void ObjectMotionState::setVelocity(const glm::vec3& velocity) const {
btVector3 v; btVector3 v;
glmToBullet(velocity, v); glmToBullet(velocity, v);
_body->setLinearVelocity(v); _body->setLinearVelocity(v);
} }
void CustomMotionState::setAngularVelocity(const glm::vec3& velocity) const { void ObjectMotionState::setAngularVelocity(const glm::vec3& velocity) const {
btVector3 v; btVector3 v;
glmToBullet(velocity, v); glmToBullet(velocity, v);
_body->setAngularVelocity(v); _body->setAngularVelocity(v);
} }
void CustomMotionState::setGravity(const glm::vec3& gravity) const { void ObjectMotionState::setGravity(const glm::vec3& gravity) const {
btVector3 g; btVector3 g;
glmToBullet(gravity, g); glmToBullet(gravity, g);
_body->setGravity(g); _body->setGravity(g);
} }
void CustomMotionState::getVelocity(glm::vec3& velocityOut) const { void ObjectMotionState::getVelocity(glm::vec3& velocityOut) const {
bulletToGLM(_body->getLinearVelocity(), velocityOut); bulletToGLM(_body->getLinearVelocity(), velocityOut);
} }
void CustomMotionState::getAngularVelocity(glm::vec3& angularVelocityOut) const { void ObjectMotionState::getAngularVelocity(glm::vec3& angularVelocityOut) const {
bulletToGLM(_body->getAngularVelocity(), angularVelocityOut); bulletToGLM(_body->getAngularVelocity(), angularVelocityOut);
} }

View file

@ -1,5 +1,5 @@
// //
// CustomMotionState.h // ObjectMotionState.h
// libraries/physcis/src // libraries/physcis/src
// //
// Created by Andrew Meadows 2014.11.05 // Created by Andrew Meadows 2014.11.05
@ -9,8 +9,8 @@
// 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
// //
#ifndef hifi_CustomMotionState_h #ifndef hifi_ObjectMotionState_h
#define hifi_CustomMotionState_h #define hifi_ObjectMotionState_h
#ifdef USE_BULLET_PHYSICS #ifdef USE_BULLET_PHYSICS
@ -25,10 +25,10 @@ enum MotionType {
MOTION_TYPE_KINEMATIC // keyframed motion MOTION_TYPE_KINEMATIC // keyframed motion
}; };
class CustomMotionState : public btMotionState { class ObjectMotionState : public btMotionState {
public: public:
CustomMotionState(); ObjectMotionState();
~CustomMotionState(); ~ObjectMotionState();
//// these override methods of the btMotionState base class //// these override methods of the btMotionState base class
//virtual void getWorldTransform (btTransform &worldTrans) const; //virtual void getWorldTransform (btTransform &worldTrans) const;
@ -70,4 +70,4 @@ protected:
}; };
#endif // USE_BULLET_PHYSICS #endif // USE_BULLET_PHYSICS
#endif // hifi_CustomMotionState_h #endif // hifi_ObjectMotionState_h

View file

@ -46,7 +46,7 @@ void PhysicsEngine::updateEntities(QSet<EntityItem*>& entitiesToDelete) {
EntityItem* entity = *item_itr; EntityItem* entity = *item_itr;
void* physicsInfo = entity->getPhysicsInfo(); void* physicsInfo = entity->getPhysicsInfo();
if (physicsInfo) { if (physicsInfo) {
CustomMotionState* motionState = static_cast<CustomMotionState*>(physicsInfo); ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
updateObject(motionState, entity->getUpdateFlags()); updateObject(motionState, entity->getUpdateFlags());
} }
entity->clearUpdateFlags(); entity->clearUpdateFlags();
@ -103,7 +103,7 @@ void PhysicsEngine::removeEntity(EntityItem* entity) {
assert(entity); assert(entity);
void* physicsInfo = entity->getPhysicsInfo(); void* physicsInfo = entity->getPhysicsInfo();
if (physicsInfo) { if (physicsInfo) {
CustomMotionState* motionState = static_cast<CustomMotionState*>(physicsInfo); ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
removeObject(motionState); removeObject(motionState);
entity->setPhysicsInfo(NULL); entity->setPhysicsInfo(NULL);
} }
@ -122,7 +122,7 @@ void PhysicsEngine::clearEntities() {
for (entityItr = _entities.begin(); entityItr != _entities.end(); ++entityItr) { for (entityItr = _entities.begin(); entityItr != _entities.end(); ++entityItr) {
void* physicsInfo = (*entityItr)->getPhysicsInfo(); void* physicsInfo = (*entityItr)->getPhysicsInfo();
if (physicsInfo) { if (physicsInfo) {
CustomMotionState* motionState = static_cast<CustomMotionState*>(physicsInfo); ObjectMotionState* motionState = static_cast<ObjectMotionState*>(physicsInfo);
removeObject(motionState); removeObject(motionState);
} }
} }
@ -242,7 +242,7 @@ bool PhysicsEngine::removeVoxel(const glm::vec3& position, float scale) {
// CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing // CF_DISABLE_VISUALIZE_OBJECT = 32, //disable debug drawing
// CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing // CF_DISABLE_SPU_COLLISION_PROCESSING = 64//disable parallel/SPU processing
bool PhysicsEngine::addObject(CustomMotionState* motionState) { bool PhysicsEngine::addObject(ObjectMotionState* motionState) {
assert(motionState); assert(motionState);
ShapeInfo info; ShapeInfo info;
motionState->computeShapeInfo(info); motionState->computeShapeInfo(info);
@ -289,7 +289,7 @@ bool PhysicsEngine::addObject(CustomMotionState* motionState) {
return false; return false;
} }
bool PhysicsEngine::removeObject(CustomMotionState* motionState) { bool PhysicsEngine::removeObject(ObjectMotionState* motionState) {
assert(motionState); assert(motionState);
btRigidBody* body = motionState->_body; btRigidBody* body = motionState->_body;
if (body) { if (body) {
@ -305,7 +305,7 @@ bool PhysicsEngine::removeObject(CustomMotionState* motionState) {
return false; return false;
} }
bool PhysicsEngine::updateObject(CustomMotionState* motionState, uint32_t flags) { bool PhysicsEngine::updateObject(ObjectMotionState* motionState, uint32_t flags) {
btRigidBody* body = motionState->_body; btRigidBody* body = motionState->_body;
if (!body) { if (!body) {
return false; return false;
@ -322,7 +322,7 @@ bool PhysicsEngine::updateObject(CustomMotionState* motionState, uint32_t flags)
} }
// private // private
void PhysicsEngine::updateObjectHard(btRigidBody* body, CustomMotionState* motionState, uint32_t flags) { void PhysicsEngine::updateObjectHard(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags) {
MotionType newType = motionState->getMotionType(); MotionType newType = motionState->getMotionType();
// pull body out of physics engine // pull body out of physics engine
@ -398,7 +398,7 @@ void PhysicsEngine::updateObjectHard(btRigidBody* body, CustomMotionState* motio
} }
// private // private
void PhysicsEngine::updateObjectEasy(btRigidBody* body, CustomMotionState* motionState, uint32_t flags) { void PhysicsEngine::updateObjectEasy(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags) {
if (flags & PHYSICS_UPDATE_POSITION) { if (flags & PHYSICS_UPDATE_POSITION) {
btTransform transform; btTransform transform;
motionState->getWorldTransform(transform); motionState->getWorldTransform(transform);

View file

@ -39,7 +39,7 @@ const uint32_t PHYSICS_UPDATE_EASY = PHYSICS_UPDATE_POSITION | PHYSICS_UPDATE_VE
#include <EntitySimulation.h> #include <EntitySimulation.h>
#include "BulletUtil.h" #include "BulletUtil.h"
#include "CustomMotionState.h" #include "ObjectMotionState.h"
#include "PositionHashKey.h" #include "PositionHashKey.h"
#include "ShapeManager.h" #include "ShapeManager.h"
#include "ThreadSafeDynamicsWorld.h" #include "ThreadSafeDynamicsWorld.h"
@ -101,20 +101,20 @@ public:
/// \param motionState pointer to Object's MotionState /// \param motionState pointer to Object's MotionState
/// \return true if Object added /// \return true if Object added
bool addObject(CustomMotionState* motionState); bool addObject(ObjectMotionState* motionState);
/// \param motionState pointer to Object's MotionState /// \param motionState pointer to Object's MotionState
/// \return true if Object removed /// \return true if Object removed
bool removeObject(CustomMotionState* motionState); bool removeObject(ObjectMotionState* motionState);
/// \param motionState pointer to Object's MotionState /// \param motionState pointer to Object's MotionState
/// \param flags set of bits indicating what categories of properties need to be updated /// \param flags set of bits indicating what categories of properties need to be updated
/// \return true if entity updated /// \return true if entity updated
bool updateObject(CustomMotionState* motionState, uint32_t flags); bool updateObject(ObjectMotionState* motionState, uint32_t flags);
protected: protected:
void updateObjectHard(btRigidBody* body, CustomMotionState* motionState, uint32_t flags); void updateObjectHard(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags);
void updateObjectEasy(btRigidBody* body, CustomMotionState* motionState, uint32_t flags); void updateObjectEasy(btRigidBody* body, ObjectMotionState* motionState, uint32_t flags);
btClock _clock; btClock _clock;
btDefaultCollisionConfiguration* _collisionConfig; btDefaultCollisionConfiguration* _collisionConfig;