From ffce38769f621596a416635dff58a5fa9c202dba Mon Sep 17 00:00:00 2001 From: Seth Alves Date: Wed, 10 Feb 2016 19:16:08 -0800 Subject: [PATCH] properties hold local velocities, not world-frame ones --- libraries/entities/src/EntityItem.cpp | 12 ++++++------ libraries/entities/src/EntityScriptingInterface.cpp | 8 ++++++-- 2 files changed, 12 insertions(+), 8 deletions(-) diff --git a/libraries/entities/src/EntityItem.cpp b/libraries/entities/src/EntityItem.cpp index bc1a848724..6936fee8a9 100644 --- a/libraries/entities/src/EntityItem.cpp +++ b/libraries/entities/src/EntityItem.cpp @@ -76,8 +76,8 @@ EntityItem::EntityItem(const EntityItemID& entityItemID) : _physicsInfo(nullptr), _simulated(false) { - setVelocity(ENTITY_ITEM_DEFAULT_VELOCITY); - setAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY); + setLocalVelocity(ENTITY_ITEM_DEFAULT_VELOCITY); + setLocalAngularVelocity(ENTITY_ITEM_DEFAULT_ANGULAR_VELOCITY); // explicitly set transform parts to set dirty flags used by batch rendering setScale(ENTITY_ITEM_DEFAULT_DIMENSIONS); quint64 now = usecTimestampNow(); @@ -244,8 +244,8 @@ OctreeElement::AppendState EntityItem::appendEntityData(OctreePacketData* packet APPEND_ENTITY_PROPERTY(PROP_SIMULATION_OWNER, _simulationOwner.toByteArray()); APPEND_ENTITY_PROPERTY(PROP_POSITION, getLocalPosition()); APPEND_ENTITY_PROPERTY(PROP_ROTATION, getLocalOrientation()); - APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getVelocity()); - APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getAngularVelocity()); + APPEND_ENTITY_PROPERTY(PROP_VELOCITY, getLocalVelocity()); + APPEND_ENTITY_PROPERTY(PROP_ANGULAR_VELOCITY, getLocalAngularVelocity()); APPEND_ENTITY_PROPERTY(PROP_ACCELERATION, getAcceleration()); APPEND_ENTITY_PROPERTY(PROP_DIMENSIONS, getDimensions()); // NOTE: PROP_RADIUS obsolete @@ -1054,7 +1054,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(dimensions, getDimensions); // NOTE: radius is obsolete COPY_ENTITY_PROPERTY_TO_PROPERTIES(rotation, getLocalOrientation); COPY_ENTITY_PROPERTY_TO_PROPERTIES(density, getDensity); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getVelocity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(velocity, getLocalVelocity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(gravity, getGravity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(acceleration, getAcceleration); COPY_ENTITY_PROPERTY_TO_PROPERTIES(damping, getDamping); @@ -1066,7 +1066,7 @@ EntityItemProperties EntityItem::getProperties(EntityPropertyFlags desiredProper COPY_ENTITY_PROPERTY_TO_PROPERTIES(scriptTimestamp, getScriptTimestamp); COPY_ENTITY_PROPERTY_TO_PROPERTIES(collisionSoundURL, getCollisionSoundURL); COPY_ENTITY_PROPERTY_TO_PROPERTIES(registrationPoint, getRegistrationPoint); - COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getAngularVelocity); + COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularVelocity, getLocalAngularVelocity); COPY_ENTITY_PROPERTY_TO_PROPERTIES(angularDamping, getAngularDamping); COPY_ENTITY_PROPERTY_TO_PROPERTIES(glowLevel, getGlowLevel); COPY_ENTITY_PROPERTY_TO_PROPERTIES(localRenderAlpha, getLocalRenderAlpha); diff --git a/libraries/entities/src/EntityScriptingInterface.cpp b/libraries/entities/src/EntityScriptingInterface.cpp index 802b21a23b..f3a25b2c9c 100644 --- a/libraries/entities/src/EntityScriptingInterface.cpp +++ b/libraries/entities/src/EntityScriptingInterface.cpp @@ -81,6 +81,8 @@ EntityItemProperties convertLocationToScriptSemantics(const EntityItemProperties entitySideProperties.getParentID(), entitySideProperties.getParentJointIndex(), success); + // TODO -- handle velocity and angularVelocity + scriptSideProperties.setPosition(worldPosition); scriptSideProperties.setRotation(worldRotation); @@ -94,6 +96,8 @@ EntityItemProperties convertLocationFromScriptSemantics(const EntityItemProperti EntityItemProperties entitySideProperties = scriptSideProperties; bool success; + // TODO -- handle velocity and angularVelocity + if (scriptSideProperties.localPositionChanged()) { entitySideProperties.setPosition(scriptSideProperties.getLocalPosition()); } else if (scriptSideProperties.positionChanged()) { @@ -128,14 +132,14 @@ QUuid EntityScriptingInterface::addEntity(const EntityItemProperties& properties auto newVelocity = propertiesWithSimID.getVelocity().length(); float cost = calculateCost(density * volume, 0, newVelocity); cost *= costMultiplier; - + if(cost > _currentAvatarEnergy) { return QUuid(); } else { //debit the avatar energy and continue emit debitEnergySource(cost); } - + EntityItemID id = EntityItemID(QUuid::createUuid()); // If we have a local entity tree set, then also update it.