mirror of
https://github.com/lubosz/overte.git
synced 2025-04-23 09:25:31 +02:00
Merge pull request #4081 from AndrewMeadows/inertia
move static const variables in EntityItem to be simple consts
This commit is contained in:
commit
c80414dd96
5 changed files with 41 additions and 68 deletions
|
@ -21,31 +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;
|
||||
|
@ -1018,7 +993,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;
|
||||
|
|
|
@ -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) / (float)TREE_SCALE;
|
||||
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.
|
||||
|
@ -149,7 +174,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
|
||||
|
@ -161,34 +185,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
|
||||
|
@ -198,13 +212,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
|
||||
|
||||
|
@ -225,46 +236,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; }
|
||||
|
||||
|
|
|
@ -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),
|
||||
|
|
|
@ -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;
|
||||
|
|
|
@ -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;
|
||||
};
|
||||
|
||||
|
|
Loading…
Reference in a new issue