mirror of
https://github.com/overte-org/overte.git
synced 2025-08-09 11:28:03 +02:00
premeeting
This commit is contained in:
parent
13157e34a4
commit
ab17a95d71
3 changed files with 114 additions and 77 deletions
|
@ -1,37 +0,0 @@
|
||||||
//
|
|
||||||
// ballDetector.js
|
|
||||||
//
|
|
||||||
// Script Type: Entity
|
|
||||||
//
|
|
||||||
// Created by James B. Pollack @imgntn on 2/15/2016
|
|
||||||
// Copyright 2016 High Fidelity, Inc.
|
|
||||||
//
|
|
||||||
//
|
|
||||||
// This script resets a ball to its original position when the ball enters it.
|
|
||||||
//
|
|
||||||
// Distributed under the Apache License, Version 2.0.
|
|
||||||
// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html
|
|
||||||
//
|
|
||||||
(function() {
|
|
||||||
var BALL_DISTANCE_THRESHOLD;
|
|
||||||
var _this;
|
|
||||||
|
|
||||||
function BallDetctor() {
|
|
||||||
_this = this;
|
|
||||||
return;
|
|
||||||
}
|
|
||||||
|
|
||||||
BallDetctor.prototype = {
|
|
||||||
preload:function(entityID){
|
|
||||||
this.entityID = entityID,
|
|
||||||
this.maze = Entities.getEntityProperties(entityID,'parentID').parentID;
|
|
||||||
},
|
|
||||||
enterEntity: function() {
|
|
||||||
print('BALL ENTERED BALL DETECTOR!!')
|
|
||||||
Entities.callEntityMethod(this.maze,'destroyBall');
|
|
||||||
Entities.callEntityMethod(this.maze,'createBall');
|
|
||||||
}
|
|
||||||
};
|
|
||||||
|
|
||||||
return new BallDetctor();
|
|
||||||
});
|
|
|
@ -1,15 +1,16 @@
|
||||||
var ball, ballSpawningAnchor, ballDetector, tiltMaze;
|
var ball, ballSpawningAnchor, ballDetector, tiltMaze;
|
||||||
|
|
||||||
var MAZE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/MAZE3.fbx";
|
var MAZE_MODEL_URL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/MAZE4.fbx";
|
||||||
var MAZE_COLLISION_HULL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/MAZE_COLLISION_HULL8.obj";
|
var MAZE_COLLISION_HULL = "http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/MAZE_COLLISION_HULL8.obj";
|
||||||
var MAZE_SCRIPT = Script.resolvePath('maze.js?'+Math.random());
|
var MAZE_SCRIPT = Script.resolvePath('maze.js?' + Math.random());
|
||||||
var BALL_DETECTOR_SCRIPT = Script.resolvePath('ballDetector.js?' + Math.random())
|
|
||||||
|
|
||||||
var MAZE_DIMENSIONS = {
|
var SCALE = 1;
|
||||||
|
|
||||||
|
var MAZE_DIMENSIONS = Vec3.multiply(SCALE,{
|
||||||
x: 1,
|
x: 1,
|
||||||
y: 0.3,
|
y: 0.3,
|
||||||
z: 1
|
z: 1
|
||||||
};
|
});
|
||||||
|
|
||||||
var BALL_DIMENSIONS = {
|
var BALL_DIMENSIONS = {
|
||||||
x: 0.05,
|
x: 0.05,
|
||||||
|
@ -24,9 +25,9 @@
|
||||||
}
|
}
|
||||||
|
|
||||||
var BALL_DETECTOR_DIMENSIONS = {
|
var BALL_DETECTOR_DIMENSIONS = {
|
||||||
x: 1,
|
x: 0.1,
|
||||||
y: 0.15,
|
y: 0.1,
|
||||||
z: 1,
|
z: 0.1
|
||||||
}
|
}
|
||||||
|
|
||||||
var BALL_COLOR = {
|
var BALL_COLOR = {
|
||||||
|
@ -71,7 +72,9 @@
|
||||||
var MAZE_DAMPING = 0.6;
|
var MAZE_DAMPING = 0.6;
|
||||||
var MAZE_ANGULAR_DAMPING = 0.6;
|
var MAZE_ANGULAR_DAMPING = 0.6;
|
||||||
|
|
||||||
var DETECTOR_VERTICAL_OFFSET = MAZE_DIMENSIONS.y / 2;
|
var DETECTOR_VERTICAL_OFFSET = 0.0;
|
||||||
|
var DETECTOR_FORWARD_OFFSET= 0.4;
|
||||||
|
var DETECTOR_RIGHT_OFFSET = 0.4;
|
||||||
|
|
||||||
var getBallStartLocation = function() {
|
var getBallStartLocation = function() {
|
||||||
var mazeProps = Entities.getEntityProperties(tiltMaze);
|
var mazeProps = Entities.getEntityProperties(tiltMaze);
|
||||||
|
@ -106,7 +109,7 @@
|
||||||
gravity: BALL_GRAVITY,
|
gravity: BALL_GRAVITY,
|
||||||
density: BALL_DENSITY,
|
density: BALL_DENSITY,
|
||||||
color: BALL_COLOR,
|
color: BALL_COLOR,
|
||||||
dimensions:BALL_DIMENSIONS
|
dimensions: BALL_DIMENSIONS
|
||||||
|
|
||||||
};
|
};
|
||||||
|
|
||||||
|
@ -117,6 +120,7 @@
|
||||||
};
|
};
|
||||||
|
|
||||||
var createBallSpawningAnchor = function() {
|
var createBallSpawningAnchor = function() {
|
||||||
|
|
||||||
var properties = {
|
var properties = {
|
||||||
name: 'Hifi Tilt Maze Ball Detector',
|
name: 'Hifi Tilt Maze Ball Detector',
|
||||||
parentID: tiltMaze,
|
parentID: tiltMaze,
|
||||||
|
@ -125,14 +129,22 @@
|
||||||
dimensions: BALL_SPAWNER_DIMENSIONS,
|
dimensions: BALL_SPAWNER_DIMENSIONS,
|
||||||
position: getBallStartLocation(),
|
position: getBallStartLocation(),
|
||||||
collisionless: true,
|
collisionless: true,
|
||||||
visible: true,
|
visible: false,
|
||||||
script: BALL_DETECTOR_SCRIPT
|
script: BALL_DETECTOR_SCRIPT
|
||||||
};
|
};
|
||||||
|
|
||||||
ballSpawningAnchor = Entities.addEntity(properties);
|
ballSpawningAnchor = Entities.addEntity(properties);
|
||||||
}
|
}
|
||||||
|
|
||||||
var createBallDetector = function(position, rotation) {
|
var createBallDetector = function() {
|
||||||
|
var mazeProps = Entities.getEntityProperties(tiltMaze);
|
||||||
|
var right = Quat.getRight(mazeProps.rotation);
|
||||||
|
var forward = Quat.getFront(mazeProps.rotation);
|
||||||
|
var up = Quat.getUp(mazeProps.rotation);
|
||||||
|
|
||||||
|
var position = Vec3.sum(mazeProps.position,Vec3.multiply(up,DETECTOR_VERTICAL_OFFSET));
|
||||||
|
position = Vec3.sum(position,Vec3.multiply(right,DETECTOR_RIGHT_OFFSET));
|
||||||
|
position = Vec3.sum(position,Vec3.multiply(forward,DETECTOR_FORWARD_OFFSET));
|
||||||
var properties = {
|
var properties = {
|
||||||
name: 'Hifi Tilt Maze Ball Detector',
|
name: 'Hifi Tilt Maze Ball Detector',
|
||||||
parentID: tiltMaze,
|
parentID: tiltMaze,
|
||||||
|
@ -140,11 +152,9 @@
|
||||||
color: DEBUG_COLOR,
|
color: DEBUG_COLOR,
|
||||||
dimensions: BALL_DETECTOR_DIMENSIONS,
|
dimensions: BALL_DETECTOR_DIMENSIONS,
|
||||||
position: position,
|
position: position,
|
||||||
rotiation: rotation,
|
|
||||||
collisionless: true,
|
collisionless: true,
|
||||||
dynamic:false,
|
dynamic: false,
|
||||||
visible: true,
|
visible: false,
|
||||||
script: BALL_DETECTOR_SCRIPT
|
|
||||||
};
|
};
|
||||||
|
|
||||||
ballDetector = Entities.addEntity(properties);
|
ballDetector = Entities.addEntity(properties);
|
||||||
|
@ -160,12 +170,12 @@
|
||||||
dimensions: MAZE_DIMENSIONS,
|
dimensions: MAZE_DIMENSIONS,
|
||||||
position: position,
|
position: position,
|
||||||
restitution: MAZE_RESTITUTION,
|
restitution: MAZE_RESTITUTION,
|
||||||
damping:MAZE_DAMPING,
|
damping: MAZE_DAMPING,
|
||||||
angularDamping:MAZE_ANGULAR_DAMPING,
|
angularDamping: MAZE_ANGULAR_DAMPING,
|
||||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 180),
|
rotation: Quat.fromPitchYawRollDegrees(0, 0, 180),
|
||||||
dynamic: true,
|
dynamic: true,
|
||||||
density: MAZE_DENSITY,
|
density: MAZE_DENSITY,
|
||||||
script:MAZE_SCRIPT
|
script: MAZE_SCRIPT
|
||||||
}
|
}
|
||||||
|
|
||||||
tiltMaze = Entities.addEntity(properties)
|
tiltMaze = Entities.addEntity(properties)
|
||||||
|
@ -174,14 +184,15 @@
|
||||||
|
|
||||||
var createAll = function() {
|
var createAll = function() {
|
||||||
createTiltMaze(center);
|
createTiltMaze(center);
|
||||||
createBallSpawningAnchor();
|
createBallSpawningAnchor();
|
||||||
// createBallDetector();
|
createBallDetector(center);
|
||||||
createBall(center);
|
createBall(center);
|
||||||
Entities.editEntity(tiltMaze,{
|
Entities.editEntity(tiltMaze, {
|
||||||
userData:JSON.stringify({
|
userData: JSON.stringify({
|
||||||
tiltMaze:{
|
tiltMaze: {
|
||||||
firstBall:ball,
|
firstBall: ball,
|
||||||
ballSpawner:ballSpawningAnchor
|
ballSpawner: ballSpawningAnchor,
|
||||||
|
detector:ballDetector
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
})
|
})
|
||||||
|
@ -194,5 +205,6 @@
|
||||||
Entities.deleteEntity(tiltMaze);
|
Entities.deleteEntity(tiltMaze);
|
||||||
Entities.deleteEntity(ball);
|
Entities.deleteEntity(ball);
|
||||||
Entities.deleteEntity(ballSpawningAnchor);
|
Entities.deleteEntity(ballSpawningAnchor);
|
||||||
|
Entities.deleteEntity(ballDetector);
|
||||||
})
|
})
|
||||||
};
|
};
|
|
@ -14,9 +14,12 @@
|
||||||
//
|
//
|
||||||
(function() {
|
(function() {
|
||||||
|
|
||||||
Script.include('../../../../libraries/utils.js')
|
Script.include('../../../../libraries/utils.js');
|
||||||
|
|
||||||
|
var VICTORY_SOUND;
|
||||||
var BALL_DISTANCE_THRESHOLD = 1;
|
var BALL_DISTANCE_THRESHOLD = 1;
|
||||||
|
|
||||||
|
var BALL_DETECTOR_THRESHOLD = 0.2;
|
||||||
var BALL_FORWARD_OFFSET = -0.2;
|
var BALL_FORWARD_OFFSET = -0.2;
|
||||||
var BALL_RIGHT_OFFSET = -0.4;
|
var BALL_RIGHT_OFFSET = -0.4;
|
||||||
var BALL_VERTICAL_OFFSET = 0.02;
|
var BALL_VERTICAL_OFFSET = 0.02;
|
||||||
|
@ -52,25 +55,31 @@
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
print('jbp test')
|
||||||
|
|
||||||
Maze.prototype = {
|
Maze.prototype = {
|
||||||
ball: null,
|
ball: null,
|
||||||
|
ballLocked: false,
|
||||||
preload: function(entityID) {
|
preload: function(entityID) {
|
||||||
this.entityID = entityID;
|
this.entityID = entityID;
|
||||||
|
VICTORY_SOUND = SoundCache.getSound("http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/levelUp.wav");
|
||||||
},
|
},
|
||||||
|
|
||||||
startNearGrab: function() {
|
startNearGrab: function() {
|
||||||
//check to make sure a ball is in range, otherwise create one
|
//check to make sure a ball is in range, otherwise create one
|
||||||
},
|
},
|
||||||
continueNearGrab: function() {
|
continueNearGrab: function() {
|
||||||
|
print('near grab')
|
||||||
|
// this.testWinDistance();
|
||||||
this.testBallDistance();
|
this.testBallDistance();
|
||||||
},
|
},
|
||||||
continueDistantGrab: function() {
|
continueDistantGrab: function() {
|
||||||
|
print('distant grab')
|
||||||
this.testBallDistance();
|
this.testBallDistance();
|
||||||
|
this.testWinDistance();
|
||||||
},
|
},
|
||||||
releaseGrab: function() {
|
releaseGrab: function() {
|
||||||
this.testBallDistance();
|
this.testBallDistance();
|
||||||
|
// this.testWinDistance();
|
||||||
},
|
},
|
||||||
getBallStartLocation: function() {
|
getBallStartLocation: function() {
|
||||||
var mazeProps = Entities.getEntityProperties(this.entityID);
|
var mazeProps = Entities.getEntityProperties(this.entityID);
|
||||||
|
@ -89,6 +98,9 @@
|
||||||
return location;
|
return location;
|
||||||
},
|
},
|
||||||
createBall: function() {
|
createBall: function() {
|
||||||
|
if (this.ballLocked === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
print('making ball')
|
print('making ball')
|
||||||
var properties = {
|
var properties = {
|
||||||
name: 'Hifi Tilt Maze Ball',
|
name: 'Hifi Tilt Maze Ball',
|
||||||
|
@ -114,17 +126,16 @@
|
||||||
res.forEach(function(r) {
|
res.forEach(function(r) {
|
||||||
var props = Entities.getEntityProperties(r, ['name']);
|
var props = Entities.getEntityProperties(r, ['name']);
|
||||||
var isAMazeBall = props.name.indexOf('Maze Ball');
|
var isAMazeBall = props.name.indexOf('Maze Ball');
|
||||||
print('found a maze ball at destory ' + isAMazeBall)
|
|
||||||
print('JBP R ' +r )
|
|
||||||
print('JBP THIS BALL' + _this.ball)
|
|
||||||
if (isAMazeBall > -1 && r === _this.ball) {
|
if (isAMazeBall > -1 && r === _this.ball) {
|
||||||
print('found a ball to delete')
|
|
||||||
Entities.deleteEntity(r);
|
Entities.deleteEntity(r);
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
},
|
},
|
||||||
testBallDistance: function() {
|
testBallDistance: function() {
|
||||||
|
if (this.ballLocked === true) {
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
print('test ball dsitance')
|
||||||
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
||||||
var data = null;
|
var data = null;
|
||||||
try {
|
try {
|
||||||
|
@ -149,17 +160,68 @@
|
||||||
var ballSpawnerPosition = Entities.getEntityProperties(data.tiltMaze.ballSpawner, 'position').position;
|
var ballSpawnerPosition = Entities.getEntityProperties(data.tiltMaze.ballSpawner, 'position').position;
|
||||||
|
|
||||||
var separation = Vec3.distance(ballPosition, ballSpawnerPosition);
|
var separation = Vec3.distance(ballPosition, ballSpawnerPosition);
|
||||||
print('testing ball distance:::' + separation)
|
|
||||||
if (separation > BALL_DISTANCE_THRESHOLD) {
|
if (separation > BALL_DISTANCE_THRESHOLD) {
|
||||||
|
print('BALL TOO FAR MAKE A NEW ONE')
|
||||||
this.destroyBall();
|
this.destroyBall();
|
||||||
this.createBall();
|
this.createBall();
|
||||||
} else {
|
} else {
|
||||||
|
|
||||||
}
|
}
|
||||||
},
|
},
|
||||||
playVictorySound:function(){
|
testWinDistance: function() {
|
||||||
|
if (this.ballLocked === true) {
|
||||||
}
|
return;
|
||||||
|
}
|
||||||
|
print('testing win distance')
|
||||||
|
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
||||||
|
var data = null;
|
||||||
|
try {
|
||||||
|
data = JSON.parse(userData)
|
||||||
|
} catch (e) {
|
||||||
|
print('error parsing json in maze userdata')
|
||||||
|
}
|
||||||
|
if (data === null) {
|
||||||
|
print('data is null in userData')
|
||||||
|
return;
|
||||||
|
}
|
||||||
|
|
||||||
|
var ballPosition;
|
||||||
|
if (this.ball === null) {
|
||||||
|
this.ball = data.tiltMaze.firstBall;
|
||||||
|
ballPosition = Entities.getEntityProperties(data.tiltMaze.firstBall, 'position').position;
|
||||||
|
|
||||||
|
} else {
|
||||||
|
ballPosition = Entities.getEntityProperties(this.ball, 'position').position
|
||||||
|
}
|
||||||
|
|
||||||
|
var ballDetectorPosition = Entities.getEntityProperties(data.tiltMaze.detector, 'position').position;
|
||||||
|
|
||||||
|
var separation = Vec3.distance(ballPosition, ballDetectorPosition);
|
||||||
|
print('separation from win:' + separation)
|
||||||
|
if (separation < BALL_DETECTOR_THRESHOLD) {
|
||||||
|
print('BALL IS IN DETECTOR, MAKE A NEW ONE')
|
||||||
|
this.ballLocked = true;
|
||||||
|
this.destroyBall();
|
||||||
|
this.playVictorySound();
|
||||||
|
Script.setTimeout(function() {
|
||||||
|
_this.ballLocked = false;
|
||||||
|
_this.createBall()
|
||||||
|
}, 1500)
|
||||||
|
} else {
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
},
|
||||||
|
playVictorySound: function() {
|
||||||
|
var position = Entities.getEntityProperties(this.entityID, "position").position;
|
||||||
|
|
||||||
|
var audioProperties = {
|
||||||
|
volume: 0.25,
|
||||||
|
position: position
|
||||||
|
};
|
||||||
|
Audio.playSound(VICTORY_SOUND, audioProperties);
|
||||||
|
|
||||||
|
},
|
||||||
};
|
};
|
||||||
|
|
||||||
return new Maze();
|
return new Maze();
|
||||||
|
|
Loading…
Reference in a new issue