Merge branch 'master' into tony/grab-script-hand-animation

This commit is contained in:
Anthony J. Thibault 2016-01-06 16:26:56 -08:00
commit 1251be1b2b
8 changed files with 150 additions and 102 deletions

View file

@ -41,6 +41,7 @@ var DISTANCE_HOLDING_RADIUS_FACTOR = 3.5; // multiplied by distance between hand
var DISTANCE_HOLDING_ACTION_TIMEFRAME = 0.1; // how quickly objects move to their new position
var DISTANCE_HOLDING_ROTATION_EXAGGERATION_FACTOR = 2.0; // object rotates this much more than hand did
var MOVE_WITH_HEAD = true; // experimental head-controll of distantly held objects
var FAR_TO_NEAR_GRAB_PADDING_FACTOR = 1.2;
var NO_INTERSECT_COLOR = {
red: 10,
@ -980,11 +981,19 @@ function MyController(hand) {
if (intersection.properties.collisionsWillMove && !intersection.properties.locked) {
// the hand is far from the intersected object. go into distance-holding mode
this.grabbedEntity = intersection.entityID;
if (typeof grabbableData.spatialKey !== 'undefined' && this.state == STATE_EQUIP_SEARCHING) {
if (this.state == STATE_EQUIP_SEARCHING) {
// if a distance pick in equip mode hits something with a spatialKey, equip it
// TODO use STATE_EQUIP_SPRING here once it works right.
// this.setState(STATE_EQUIP_SPRING);
if (typeof grabbableData.spatialKey === 'undefined') {
// We want to give a temporary position offset to this object so it is pulled close to hand
var intersectionPointToCenterDistance = Vec3.length(Vec3.subtract(intersection.intersection, intersection.properties.position));
this.temporaryPositionOffset = Vec3.normalize(Vec3.subtract(intersection.properties.position, handPosition));
this.temporaryPositionOffset = Vec3.multiply(this.temporaryPositionOffset, intersectionPointToCenterDistance * FAR_TO_NEAR_GRAB_PADDING_FACTOR);
}
this.setState(STATE_EQUIP);
this.turnOffVisualizations();
return;
} else if ((this.state == STATE_SEARCHING) && this.triggerSmoothedGrab()) {
this.setState(STATE_DISTANCE_HOLDING);
@ -1437,7 +1446,11 @@ function MyController(hand) {
var currentObjectPosition = grabbedProperties.position;
var offset = Vec3.subtract(currentObjectPosition, handPosition);
this.offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, this.offsetRotation)), offset);
if (this.temporaryPositionOffset && this.state != STATE_NEAR_GRABBING) {
this.offsetPosition = this.temporaryPositionOffset;
}
}
if (!this.setupHoldAction()) {
return;

View file

@ -16,5 +16,12 @@
this.collisionWithEntity = function(myID, otherID, collisionInfo) {
Entities.editEntity(myID, { color: { red: getRandomInt(128,255), green: getRandomInt(128,255), blue: getRandomInt(128,255)} });
print("collisionWithEntity() myID:" + myID + ", otherID:" + otherID);
print(" collisionInfo.type:" + collisionInfo.type);
print(" collisionInfo.idA:" + collisionInfo.idA);
print(" collisionInfo.idB:" + collisionInfo.idB);
Vec3.print(" collisionInfo.penetration:", collisionInfo.penetration);
Vec3.print(" collisionInfo.contactPoint:", collisionInfo.contactPoint);
Vec3.print(" collisionInfo.velocityChange:", collisionInfo.velocityChange);
};
})

View file

@ -309,7 +309,7 @@ Grabber.prototype.computeNewGrabPlane = function() {
}
Grabber.prototype.pressEvent = function(event) {
if (!event.isLeftButton) {
if (event.isLeftButton!==true ||event.isRightButton===true || event.isMiddleButton===true) {
return;
}
@ -374,7 +374,11 @@ Grabber.prototype.pressEvent = function(event) {
//Audio.playSound(grabSound, { position: entityProperties.position, volume: VOLUME });
}
Grabber.prototype.releaseEvent = function() {
Grabber.prototype.releaseEvent = function(event) {
if (event.isLeftButton!==true ||event.isRightButton===true || event.isMiddleButton===true) {
return;
}
if (this.isGrabbing) {
this.deactivateEntity(this.entityID);
this.isGrabbing = false

View file

@ -64,7 +64,7 @@ const float MIN_AVATAR_SPEED = 0.05f; // speed is set to zero below this
// TODO: normalize avatar speed for standard avatar size, then scale all motion logic
// to properly follow avatar size.
float MAX_AVATAR_SPEED = 300.0f;
float MAX_AVATAR_SPEED = 30.0f;
float MAX_KEYBOARD_MOTOR_SPEED = MAX_AVATAR_SPEED;
float DEFAULT_KEYBOARD_MOTOR_TIMESCALE = 0.25f;
float MIN_SCRIPTED_MOTOR_TIMESCALE = 0.005f;

View file

@ -717,11 +717,11 @@ void EntityTreeRenderer::checkAndCallPreload(const EntityItemID& entityID, const
}
}
void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree,
bool EntityTreeRenderer::isCollisionOwner(const QUuid& myNodeID, EntityTreePointer entityTree,
const EntityItemID& id, const Collision& collision) {
EntityItemPointer entity = entityTree->findEntityByEntityItemID(id);
if (!entity) {
return;
return false;
}
QUuid simulatorID = entity->getSimulatorID();
if (simulatorID.isNull()) {
@ -730,14 +730,30 @@ void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityT
const EntityItemID& otherID = (id == collision.idA) ? collision.idB : collision.idA;
EntityItemPointer otherEntity = entityTree->findEntityByEntityItemID(otherID);
if (!otherEntity) {
return;
return false;
}
simulatorID = otherEntity->getSimulatorID();
}
if (simulatorID.isNull() || (simulatorID != myNodeID)) {
return; // Only one injector per simulation, please.
return false;
}
return true;
}
void EntityTreeRenderer::playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree,
const EntityItemID& id, const Collision& collision) {
if (!isCollisionOwner(myNodeID, entityTree, id, collision)) {
return;
}
EntityItemPointer entity = entityTree->findEntityByEntityItemID(id);
if (!entity) {
return;
}
const QString& collisionSoundURL = entity->getCollisionSoundURL();
if (collisionSoundURL.isEmpty()) {
return;
@ -796,11 +812,16 @@ void EntityTreeRenderer::entityCollisionWithEntity(const EntityItemID& idA, cons
playEntityCollisionSound(myNodeID, entityTree, idB, collision);
// And now the entity scripts
if (isCollisionOwner(myNodeID, entityTree, idA, collision)) {
emit collisionWithEntity(idA, idB, collision);
_entitiesScriptEngine->callEntityScriptMethod(idA, "collisionWithEntity", idB, collision);
}
if (isCollisionOwner(myNodeID, entityTree, idA, collision)) {
emit collisionWithEntity(idB, idA, collision);
_entitiesScriptEngine->callEntityScriptMethod(idB, "collisionWithEntity", idA, collision);
}
}
void EntityTreeRenderer::updateEntityRenderStatus(bool shouldRenderEntities) {
if (DependencyManager::get<SceneScriptingInterface>()->shouldRenderEntities()) {

View file

@ -148,6 +148,9 @@ private:
bool _wantScripts;
ScriptEngine* _entitiesScriptEngine;
bool isCollisionOwner(const QUuid& myNodeID, EntityTreePointer entityTree,
const EntityItemID& id, const Collision& collision);
void playEntityCollisionSound(const QUuid& myNodeID, EntityTreePointer entityTree,
const EntityItemID& id, const Collision& collision);

View file

@ -41,7 +41,7 @@ PacketVersion versionForPacketType(PacketType packetType) {
case PacketType::EntityAdd:
case PacketType::EntityEdit:
case PacketType::EntityData:
return VERSION_MODEL_ENTITIES_JOINTS_ON_WIRE;
return VERSION_ENTITITES_HAVE_QUERY_BOX;
case PacketType::AvatarData:
case PacketType::BulkAvatarData:
return static_cast<PacketVersion>(AvatarMixerPacketVersion::SoftAttachmentSupport);

View file

@ -699,7 +699,7 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char *dataBytes, QVecto
dataBytes += unpackOrientationQuatFromBytes(dataBytes, result[i]);
}
return (dataBytes - start) + sizeof(uint16_t);
return (dataBytes - start) + (int)sizeof(uint16_t);
}
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVector<float>& result) {
@ -728,7 +728,7 @@ int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QVecto
bit = (bit + 1) % BITS_IN_BYTE;
}
return (dataBytes - start) + sizeof(uint16_t);
return (dataBytes - start) + (int)sizeof(uint16_t);
}
int OctreePacketData::unpackDataFromBytes(const unsigned char* dataBytes, QByteArray& result) {