From 4946ec18b6be68b73d88ce41013498244b74ef4c Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Fri, 9 Jan 2015 09:28:01 -0800 Subject: [PATCH 1/3] remove some TODO comments --- libraries/entities/src/EntityItem.cpp | 1 - libraries/physics/src/ObjectMotionState.cpp | 2 -- libraries/physics/src/ObjectMotionState.h | 2 +- 3 files changed, 1 insertion(+), 4 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index a744d39f05..48ceed863e 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -1015,7 +1015,6 @@ void EntityItem::recalculateCollisionShape() { entityAACube.scale(TREE_SCALE); // scale to meters _collisionShape.setTranslation(entityAACube.calcCenter()); _collisionShape.setScale(entityAACube.getScale()); - // TODO: use motionState to update physics object } const float MIN_POSITION_DELTA = 0.0001f; diff --git a/libraries/physics/src/ObjectMotionState.cpp b/libraries/physics/src/ObjectMotionState.cpp index f8f0712d5e..46c67c0ec2 100644 --- a/libraries/physics/src/ObjectMotionState.cpp +++ b/libraries/physics/src/ObjectMotionState.cpp @@ -154,8 +154,6 @@ bool ObjectMotionState::shouldSendUpdate(uint32_t simulationFrame, float subStep // NOTE: math in done the simulation-frame, which is NOT necessarily the same as the world-frame // due to _worldOffset. - // TODO: Andrew to reconcile Bullet and legacy damping coefficients. - // compute position error if (glm::length2(_sentVelocity) > 0.0f) { _sentVelocity += _sentAcceleration * dt; diff --git a/libraries/physics/src/ObjectMotionState.h b/libraries/physics/src/ObjectMotionState.h index c0d3d2cabf..cb19babc1d 100644 --- a/libraries/physics/src/ObjectMotionState.h +++ b/libraries/physics/src/ObjectMotionState.h @@ -111,7 +111,7 @@ protected: glm::vec3 _sentPosition; // in simulation-frame (not world-frame) glm::quat _sentRotation;; glm::vec3 _sentVelocity; - glm::vec3 _sentAngularVelocity; + glm::vec3 _sentAngularVelocity; // radians per second glm::vec3 _sentAcceleration; }; From 25e64d619ca9041b54dc9fd98449db8c0953ae01 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Sat, 10 Jan 2015 11:46:42 -0800 Subject: [PATCH 2/3] move statics out of EntityItem This makes for much more readable core dumps --- libraries/entities/src/EntityItem.cpp | 2 + libraries/entities/src/EntityItem.h | 49 ++++++++++--------- .../entities/src/EntityItemProperties.cpp | 30 ++++++------ 3 files changed, 42 insertions(+), 39 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index 48ceed863e..73509305ed 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -21,6 +21,7 @@ #include "EntityItem.h" #include "EntityTree.h" +/* const float EntityItem::IMMORTAL = -1.0f; /// special lifetime which means the entity lives for ever. default lifetime const float EntityItem::DEFAULT_GLOW_LEVEL = 0.0f; const float EntityItem::DEFAULT_LOCAL_RENDER_ALPHA = 1.0f; @@ -45,6 +46,7 @@ const bool EntityItem::DEFAULT_VISIBLE = true; const bool EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS = false; const bool EntityItem::DEFAULT_COLLISIONS_WILL_MOVE = false; const bool EntityItem::DEFAULT_LOCKED = false; +*/ void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _id = entityItemID.id; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index e52be1707a..365bc1b0f5 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -35,6 +35,31 @@ class EntityTreeElementExtraEncodeData; #define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0; #define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() { }; +const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f); +const glm::quat DEFAULT_ROTATION; +const float DEFAULT_GLOW_LEVEL = 0.0f; +const float DEFAULT_LOCAL_RENDER_ALPHA = 1.0f; +const float DEFAULT_MASS = 1.0f; +const glm::vec3 NO_VELOCITY= glm::vec3(0.0f); +const glm::vec3 DEFAULT_VELOCITY = NO_VELOCITY; +const float EPSILON_VELOCITY_LENGTH = 0.001f / (float)TREE_SCALE; +const glm::vec3 NO_GRAVITY = glm::vec3(0.0f); +const glm::vec3 DEFAULT_GRAVITY = NO_GRAVITY; +const glm::vec3 REGULAR_GRAVITY = glm::vec3(0, -9.8f / (float)TREE_SCALE, 0); +const float DEFAULT_DAMPING = 0.39347f; // approx timescale = 2.0 sec (see damping timescale formula in header) +const float IMMORTAL = -1.0f; /// special lifetime which means the entity lives for ever. default lifetime +const float DEFAULT_LIFETIME = IMMORTAL; +const QString DEFAULT_SCRIPT = QString(""); +const glm::vec3 DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f, 0.5f, 0.5f); // center +const glm::vec3 NO_ANGULAR_VELOCITY = glm::vec3(0.0f); +const glm::vec3 DEFAULT_ANGULAR_VELOCITY = NO_ANGULAR_VELOCITY; +const float DEFAULT_ANGULAR_DAMPING = 0.39347f; // approx timescale = 2.0 sec (see damping timescale formula in header) +const bool DEFAULT_VISIBLE = true; +const bool DEFAULT_IGNORE_FOR_COLLISIONS = false; +const bool DEFAULT_COLLISIONS_WILL_MOVE = false; +const bool DEFAULT_LOCKED = false; +const QString DEFAULT_USER_DATA = QString(""); + /// EntityItem class this is the base class for all entity types. It handles the basic properties and functionality available /// to all other entity types. In particular: postion, size, rotation, age, lifetime, velocity, gravity. You can not instantiate /// one directly, instead you must only construct one of it's derived classes with additional features. @@ -148,7 +173,6 @@ public: glm::vec3 getCenter() const; /// calculates center of the entity in domain scale units (0.0 - 1.0) glm::vec3 getCenterInMeters() const { return getCenter() * (float) TREE_SCALE; } - static const glm::vec3 DEFAULT_DIMENSIONS; const glm::vec3& getDimensions() const { return _dimensions; } /// get dimensions in domain scale units (0.0 - 1.0) glm::vec3 getDimensionsInMeters() const { return _dimensions * (float) TREE_SCALE; } /// get dimensions in meters float getDistanceToBottomOfEntity() const; /// get the distance from the position of the entity to its "bottom" in y axis @@ -160,34 +184,24 @@ public: /// set dimensions in meter units (0.0 - TREE_SCALE) this will also reset radius appropriately void setDimensionsInMeters(const glm::vec3& value) { setDimensions(value / (float) TREE_SCALE); } - static const glm::quat DEFAULT_ROTATION; const glm::quat& getRotation() const { return _rotation; } void setRotation(const glm::quat& rotation) { _rotation = rotation; recalculateCollisionShape(); } - static const float DEFAULT_GLOW_LEVEL; float getGlowLevel() const { return _glowLevel; } void setGlowLevel(float glowLevel) { _glowLevel = glowLevel; } - static const float DEFAULT_LOCAL_RENDER_ALPHA; float getLocalRenderAlpha() const { return _localRenderAlpha; } void setLocalRenderAlpha(float localRenderAlpha) { _localRenderAlpha = localRenderAlpha; } - static const float DEFAULT_MASS; float getMass() const { return _mass; } void setMass(float value) { _mass = value; } - static const glm::vec3 DEFAULT_VELOCITY; - static const glm::vec3 NO_VELOCITY; - static const float EPSILON_VELOCITY_LENGTH; const glm::vec3& getVelocity() const { return _velocity; } /// velocity in domain scale units (0.0-1.0) per second glm::vec3 getVelocityInMeters() const { return _velocity * (float) TREE_SCALE; } /// get velocity in meters void setVelocity(const glm::vec3& value) { _velocity = value; } /// velocity in domain scale units (0.0-1.0) per second void setVelocityInMeters(const glm::vec3& value) { _velocity = value / (float) TREE_SCALE; } /// velocity in meters bool hasVelocity() const { return _velocity != NO_VELOCITY; } - static const glm::vec3 DEFAULT_GRAVITY; - static const glm::vec3 REGULAR_GRAVITY; - static const glm::vec3 NO_GRAVITY; const glm::vec3& getGravity() const { return _gravity; } /// gravity in domain scale units (0.0-1.0) per second squared glm::vec3 getGravityInMeters() const { return _gravity * (float) TREE_SCALE; } /// get gravity in meters void setGravity(const glm::vec3& value) { _gravity = value; } /// gravity in domain scale units (0.0-1.0) per second squared @@ -197,13 +211,10 @@ public: // TODO: this should eventually be updated to support resting on collisions with other surfaces bool isRestingOnSurface() const; - static const float DEFAULT_DAMPING; float getDamping() const { return _damping; } void setDamping(float value) { _damping = value; } // lifetime related properties. - static const float IMMORTAL; /// special lifetime which means the entity lives for ever. default lifetime - static const float DEFAULT_LIFETIME; float getLifetime() const { return _lifetime; } /// get the lifetime in seconds for the entity void setLifetime(float value) { _lifetime = value; } /// set the lifetime in seconds for the entity @@ -224,46 +235,36 @@ public: AACube getMinimumAACube() const; AABox getAABox() const; /// axis aligned bounding box in domain scale units (0.0 - 1.0) - static const QString DEFAULT_SCRIPT; const QString& getScript() const { return _script; } void setScript(const QString& value) { _script = value; } - static const glm::vec3 DEFAULT_REGISTRATION_POINT; const glm::vec3& getRegistrationPoint() const { return _registrationPoint; } /// registration point as ratio of entity /// registration point as ratio of entity void setRegistrationPoint(const glm::vec3& value) { _registrationPoint = glm::clamp(value, 0.0f, 1.0f); recalculateCollisionShape(); } - static const glm::vec3 NO_ANGULAR_VELOCITY; - static const glm::vec3 DEFAULT_ANGULAR_VELOCITY; const glm::vec3& getAngularVelocity() const { return _angularVelocity; } void setAngularVelocity(const glm::vec3& value) { _angularVelocity = value; } bool hasAngularVelocity() const { return _angularVelocity != NO_ANGULAR_VELOCITY; } - static const float DEFAULT_ANGULAR_DAMPING; float getAngularDamping() const { return _angularDamping; } void setAngularDamping(float value) { _angularDamping = value; } - static const bool DEFAULT_VISIBLE; bool getVisible() const { return _visible; } void setVisible(bool value) { _visible = value; } bool isVisible() const { return _visible; } bool isInvisible() const { return !_visible; } - static const bool DEFAULT_IGNORE_FOR_COLLISIONS; bool getIgnoreForCollisions() const { return _ignoreForCollisions; } void setIgnoreForCollisions(bool value) { _ignoreForCollisions = value; } - static const bool DEFAULT_COLLISIONS_WILL_MOVE; bool getCollisionsWillMove() const { return _collisionsWillMove; } void setCollisionsWillMove(bool value) { _collisionsWillMove = value; } - static const bool DEFAULT_LOCKED; bool getLocked() const { return _locked; } void setLocked(bool value) { _locked = value; } - static const QString DEFAULT_USER_DATA; const QString& getUserData() const { return _userData; } void setUserData(const QString& value) { _userData = value; } diff --git a/libraries/entities/src/EntityItemProperties.cpp b/libraries/entities/src/EntityItemProperties.cpp index 58b110c4b0..be6fe01841 100644 --- a/libraries/entities/src/EntityItemProperties.cpp +++ b/libraries/entities/src/EntityItemProperties.cpp @@ -24,27 +24,27 @@ EntityItemProperties::EntityItemProperties() : - CONSTRUCT_PROPERTY(visible, EntityItem::DEFAULT_VISIBLE), + CONSTRUCT_PROPERTY(visible, DEFAULT_VISIBLE), CONSTRUCT_PROPERTY(position, 0), - CONSTRUCT_PROPERTY(dimensions, EntityItem::DEFAULT_DIMENSIONS), - CONSTRUCT_PROPERTY(rotation, EntityItem::DEFAULT_ROTATION), - CONSTRUCT_PROPERTY(mass, EntityItem::DEFAULT_MASS), - CONSTRUCT_PROPERTY(velocity, EntityItem::DEFAULT_VELOCITY), - CONSTRUCT_PROPERTY(gravity, EntityItem::DEFAULT_GRAVITY), - CONSTRUCT_PROPERTY(damping, EntityItem::DEFAULT_DAMPING), - CONSTRUCT_PROPERTY(lifetime, EntityItem::DEFAULT_LIFETIME), - CONSTRUCT_PROPERTY(script, EntityItem::DEFAULT_SCRIPT), + CONSTRUCT_PROPERTY(dimensions, DEFAULT_DIMENSIONS), + CONSTRUCT_PROPERTY(rotation, DEFAULT_ROTATION), + CONSTRUCT_PROPERTY(mass, DEFAULT_MASS), + CONSTRUCT_PROPERTY(velocity, DEFAULT_VELOCITY), + CONSTRUCT_PROPERTY(gravity, DEFAULT_GRAVITY), + CONSTRUCT_PROPERTY(damping, DEFAULT_DAMPING), + CONSTRUCT_PROPERTY(lifetime, DEFAULT_LIFETIME), + CONSTRUCT_PROPERTY(script, DEFAULT_SCRIPT), CONSTRUCT_PROPERTY(color, ), CONSTRUCT_PROPERTY(modelURL, ""), CONSTRUCT_PROPERTY(animationURL, ""), CONSTRUCT_PROPERTY(animationFPS, ModelEntityItem::DEFAULT_ANIMATION_FPS), CONSTRUCT_PROPERTY(animationFrameIndex, ModelEntityItem::DEFAULT_ANIMATION_FRAME_INDEX), CONSTRUCT_PROPERTY(animationIsPlaying, ModelEntityItem::DEFAULT_ANIMATION_IS_PLAYING), - CONSTRUCT_PROPERTY(registrationPoint, EntityItem::DEFAULT_REGISTRATION_POINT), - CONSTRUCT_PROPERTY(angularVelocity, EntityItem::DEFAULT_ANGULAR_VELOCITY), - CONSTRUCT_PROPERTY(angularDamping, EntityItem::DEFAULT_ANGULAR_DAMPING), - CONSTRUCT_PROPERTY(ignoreForCollisions, EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS), - CONSTRUCT_PROPERTY(collisionsWillMove, EntityItem::DEFAULT_COLLISIONS_WILL_MOVE), + CONSTRUCT_PROPERTY(registrationPoint, DEFAULT_REGISTRATION_POINT), + CONSTRUCT_PROPERTY(angularVelocity, DEFAULT_ANGULAR_VELOCITY), + CONSTRUCT_PROPERTY(angularDamping, DEFAULT_ANGULAR_DAMPING), + CONSTRUCT_PROPERTY(ignoreForCollisions, DEFAULT_IGNORE_FOR_COLLISIONS), + CONSTRUCT_PROPERTY(collisionsWillMove, DEFAULT_COLLISIONS_WILL_MOVE), CONSTRUCT_PROPERTY(isSpotlight, false), CONSTRUCT_PROPERTY(diffuseColor, ), CONSTRUCT_PROPERTY(ambientColor, ), @@ -57,7 +57,7 @@ EntityItemProperties::EntityItemProperties() : CONSTRUCT_PROPERTY(locked, false), CONSTRUCT_PROPERTY(textures, ""), CONSTRUCT_PROPERTY(animationSettings, ""), - CONSTRUCT_PROPERTY(userData, EntityItem::DEFAULT_USER_DATA), + CONSTRUCT_PROPERTY(userData, DEFAULT_USER_DATA), CONSTRUCT_PROPERTY(text, TextEntityItem::DEFAULT_TEXT), CONSTRUCT_PROPERTY(lineHeight, TextEntityItem::DEFAULT_LINE_HEIGHT), CONSTRUCT_PROPERTY(textColor, TextEntityItem::DEFAULT_TEXT_COLOR), From e711b86519e99eaf855a33788468689b3f434da1 Mon Sep 17 00:00:00 2001 From: Andrew Meadows Date: Sat, 10 Jan 2015 19:07:58 -0800 Subject: [PATCH 3/3] scale DEFAULT_DIMENSIONS correctly also remove a block of commented out cruft --- libraries/entities/src/EntityItem.cpp | 27 --------------------------- libraries/entities/src/EntityItem.h | 2 +- 2 files changed, 1 insertion(+), 28 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index b89f5fedc0..4bf394314b 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -21,33 +21,6 @@ #include "EntityItem.h" #include "EntityTree.h" -/* -const float EntityItem::IMMORTAL = -1.0f; /// special lifetime which means the entity lives for ever. default lifetime -const float EntityItem::DEFAULT_GLOW_LEVEL = 0.0f; -const float EntityItem::DEFAULT_LOCAL_RENDER_ALPHA = 1.0f; -const float EntityItem::DEFAULT_MASS = 1.0f; -const float EntityItem::DEFAULT_LIFETIME = EntityItem::IMMORTAL; -const QString EntityItem::DEFAULT_USER_DATA = QString(""); -const float EntityItem::DEFAULT_DAMPING = 0.39347f; // approx timescale = 2.0 sec (see damping timescale formula in header) -const glm::vec3 EntityItem::NO_VELOCITY = glm::vec3(0, 0, 0); -const float EntityItem::EPSILON_VELOCITY_LENGTH = (1.0f / 1000.0f) / (float)TREE_SCALE; // really small: 1mm/second -const glm::vec3 EntityItem::DEFAULT_VELOCITY = EntityItem::NO_VELOCITY; -const glm::vec3 EntityItem::NO_GRAVITY = glm::vec3(0, 0, 0); -const glm::vec3 EntityItem::REGULAR_GRAVITY = glm::vec3(0, (-9.8f / TREE_SCALE), 0); -const glm::vec3 EntityItem::DEFAULT_GRAVITY = EntityItem::NO_GRAVITY; -const QString EntityItem::DEFAULT_SCRIPT = QString(""); -const glm::quat EntityItem::DEFAULT_ROTATION; -const glm::vec3 EntityItem::DEFAULT_DIMENSIONS = glm::vec3(0.1f, 0.1f, 0.1f); -const glm::vec3 EntityItem::DEFAULT_REGISTRATION_POINT = glm::vec3(0.5f, 0.5f, 0.5f); // center -const glm::vec3 EntityItem::NO_ANGULAR_VELOCITY = glm::vec3(0.0f, 0.0f, 0.0f); -const glm::vec3 EntityItem::DEFAULT_ANGULAR_VELOCITY = NO_ANGULAR_VELOCITY; -const float EntityItem::DEFAULT_ANGULAR_DAMPING = 2.0f; -const bool EntityItem::DEFAULT_VISIBLE = true; -const bool EntityItem::DEFAULT_IGNORE_FOR_COLLISIONS = false; -const bool EntityItem::DEFAULT_COLLISIONS_WILL_MOVE = false; -const bool EntityItem::DEFAULT_LOCKED = false; -*/ - void EntityItem::initFromEntityItemID(const EntityItemID& entityItemID) { _id = entityItemID.id; _creatorTokenID = entityItemID.creatorTokenID; diff --git a/libraries/entities/src/EntityItem.h b/libraries/entities/src/EntityItem.h index 9bdd73c503..1b8afa930b 100644 --- a/libraries/entities/src/EntityItem.h +++ b/libraries/entities/src/EntityItem.h @@ -35,7 +35,7 @@ class EntityTreeElementExtraEncodeData; #define DONT_ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() = 0; #define ALLOW_INSTANTIATION virtual void pureVirtualFunctionPlaceHolder() { }; -const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f); +const glm::vec3 DEFAULT_DIMENSIONS = glm::vec3(0.1f) / (float)TREE_SCALE; const glm::quat DEFAULT_ROTATION; const float DEFAULT_GLOW_LEVEL = 0.0f; const float DEFAULT_LOCAL_RENDER_ALPHA = 1.0f;