cleanup and fix script paths to get random movement working again

This commit is contained in:
James B. Pollack 2016-01-30 11:53:10 -08:00
parent 0e036d3e2c
commit 514edee3f1
11 changed files with 190 additions and 220 deletions

View file

@ -7,8 +7,16 @@ var spriteDimensions = {
var sprite;
var isMouseDown = false;
var RAD_TO_DEG = 180.0 / Math.PI;
var Y_AXIS = { x: 0, y: 1, z: 0 };
var X_AXIS = { x: 1, y: 0, z: 0 };
var Y_AXIS = {
x: 0,
y: 1,
z: 0
};
var X_AXIS = {
x: 1,
y: 0,
z: 0
};
function MakeSprite() {
sprite = Entities.addEntity({

View file

@ -1,5 +1,4 @@
function deleteAllInRadius (r)
{
function deleteAllInRadius(r) {
var n = 0;
var arrayFound = Entities.findEntities(MyAvatar.position, r);
for (var i = 0; i < arrayFound.length; i++) {

View file

@ -1,7 +1,6 @@
var scriptName = "Controller";
function findScriptsInRadius(r)
{
function findScriptsInRadius(r) {
var n = 0;
var arrayFound = Entities.findEntities(MyAvatar.position, r);
for (var i = 0; i < arrayFound.length; i++) {

View file

@ -28,7 +28,11 @@
self.posFrame = 0;
var magnitudeV = self.maxVelocity;
var directionV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
var directionV = {
x: Math.random() - 0.5,
y: Math.random() - 0.5,
z: Math.random() - 0.5
};
// print("POS magnitude is " + magnitudeV + " and direction is " + directionV.x);
Entities.editEntity(self.entityId, {
@ -45,7 +49,11 @@
var magnitudeAV = self.maxAngularVelocity;
var directionAV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
var directionAV = {
x: Math.random() - 0.5,
y: Math.random() - 0.5,
z: Math.random() - 0.5
};
// print("ROT magnitude is " + magnitudeAV + " and direction is " + directionAV.x);
Entities.editEntity(self.entityId, {
angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV))

View file

@ -1,49 +0,0 @@
(function(){
var self = this;
this.preload = function(entityId) {
this.entityId = entityId;
this.updateInterval = 30;
this.frame = 0;
this.minVelocity = 0.15;
this.maxVelocity = 0.35;
this.minAngularVelocity = 0.3;
this.maxAngularVelocity = 0.7;
}
this.update = function(deltaTime) {
self.frame++;
if (self.frame > self.updateInterval) {
self.updateInterval = 20 * Math.random() + 0;
self.frame = 0;
var magnitudeV = (self.maxVelocity - self.minVelocity) * Math.random() + self.minVelocity;
var magnitudeAV = (self.maxAngularVelocity - self.minAngularVelocity) * Math.random() + self.minAngularVelocity;
var directionV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
var directionAV = {x: Math.random() - 0.5, y: Math.random() - 0.5, z: Math.random() - 0.5};
Entities.editEntity(self.entityId, {
velocity: Vec3.multiply(magnitudeV, Vec3.normalize(directionV)),
angularVelocity: Vec3.multiply(magnitudeAV, Vec3.normalize(directionAV))
});
}
}
this.unload = function() {
Script.update.disconnect(this.update);
}
Script.update.connect(this.update);
})

View file

@ -1,6 +1,8 @@
setEntityUserData = function(id, data) {
var json = JSON.stringify(data)
Entities.editEntity(id, { userData: json });
Entities.editEntity(id, {
userData: json
});
}
// FIXME do non-destructive modification of the existing user data

View file

@ -21,12 +21,12 @@
volume: 0.5
};
this.teleportSound = SoundCache.getSound("https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/Audio/whoosh.wav");
print('JBP PRELOADING A ZOOM ENTITY')
//print('JBP PRELOADING A ZOOM ENTITY')
print(" portal destination is " + portalDestination);
}
this.enterEntity = function(entityID) {
print('ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID)
print('JBP ENTERED A BOUNDARY ENTITY, SHOULD ZOOM', entityID)
var data = JSON.parse(Entities.getEntityProperties(this.entityId).userData);
@ -50,11 +50,16 @@
this.lookAt = function(targetPosition, avatarPosition) {
var direction = Vec3.normalize(Vec3.subtract(MyAvatar.position, targetPosition));
var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, {x:1, y:0, z:0});
var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, {x:0, y:1, z:0});
// var rotation = Quat.multiply(yaw, pitch);
// MyAvatar.orientation = rotation;
var pitch = Quat.angleAxis(Math.asin(-direction.y) * 180.0 / Math.PI, {
x: 1,
y: 0,
z: 0
});
var yaw = Quat.angleAxis(Math.atan2(direction.x, direction.z) * 180.0 / Math.PI, {
x: 0,
y: 1,
z: 0
});
MyAvatar.goToLocation(avatarPosition, true, yaw);
MyAvatar.headYaw = 0;

View file

@ -1,4 +1,4 @@
var version = 1001;
var version = 1003;
var cellLayout;
var baseLocation = "https://hifi-content.s3.amazonaws.com/DomainContent/CellScience/";
@ -6,7 +6,9 @@ var utilsScript = Script.resolvePath('Scripts/utils.js');
Script.include(utilsScript);
function makeUngrabbable(entityID) {
setEntityCustomData('grabbableKey', entityID, {grabbable:false});
setEntityCustomData('grabbableKey', entityID, {
grabbable: false
});
}
Entities.addingEntity.connect(makeUngrabbable);
@ -70,9 +72,7 @@ var locations = {
}, 1000]
};
var scenes = [
{
name: "Cells",
objects: "",
@ -108,7 +108,7 @@ var scenes = [
},
radius: 500,
number: 10,
script: "moveRandomly",
script: "moveRandomly.js?" + version,
visible: true
}],
boundary: {
@ -182,7 +182,7 @@ var scenes = [
grabbable: false
}
}),
script: "moveRandomly",
script: "moveRandomly.js?" + version,
visible: true
}, { //golgi vesicles
model: "vesicle",
@ -226,7 +226,7 @@ var scenes = [
grabbable: false
}
}),
script: "moveRandomly",
script: "moveRandomly.js?" + version,
visible: true
}, {
model: "vesicle",
@ -292,7 +292,7 @@ var scenes = [
grabbable: false
}
}),
script: "moveRandomly",
script: "moveRandomly.js?" + version,
visible: true
}, { //outer vesicles
model: "vesicle",
@ -314,7 +314,7 @@ var scenes = [
grabbable: false
}
}),
script: "moveRandomly",
script: "moveRandomly.js?" + version,
visible: true
},
// {//wigglies
@ -594,6 +594,7 @@ function ImportScene(scene) {
}
clearAllNav();
function clearAllNav() {
// print('NAV CLEARING ALL NAV');
var result = Entities.findEntities(MyAvatar.position, 25000);
@ -605,6 +606,31 @@ function clearAllNav() {
}
})
}
function createLayoutLights() {
Entities.addEntity({
type: "Light",
name: "Cell layout light",
position: {
x: locations.cellLayout[0] + 110,
y: locations.cellLayout[0] + 160,
z: locations.cellLayout[0] + 785
},
dimensions: {
x: 1500,
y: 1500,
z: 1500
},
intensity: 2,
color: {
red: 240,
green: 165,
blue: 240
}
})
}
function CreateNavigationButton(scene, number) {
// print('NAV NAVIGATION CREATING NAV!!' +scene.name + " " + number)
@ -744,7 +770,6 @@ function CreateInstances(scene) {
var point = getPointOnSphereOfRadius(scene.instances[i].radius, j + 2, scene.instances[i].number);
// print(scene.name + " point is " + point.x + " " + point.y + " " + point.z);
var posX = scene.location.x + point.x + scene.instances[i].offset.x + Math.random() * (scene.instances[i].radius / 10);
var posY = scene.location.y + point.y + scene.instances[i].offset.y + Math.random() * (scene.instances[i].radius / 10);
var posZ = scene.location.z + point.z + scene.instances[i].offset.z + Math.random() * (scene.instances[i].radius / 10);
@ -754,13 +779,13 @@ function CreateInstances(scene) {
z: posZ
};
var url = baseLocation + "Instances/" + scene.instances[i].model + ".fbx?" + version;
var script = scene.instances[i].script + ".js?" + version;
var script = scene.instances[i].script;
var rotX = 360 * Math.random() - 180;
var rotY = 360 * Math.random() - 180;
var rotZ = 360 * Math.random() - 180;
var rotation = Quat.fromPitchYawRollDegrees(rotX, rotY, rotZ);
var dimensions;
if (scene.instances[i].script == "") {
if (scene.instances[i].script === "") {
script = "";
}
//is there a smarter way to randomize size?
@ -780,7 +805,7 @@ function CreateInstances(scene) {
}, idBounds, 150);
}
print('JBP SCRIPT AT CREATE ENTITY: ' + script)
CreateEntity(scene.instances[i].model, position, rotation, scene.instances[i].dimensions, url, script, scene.instances[i].userData, scene.instances[i].visible);
}
}
@ -876,12 +901,13 @@ function getPointOnSphereOfRadius(radius, number, totalNumber) {
function CreateEntity(name, position, rotation, dimensions, url, script, userData, visible) {
var scriptLocation;
if (script == "") {
if (script === "") {
scriptLocation = "";
} else {
scriptLocation = baseLocation + "Scripts/" + script;
}
print('JBP SCRIPT LOCATION IN CREATE ENTITY' + scriptLocation)
Entities.addEntity({
type: "Model",
name: name,
@ -9020,35 +9046,7 @@ for (var i = 0; i < scenes.length; i++) {
CreateNavigationButton(scenes[i], i);
}
//Entities.addEntity({
// type: "Box",
// name: "motorProteinController",
// position: {x:4000, y:4000, z:4000},
// color: {red: 200, green: 0, blue: 0},
// script: baseLocation + "Scripts/motorProteinController.js?"+version,
// visible: false
//});
Entities.addEntity({
type: "Light",
name: "Cell layout light",
position: {
x: locations.cellLayout[0] + 110,
y: locations.cellLayout[0] + 160,
z: locations.cellLayout[0] + 785
},
dimensions: {
x: 1500,
y: 1500,
z: 1500
},
intensity: 2,
color: {
red: 240,
green: 165,
blue: 240
}
})
createLayoutLights();
Script.scriptEnding.connect(function() {
Entities.addingEntity.disconnect(makeUngrabbable);