mirror of
https://github.com/overte-org/overte.git
synced 2025-04-20 04:44:11 +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 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_SCRIPT = Script.resolvePath('maze.js?'+Math.random());
|
||||
var BALL_DETECTOR_SCRIPT = Script.resolvePath('ballDetector.js?' + Math.random())
|
||||
var MAZE_SCRIPT = Script.resolvePath('maze.js?' + Math.random());
|
||||
|
||||
var MAZE_DIMENSIONS = {
|
||||
var SCALE = 1;
|
||||
|
||||
var MAZE_DIMENSIONS = Vec3.multiply(SCALE,{
|
||||
x: 1,
|
||||
y: 0.3,
|
||||
z: 1
|
||||
};
|
||||
});
|
||||
|
||||
var BALL_DIMENSIONS = {
|
||||
x: 0.05,
|
||||
|
@ -24,9 +25,9 @@
|
|||
}
|
||||
|
||||
var BALL_DETECTOR_DIMENSIONS = {
|
||||
x: 1,
|
||||
y: 0.15,
|
||||
z: 1,
|
||||
x: 0.1,
|
||||
y: 0.1,
|
||||
z: 0.1
|
||||
}
|
||||
|
||||
var BALL_COLOR = {
|
||||
|
@ -71,7 +72,9 @@
|
|||
var MAZE_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 mazeProps = Entities.getEntityProperties(tiltMaze);
|
||||
|
@ -106,7 +109,7 @@
|
|||
gravity: BALL_GRAVITY,
|
||||
density: BALL_DENSITY,
|
||||
color: BALL_COLOR,
|
||||
dimensions:BALL_DIMENSIONS
|
||||
dimensions: BALL_DIMENSIONS
|
||||
|
||||
};
|
||||
|
||||
|
@ -117,6 +120,7 @@
|
|||
};
|
||||
|
||||
var createBallSpawningAnchor = function() {
|
||||
|
||||
var properties = {
|
||||
name: 'Hifi Tilt Maze Ball Detector',
|
||||
parentID: tiltMaze,
|
||||
|
@ -125,14 +129,22 @@
|
|||
dimensions: BALL_SPAWNER_DIMENSIONS,
|
||||
position: getBallStartLocation(),
|
||||
collisionless: true,
|
||||
visible: true,
|
||||
visible: false,
|
||||
script: BALL_DETECTOR_SCRIPT
|
||||
};
|
||||
|
||||
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 = {
|
||||
name: 'Hifi Tilt Maze Ball Detector',
|
||||
parentID: tiltMaze,
|
||||
|
@ -140,11 +152,9 @@
|
|||
color: DEBUG_COLOR,
|
||||
dimensions: BALL_DETECTOR_DIMENSIONS,
|
||||
position: position,
|
||||
rotiation: rotation,
|
||||
collisionless: true,
|
||||
dynamic:false,
|
||||
visible: true,
|
||||
script: BALL_DETECTOR_SCRIPT
|
||||
dynamic: false,
|
||||
visible: false,
|
||||
};
|
||||
|
||||
ballDetector = Entities.addEntity(properties);
|
||||
|
@ -160,12 +170,12 @@
|
|||
dimensions: MAZE_DIMENSIONS,
|
||||
position: position,
|
||||
restitution: MAZE_RESTITUTION,
|
||||
damping:MAZE_DAMPING,
|
||||
angularDamping:MAZE_ANGULAR_DAMPING,
|
||||
damping: MAZE_DAMPING,
|
||||
angularDamping: MAZE_ANGULAR_DAMPING,
|
||||
rotation: Quat.fromPitchYawRollDegrees(0, 0, 180),
|
||||
dynamic: true,
|
||||
density: MAZE_DENSITY,
|
||||
script:MAZE_SCRIPT
|
||||
script: MAZE_SCRIPT
|
||||
}
|
||||
|
||||
tiltMaze = Entities.addEntity(properties)
|
||||
|
@ -174,14 +184,15 @@
|
|||
|
||||
var createAll = function() {
|
||||
createTiltMaze(center);
|
||||
createBallSpawningAnchor();
|
||||
// createBallDetector();
|
||||
createBall(center);
|
||||
Entities.editEntity(tiltMaze,{
|
||||
userData:JSON.stringify({
|
||||
tiltMaze:{
|
||||
firstBall:ball,
|
||||
ballSpawner:ballSpawningAnchor
|
||||
createBallSpawningAnchor();
|
||||
createBallDetector(center);
|
||||
createBall(center);
|
||||
Entities.editEntity(tiltMaze, {
|
||||
userData: JSON.stringify({
|
||||
tiltMaze: {
|
||||
firstBall: ball,
|
||||
ballSpawner: ballSpawningAnchor,
|
||||
detector:ballDetector
|
||||
}
|
||||
})
|
||||
})
|
||||
|
@ -194,5 +205,6 @@
|
|||
Entities.deleteEntity(tiltMaze);
|
||||
Entities.deleteEntity(ball);
|
||||
Entities.deleteEntity(ballSpawningAnchor);
|
||||
Entities.deleteEntity(ballDetector);
|
||||
})
|
||||
};
|
|
@ -14,9 +14,12 @@
|
|||
//
|
||||
(function() {
|
||||
|
||||
Script.include('../../../../libraries/utils.js')
|
||||
Script.include('../../../../libraries/utils.js');
|
||||
|
||||
var VICTORY_SOUND;
|
||||
var BALL_DISTANCE_THRESHOLD = 1;
|
||||
|
||||
var BALL_DETECTOR_THRESHOLD = 0.2;
|
||||
var BALL_FORWARD_OFFSET = -0.2;
|
||||
var BALL_RIGHT_OFFSET = -0.4;
|
||||
var BALL_VERTICAL_OFFSET = 0.02;
|
||||
|
@ -52,25 +55,31 @@
|
|||
return;
|
||||
}
|
||||
|
||||
print('jbp test')
|
||||
|
||||
Maze.prototype = {
|
||||
ball: null,
|
||||
ballLocked: false,
|
||||
preload: function(entityID) {
|
||||
this.entityID = entityID;
|
||||
VICTORY_SOUND = SoundCache.getSound("http://hifi-content.s3.amazonaws.com/DomainContent/Home/tiltMaze/levelUp.wav");
|
||||
},
|
||||
|
||||
startNearGrab: function() {
|
||||
//check to make sure a ball is in range, otherwise create one
|
||||
},
|
||||
continueNearGrab: function() {
|
||||
|
||||
print('near grab')
|
||||
// this.testWinDistance();
|
||||
this.testBallDistance();
|
||||
},
|
||||
continueDistantGrab: function() {
|
||||
|
||||
print('distant grab')
|
||||
this.testBallDistance();
|
||||
this.testWinDistance();
|
||||
},
|
||||
releaseGrab: function() {
|
||||
this.testBallDistance();
|
||||
// this.testWinDistance();
|
||||
},
|
||||
getBallStartLocation: function() {
|
||||
var mazeProps = Entities.getEntityProperties(this.entityID);
|
||||
|
@ -89,6 +98,9 @@
|
|||
return location;
|
||||
},
|
||||
createBall: function() {
|
||||
if (this.ballLocked === true) {
|
||||
return;
|
||||
}
|
||||
print('making ball')
|
||||
var properties = {
|
||||
name: 'Hifi Tilt Maze Ball',
|
||||
|
@ -114,17 +126,16 @@
|
|||
res.forEach(function(r) {
|
||||
var props = Entities.getEntityProperties(r, ['name']);
|
||||
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) {
|
||||
print('found a ball to delete')
|
||||
Entities.deleteEntity(r);
|
||||
}
|
||||
})
|
||||
},
|
||||
testBallDistance: function() {
|
||||
|
||||
if (this.ballLocked === true) {
|
||||
return;
|
||||
}
|
||||
print('test ball dsitance')
|
||||
var userData = Entities.getEntityProperties(this.entityID, 'userData').userData;
|
||||
var data = null;
|
||||
try {
|
||||
|
@ -149,17 +160,68 @@
|
|||
var ballSpawnerPosition = Entities.getEntityProperties(data.tiltMaze.ballSpawner, 'position').position;
|
||||
|
||||
var separation = Vec3.distance(ballPosition, ballSpawnerPosition);
|
||||
print('testing ball distance:::' + separation)
|
||||
if (separation > BALL_DISTANCE_THRESHOLD) {
|
||||
print('BALL TOO FAR MAKE A NEW ONE')
|
||||
this.destroyBall();
|
||||
this.createBall();
|
||||
} 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();
|
||||
|
|
Loading…
Reference in a new issue