Replace entities pos/rot/dim with transform

Removed _position, _rotation, _dimensions
Added Transform _transform
This commit is contained in:
Atlante45 2015-05-15 17:35:24 +02:00
parent 3471c0a44f
commit d0cd18d6c0
12 changed files with 71 additions and 77 deletions

View file

@ -396,7 +396,7 @@ void RenderableModelEntityItem::computeShapeInfo(ShapeInfo& info) {
// to the visual model and apply them to the collision model (without regard for the
// collision model's extents).
glm::vec3 scale = _dimensions / renderGeometry.getUnscaledMeshExtents().size();
glm::vec3 scale = getDimensions() / renderGeometry.getUnscaledMeshExtents().size();
// multiply each point by scale before handing the point-set off to the physics engine.
// also determine the extents of the collision model.
AABox box;

View file

@ -122,10 +122,10 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
glm::vec3 point = intersection.intersection;
point -= getPosition();
point = glm::inverse(getRotation()) * point;
point /= _dimensions;
point /= getDimensions();
point += 0.5f;
point.y = 1.0f - point.y;
point *= _dimensions * METERS_TO_INCHES * DPI;
point *= getDimensions() * METERS_TO_INCHES * DPI;
// Forward the mouse event.
QMouseEvent mappedEvent(event->type(),
QPoint((int)point.x, (int)point.y),
@ -140,7 +140,7 @@ void RenderableWebEntityItem::render(RenderArgs* args) {
QObject::connect(renderer, &EntityTreeRenderer::mouseMoveOnEntity, forwardMouseEvent);
}
glm::vec2 dims = glm::vec2(_dimensions);
glm::vec2 dims = glm::vec2(getDimensions());
dims *= METERS_TO_INCHES * DPI;
// The offscreen surface is idempotent for resizes (bails early
// if it's a no-op), so it's safe to just call resize every frame

View file

@ -101,8 +101,8 @@ void BoxEntityItem::debugDump() const {
quint64 now = usecTimestampNow();
qCDebug(entities) << " BOX EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " position:" << debugTreeVector(getPosition());
qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions());
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
}

View file

@ -40,9 +40,6 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) :
_lastEditedFromRemoteInRemoteTime(0),
_created(UNKNOWN_CREATED_TIME),
_changedOnServer(0),
_position(ENTITY_ITEM_ZERO_VEC3),
_dimensions(ENTITY_ITEM_DEFAULT_DIMENSIONS),
_rotation(ENTITY_ITEM_DEFAULT_ROTATION),
_glowLevel(ENTITY_ITEM_DEFAULT_GLOW_LEVEL),
_localRenderAlpha(ENTITY_ITEM_DEFAULT_LOCAL_RENDER_ALPHA),
_density(ENTITY_ITEM_DEFAULT_DENSITY),
@ -321,8 +318,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
}
// if this bitstream indicates that this node is the simulation owner, ignore any physics-related updates.
glm::vec3 savePosition = _position;
glm::quat saveRotation = _rotation;
glm::vec3 savePosition = getPosition();
glm::quat saveRotation = getRotation();
// glm::vec3 saveVelocity = _velocity;
// glm::vec3 saveAngularVelocity = _angularVelocity;
// glm::vec3 saveGravity = _gravity;
@ -628,8 +625,8 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
if (_simulatorID == myNodeID && !_simulatorID.isNull()) {
// the packet that produced this bitstream originally came from physics simulations performed by
// this node, so our version has to be newer than what the packet contained.
_position = savePosition;
_rotation = saveRotation;
setPosition(savePosition);
setRotation(saveRotation);
// _velocity = saveVelocity;
// _angularVelocity = saveAngularVelocity;
// _gravity = saveGravity;
@ -640,10 +637,11 @@ int EntityItem::readEntityDataFromBuffer(const unsigned char* data, int bytesLef
}
void EntityItem::debugDump() const {
auto position = getPosition();
qCDebug(entities) << "EntityItem id:" << getEntityItemID();
qCDebug(entities, " edited ago:%f", getEditedAgo());
qCDebug(entities, " position:%f,%f,%f", _position.x, _position.y, _position.z);
qCDebug(entities) << " dimensions:" << _dimensions;
qCDebug(entities, " position:%f,%f,%f", position.x, position.y, position.z);
qCDebug(entities) << " dimensions:" << getDimensions();
}
// adjust any internal timestamps to fix clock skew for this server
@ -666,8 +664,8 @@ void EntityItem::adjustEditPacketForClockSkew(unsigned char* editPacketBuffer, s
#endif
}
float EntityItem::computeMass() const {
return _density * _volumeMultiplier * _dimensions.x * _dimensions.y * _dimensions.z;
float EntityItem::computeMass() const {
return _density * _volumeMultiplier * getDimensions().x * getDimensions().y * getDimensions().z;
}
void EntityItem::setDensity(float density) {
@ -692,8 +690,8 @@ void EntityItem::setMass(float mass) {
// Setting the mass actually changes the _density (at fixed volume), however
// we must protect the density range to help maintain stability of physics simulation
// therefore this method might not accept the mass that is supplied.
float volume = _volumeMultiplier * _dimensions.x * _dimensions.y * _dimensions.z;
float volume = _volumeMultiplier * getDimensions().x * getDimensions().y * getDimensions().z;
// compute new density
const float MIN_VOLUME = 1.0e-6f; // 0.001mm^3
@ -997,10 +995,8 @@ void EntityItem::recordCreationTime() {
_lastSimulated = _created;
}
// TODO: doesn't this need to handle rotation?
glm::vec3 EntityItem::getCenter() const {
return _position + (_dimensions * (glm::vec3(0.5f,0.5f,0.5f) - _registrationPoint));
return getPosition() + (getDimensions() * (ENTITY_ITEM_DEFAULT_REGISTRATION_POINT - getRegistrationPoint()));
}
/// The maximum bounding cube for the entity, independent of it's rotation.
@ -1008,13 +1004,13 @@ glm::vec3 EntityItem::getCenter() const {
///
AACube EntityItem::getMaximumAACube() const {
// * we know that the position is the center of rotation
glm::vec3 centerOfRotation = _position; // also where _registration point is
glm::vec3 centerOfRotation = getPosition(); // also where _registration point is
// * we know that the registration point is the center of rotation
// * we can calculate the length of the furthest extent from the registration point
// as the dimensions * max (registrationPoint, (1.0,1.0,1.0) - registrationPoint)
glm::vec3 registrationPoint = (_dimensions * _registrationPoint);
glm::vec3 registrationRemainder = (_dimensions * (glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint));
glm::vec3 registrationPoint = (getDimensions() * getRegistrationPoint());
glm::vec3 registrationRemainder = (getDimensions() * (glm::vec3(1.0f, 1.0f, 1.0f) - getRegistrationPoint()));
glm::vec3 furthestExtentFromRegistration = glm::max(registrationPoint, registrationRemainder);
// * we know that if you rotate in any direction you would create a sphere
@ -1036,13 +1032,13 @@ AACube EntityItem::getMinimumAACube() const {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
glm::vec3 unrotatedMinRelativeToEntity = - (_dimensions * _registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = _dimensions * registrationRemainder;
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * getRegistrationPoint());
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
// shift the extents to be relative to the position/registration point
rotatedExtentsRelativeToRegistrationPoint.shiftBy(_position);
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
// the cube that best encompasses extents is...
AABox box(rotatedExtentsRelativeToRegistrationPoint);
@ -1060,13 +1056,13 @@ AABox EntityItem::getAABox() const {
// _position represents the position of the registration point.
glm::vec3 registrationRemainder = glm::vec3(1.0f, 1.0f, 1.0f) - _registrationPoint;
glm::vec3 unrotatedMinRelativeToEntity = - (_dimensions * _registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = _dimensions * registrationRemainder;
glm::vec3 unrotatedMinRelativeToEntity = - (getDimensions() * _registrationPoint);
glm::vec3 unrotatedMaxRelativeToEntity = getDimensions() * registrationRemainder;
Extents unrotatedExtentsRelativeToRegistrationPoint = { unrotatedMinRelativeToEntity, unrotatedMaxRelativeToEntity };
Extents rotatedExtentsRelativeToRegistrationPoint = unrotatedExtentsRelativeToRegistrationPoint.getRotated(getRotation());
// shift the extents to be relative to the position/registration point
rotatedExtentsRelativeToRegistrationPoint.shiftBy(_position);
rotatedExtentsRelativeToRegistrationPoint.shiftBy(getPosition());
return AABox(rotatedExtentsRelativeToRegistrationPoint);
}
@ -1087,7 +1083,7 @@ AABox EntityItem::getAABox() const {
void EntityItem::setRadius(float value) {
float diameter = value * 2.0f;
float maxDimension = sqrt((diameter * diameter) / 3.0f);
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension));
}
// TODO: get rid of all users of this function...
@ -1095,7 +1091,7 @@ void EntityItem::setRadius(float value) {
// ... cornerToCornerLength = sqrt(3 x maxDimension ^ 2)
// ... radius = sqrt(3 x maxDimension ^ 2) / 2.0f;
float EntityItem::getRadius() const {
return 0.5f * glm::length(_dimensions);
return 0.5f * glm::length(getDimensions());
}
bool EntityItem::contains(const glm::vec3& point) const {
@ -1118,10 +1114,10 @@ void EntityItem::updatePositionInDomainUnits(const glm::vec3& value) {
}
void EntityItem::updatePosition(const glm::vec3& value) {
auto delta = glm::distance(_position, value);
auto delta = glm::distance(getPosition(), value);
if (delta > IGNORE_POSITION_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_POSITION;
_position = value;
setPosition(value);
if (delta > ACTIVATION_POSITION_DELTA) {
_dirtyFlags |= EntityItem::DIRTY_PHYSICS_ACTIVATION;
}
@ -1134,9 +1130,9 @@ void EntityItem::updateDimensionsInDomainUnits(const glm::vec3& value) {
}
void EntityItem::updateDimensions(const glm::vec3& value) {
auto delta = glm::distance(_dimensions, value);
auto delta = glm::distance(getDimensions(), value);
if (delta > IGNORE_DIMENSIONS_DELTA) {
_dimensions = value;
setDimensions(value);
if (delta > ACTIVATION_DIMENSIONS_DELTA) {
// rebuilding the shape will always activate
_dirtyFlags |= (EntityItem::DIRTY_SHAPE | EntityItem::DIRTY_MASS);
@ -1145,10 +1141,10 @@ void EntityItem::updateDimensions(const glm::vec3& value) {
}
void EntityItem::updateRotation(const glm::quat& rotation) {
if (_rotation != rotation) {
_rotation = rotation;
if (getRotation() != rotation) {
setRotation(rotation);
auto alignmentDot = glm::abs(glm::dot(_rotation, rotation));
auto alignmentDot = glm::abs(glm::dot(getRotation(), rotation));
if (alignmentDot < IGNORE_ALIGNMENT_DOT) {
_dirtyFlags |= EntityItem::DIRTY_ROTATION;
}
@ -1163,7 +1159,7 @@ void EntityItem::updateMass(float mass) {
// we must protect the density range to help maintain stability of physics simulation
// therefore this method might not accept the mass that is supplied.
float volume = _volumeMultiplier * _dimensions.x * _dimensions.y * _dimensions.z;
float volume = _volumeMultiplier * getDimensions().x * getDimensions().y * getDimensions().z;
// compute new density
float newDensity = _density;

View file

@ -22,6 +22,7 @@
#include <OctreeElement.h> // for OctreeElement::AppendState
#include <OctreePacketData.h>
#include <ShapeInfo.h>
#include <Transform.h>
#include "EntityItemID.h"
#include "EntityItemProperties.h"
@ -179,21 +180,20 @@ public:
// attributes applicable to all entity types
EntityTypes::EntityType getType() const { return _type; }
const glm::vec3& getPosition() const { return _position; } /// get position in meters
void setPosition(const glm::vec3& value) {
_position = value;
}
glm::vec3 getCenter() const;
/// Position in meters (0.0 - TREE_SCALE)
const glm::vec3& getPosition() const { return _transform.getTranslation(); } /// get position in meters
void setPosition(const glm::vec3& value) { _transform.setTranslation(value); }
const glm::quat& getRotation() const { return _transform.getRotation(); }
void setRotation(const glm::quat& rotation) { _transform.setRotation(rotation); }
/// Dimensions in meters (0.0 - TREE_SCALE)
const glm::vec3& getDimensions() const { return _transform.getScale(); }
virtual void setDimensions(const glm::vec3& value) { _transform.setScale(glm::abs(value)); }
const glm::vec3& getDimensions() const { return _dimensions; } /// get dimensions in meters
/// set dimensions in meter units (0.0 - TREE_SCALE)
virtual void setDimensions(const glm::vec3& value) { _dimensions = glm::abs(value); }
const glm::quat& getRotation() const { return _rotation; }
void setRotation(const glm::quat& rotation) { _rotation = rotation; }
float getGlowLevel() const { return _glowLevel; }
void setGlowLevel(float glowLevel) { _glowLevel = glowLevel; }
@ -303,7 +303,7 @@ public:
virtual bool isReadyToComputeShape() { return true; }
virtual void computeShapeInfo(ShapeInfo& info);
virtual float getVolumeEstimate() const { return _dimensions.x * _dimensions.y * _dimensions.z; }
virtual float getVolumeEstimate() const { return getDimensions().x * getDimensions().y * getDimensions().z; }
/// return preferred shape type (actual physical shape may differ)
virtual ShapeType getShapeType() const { return SHAPE_TYPE_NONE; }
@ -368,9 +368,7 @@ protected:
quint64 _created;
quint64 _changedOnServer;
glm::vec3 _position;
glm::vec3 _dimensions;
glm::quat _rotation;
Transform _transform;
float _glowLevel;
float _localRenderAlpha;
float _density = ENTITY_ITEM_DEFAULT_DENSITY; // kg/m^3

View file

@ -47,10 +47,10 @@ void LightEntityItem::setDimensions(const glm::vec3& value) {
// recalculate the x/y dimensions to properly encapsulate the spotlight.
const float length = value.z;
const float width = length * glm::tan(glm::radians(_cutoff));
_dimensions = glm::vec3(width, width, length);
EntityItem::setDimensions(glm::vec3(width, width, length));
} else {
float maxDimension = glm::max(value.x, value.y, value.z);
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
EntityItem::setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension));
}
}
@ -72,12 +72,12 @@ void LightEntityItem::setIsSpotlight(bool value) {
_isSpotlight = value;
if (_isSpotlight) {
const float length = _dimensions.z;
const float length = getDimensions().z;
const float width = length * glm::tan(glm::radians(_cutoff));
_dimensions = glm::vec3(width, width, length);
setDimensions(glm::vec3(width, width, length));
} else {
float maxDimension = glm::max(_dimensions.x, _dimensions.y, _dimensions.z);
_dimensions = glm::vec3(maxDimension, maxDimension, maxDimension);
float maxDimension = glm::max(getDimensions().x, getDimensions().y, getDimensions().z);
setDimensions(glm::vec3(maxDimension, maxDimension, maxDimension));
}
}
}
@ -88,9 +88,9 @@ void LightEntityItem::setCutoff(float value) {
if (_isSpotlight) {
// If we are a spotlight, adjusting the cutoff will affect the area we encapsulate,
// so update the dimensions to reflect this.
const float length = _dimensions.z;
const float length = getDimensions().z;
const float width = length * glm::tan(glm::radians(_cutoff));
_dimensions = glm::vec3(width, width, length);
setDimensions(glm::vec3(width, width, length));
}
}

View file

@ -101,8 +101,8 @@ void LineEntityItem::debugDump() const {
quint64 now = usecTimestampNow();
qCDebug(entities) << " LINE EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " position:" << debugTreeVector(getPosition());
qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions());
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
}

View file

@ -276,8 +276,8 @@ void ParticleEffectEntityItem::debugDump() const {
quint64 now = usecTimestampNow();
qCDebug(entities) << "PA EFFECT EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " position:" << debugTreeVector(getPosition());
qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions());
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
}

View file

@ -119,8 +119,8 @@ void SphereEntityItem::debugDump() const {
quint64 now = usecTimestampNow();
qCDebug(entities) << "SHPERE EntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " color:" << _color[0] << "," << _color[1] << "," << _color[2];
qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " position:" << debugTreeVector(getPosition());
qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions());
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
}

View file

@ -45,7 +45,7 @@ const float TEXT_ENTITY_ITEM_FIXED_DEPTH = 0.01f;
void TextEntityItem::setDimensions(const glm::vec3& value) {
// NOTE: Text Entities always have a "depth" of 1cm.
_dimensions = glm::vec3(value.x, value.y, TEXT_ENTITY_ITEM_FIXED_DEPTH);
EntityItem::setDimensions(glm::vec3(value.x, value.y, TEXT_ENTITY_ITEM_FIXED_DEPTH));
}
EntityItemProperties TextEntityItem::getProperties() const {
@ -136,7 +136,7 @@ bool TextEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const
PlaneShape plane;
const glm::vec3 UNROTATED_NORMAL(0.0f, 0.0f, -1.0f);
glm::vec3 normal = _rotation * UNROTATED_NORMAL;
glm::vec3 normal = getRotation() * UNROTATED_NORMAL;
plane.setNormal(normal);
plane.setPoint(getPosition()); // the position is definitely a point on our plane

View file

@ -39,7 +39,7 @@ const float WEB_ENTITY_ITEM_FIXED_DEPTH = 0.01f;
void WebEntityItem::setDimensions(const glm::vec3& value) {
// NOTE: Web Entities always have a "depth" of 1cm.
_dimensions = glm::vec3(value.x, value.y, WEB_ENTITY_ITEM_FIXED_DEPTH);
EntityItem::setDimensions(glm::vec3(value.x, value.y, WEB_ENTITY_ITEM_FIXED_DEPTH));
}
EntityItemProperties WebEntityItem::getProperties() const {
@ -113,7 +113,7 @@ bool WebEntityItem::findDetailedRayIntersection(const glm::vec3& origin, const g
PlaneShape plane;
const glm::vec3 UNROTATED_NORMAL(0.0f, 0.0f, -1.0f);
glm::vec3 normal = _rotation * UNROTATED_NORMAL;
glm::vec3 normal = getRotation() * UNROTATED_NORMAL;
plane.setNormal(normal);
plane.setPoint(getPosition()); // the position is definitely a point on our plane

View file

@ -218,8 +218,8 @@ void ZoneEntityItem::debugDump() const {
quint64 now = usecTimestampNow();
qCDebug(entities) << " ZoneEntityItem id:" << getEntityItemID() << "---------------------------------------------";
qCDebug(entities) << " keyLightColor:" << _keyLightColor[0] << "," << _keyLightColor[1] << "," << _keyLightColor[2];
qCDebug(entities) << " position:" << debugTreeVector(_position);
qCDebug(entities) << " dimensions:" << debugTreeVector(_dimensions);
qCDebug(entities) << " position:" << debugTreeVector(getPosition());
qCDebug(entities) << " dimensions:" << debugTreeVector(getDimensions());
qCDebug(entities) << " getLastEdited:" << debugTime(getLastEdited(), now);
qCDebug(entities) << " _keyLightIntensity:" << _keyLightIntensity;
qCDebug(entities) << " _keyLightAmbientIntensity:" << _keyLightAmbientIntensity;