Make the flashlight grab frame work correctly

This commit is contained in:
Sam Gateau 2015-09-10 15:30:50 -07:00
parent 38fcb80135
commit d0592d562c

View file

@ -16,10 +16,11 @@
(function() {
function debugPrint(message) {
// print(message);
print(message);
}
Script.include("../../libraries/utils.js");
//Script.include("../../libraries/utils.js");
Script.include("https://hifi-public.s3.amazonaws.com/scripts/libraries/utils.js");
var _this;
@ -31,6 +32,15 @@
_this._spotlight = null;
};
GRAB_FRAME_USER_DATA_KEY = "grabFrame";
// These constants define the Flashlight model Grab Frame
var MODEL_GRAB_FRAME = {
relativePosition: {x: 0, y: -0.1, z: 0},
relativeRotation: Quat.angleAxis(180, {x: 1, y: 0, z: 0})
};
// These constants define the Spotlight position and orientation relative to the model
var MODEL_LIGHT_POSITION = {x: 0, y: 0, z: 0};
var MODEL_LIGHT_ROTATION = Quat.angleAxis (-90, {x: 1, y: 0, z: 0});
@ -43,6 +53,8 @@
Flashlight.prototype = {
// update() will be called regulary, because we've hooked the update signal in our preload() function
// we will check out userData for the grabData. In the case of the hydraGrab script, it will tell us
// if we're currently being grabbed and if the person grabbing us is the current interfaces avatar.
@ -126,11 +138,20 @@
// * connecting to the update signal so we can check our grabbed state
preload: function(entityID) {
_this.entityID = entityID;
var modelProperties = Entities.getEntityProperties(entityID);
_this._startModelPosition = modelProperties.position;
_this._startModelRotation = modelProperties.rotation;
// Make sure the Flashlight entity has a correct grab frame setup
var userData = getEntityUserData(entityID);
debugPrint(JSON.stringify(userData));
if (!userData.grabFrame) {
setEntityCustomData(GRAB_FRAME_USER_DATA_KEY, entityID, MODEL_GRAB_FRAME);
debugPrint(JSON.stringify(MODEL_GRAB_FRAME));
debugPrint("Assigned the grab frmae for the Flashlight entity");
}
Script.update.connect(this.update);
},