Merge pull request #5737 from ericrius1/grabChanges

hydraGrab is now called handControllerGrab.js now grabs entities based on how they want to be grabbed (th…
This commit is contained in:
Brad Hefta-Gaub 2015-09-08 15:59:28 -07:00
commit fe90af0e07
2 changed files with 41 additions and 34 deletions

View file

@ -11,7 +11,8 @@
//
Script.include("../../libraries/utils.js");
Script.include("../libraries/utils.js");
var RIGHT_HAND_CLICK = Controller.findAction("RIGHT_HAND_CLICK");
var rightTriggerAction = RIGHT_HAND_CLICK;
@ -41,7 +42,7 @@ var INTERSECT_COLOR = {
blue: 10
};
var GRAB_RADIUS = 0.5;
var GRAB_RADIUS = 1.0;
var GRAB_COLOR = {
red: 250,
@ -135,7 +136,8 @@ controller.prototype.checkForIntersections = function(origin, direction) {
var intersection = Entities.findRayIntersection(pickRay, true);
if (intersection.intersects && intersection.properties.collisionsWillMove === 1) {
this.distanceToEntity = Vec3.distance(origin, intersection.properties.position);
var handPosition = Controller.getSpatialControlPosition(this.palm);
this.distanceToEntity = Vec3.distance(handPosition, intersection.properties.position);
Entities.editEntity(this.pointer, {
linePoints: [
ZERO_VEC,
@ -236,19 +238,24 @@ controller.prototype.update = function() {
controller.prototype.grabEntity = function() {
var handRotation = this.getHandRotation();
var handPosition = this.getHandPosition();
var objectRotation = Entities.getEntityProperties(this.grabbedEntity).rotation;
var offsetRotation = Quat.multiply(Quat.inverse(handRotation), objectRotation);
var objectPosition = Entities.getEntityProperties(this.grabbedEntity).position;
var offset = Vec3.subtract(objectPosition, handPosition);
var offsetPosition = Vec3.multiplyQbyV(Quat.inverse(Quat.multiply(handRotation, offsetRotation)), offset);
this.closeGrabbing = true;
//check if our entity has instructions on how to be grabbed, otherwise, just use default relative position and rotation
var userData = getEntityUserData(this.grabbedEntity);
var relativePosition = ZERO_VEC;
var relativeRotation = Quat.fromPitchYawRollDegrees(0, 0, 0);
if(userData.spatialKey) {
if(userData.spatialKey.relativePosition) {
relativePosition = userData.spatialKey.relativePosition;
}
if(userData.spatialKey.relativeRotation) {
relativeRotation = userData.spatialKey.relativeRotation;
}
}
this.actionID = Entities.addAction("hold", this.grabbedEntity, {
relativePosition: offsetPosition,
relativeRotation: offsetRotation,
hand: this.hand,
timeScale: 0.05
timeScale: 0.05,
relativePosition: relativePosition,
relativeRotation: relativeRotation
});
}
@ -305,10 +312,10 @@ controller.prototype.onActionEvent = function(action, state) {
self.checkForEntityArrival = true;
}, 500);
var handPosition = Controller.getSpatialControlPosition(this.palm);
var direction = Controller.getSpatialControlNormal(this.tip);
var direction = Vec3.normalize(Controller.getSpatialControlNormal(this.tip));
//move final destination along line a bit, so it doesnt hit avatar hand
Entities.updateAction(this.grabbedEntity, this.actionID, {
targetPosition: Vec3.sum(handPosition, Vec3.multiply(2, direction))
targetPosition: Vec3.sum(handPosition, Vec3.multiply(3, direction))
});
}
}
@ -339,8 +346,6 @@ function cleanup() {
leftController.cleanup();
}
Script.scriptEnding.connect(cleanup);
Script.update.connect(update)
Controller.actionEvent.connect(onActionEvent);

View file

@ -1,16 +1,6 @@
//
// sprayPaintCan.js
// examples/entityScripts
//
// Created by Eric Levin on 9/3/15
// Copyright 2015 High Fidelity, Inc.
//
// This is an example of an entity script for painting with a spraypaint can
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
(function() {
Script.include("../libraries/utils.js");
SPATIAL_USER_DATA_KEY = "spatialKey";
this.userData = {};
var TIP_OFFSET_Z = 0.14;
@ -36,6 +26,8 @@
});
this.getUserData = function() {
if (this.properties.userData) {
this.userData = JSON.parse(this.properties.userData);
}
@ -50,8 +42,7 @@
this.update = function(deltaTime) {
self.properties = Entities.getEntityProperties(self.entityId);
self.getUserData();
//Only run the logic if this is the client whose avatar is grabbing
if (self.userData.grabKey && self.userData.grabKey.activated === true && self.userData.grabKey.avatarId === MyAvatar.sessionUUID) {
if (self.userData.grabKey && self.userData.grabKey.activated === true) {
if (self.activated !== true) {
Entities.editEntity(self.paintStream, {
animationSettings: startSetting
@ -70,6 +61,8 @@
this.sprayStream = function() {
var forwardVec = Quat.getFront(self.properties.rotation);
forwardVec = Vec3.multiplyQbyV(Quat.fromPitchYawRollDegrees(0, 90, 0), forwardVec);
var upVec = Quat.getUp(self.properties.rotation);
var position = Vec3.sum(self.properties.position, Vec3.multiply(forwardVec, TIP_OFFSET_Z));
position = Vec3.sum(position, Vec3.multiply(upVec, TIP_OFFSET_Y))
@ -92,11 +85,12 @@
var normal = Vec3.multiply(-1, Quat.getFront(intersection.properties.rotation));
this.paint(intersection.intersection, normal);
}
}
this.paint = function(position, normal) {
if (!this.painting) {
print("position " + JSON.stringify(position))
this.newStroke(position);
this.painting = true;
@ -125,6 +119,7 @@
strokeWidths: this.strokeWidths
});
}
this.newStroke = function(position) {
@ -157,10 +152,16 @@
this.entityId = entityId;
this.properties = Entities.getEntityProperties(self.entityId);
this.getUserData();
print("USER DATA " + JSON.stringify(this.userData))
if (this.userData.activated) {
if (this.userData.grabKey && this.userData.grabKey.activated) {
this.activated = true;
}
if(!this.userData.spatialKey) {
var data = {
relativePosition: {x: 0, y: 0, z: 0},
relativeRotation: Quat.fromPitchYawRollDegrees(0, 0,0)
}
setEntityCustomData(SPATIAL_USER_DATA_KEY, this.entityId, data);
}
this.initialize();
}
@ -173,6 +174,7 @@
running: false
});
this.paintStream = Entities.addEntity({
type: "ParticleEffect",
animationSettings: animationSettings,