content/hifi-content/thoys/dev/2017/whackAMole/helpers.js
2022-02-14 02:04:11 +01:00

51 lines
1.8 KiB
JavaScript

//
// whackAMole/helpers.js
//
// Created by Thijs Wenker on 5/10/17.
// Copyright 2017 High Fidelity, Inc.
//
// Distributed under the Apache License, Version 2.0.
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
//
/* global module */
// @module helpers
var constants = Script.require('./constants.js');
module.exports = {
getModelURL: function(file) {
return Script.resolvePath('models/' + file);
},
getSoundURL: function(file) {
return Script.resolvePath('sounds/' + file);
},
debugPrint: function(message) {
if (constants.DEBUG) {
print(message);
}
},
// Creates an entity and returns a mixed object of the creation properties and the assigned entityID
createEntity: function(entityProperties, parent) {
if (parent.rotation !== undefined) {
if (entityProperties.rotation !== undefined) {
entityProperties.rotation = Quat.multiply(parent.rotation, entityProperties.rotation);
} else {
entityProperties.rotation = parent.rotation;
}
}
if (parent.position !== undefined) {
var localPosition = (parent.rotation !== undefined) ?
Vec3.multiplyQbyV(parent.rotation, entityProperties.position) : entityProperties.position;
entityProperties.position = Vec3.sum(localPosition, parent.position);
}
if (parent.id !== undefined) {
entityProperties.parentID = parent.id;
}
entityProperties.id = Entities.addEntity(entityProperties);
return entityProperties;
},
mix: function(min, max, percentage) {
return ((max - min) * percentage) + min;
}
};