From 41b2f82be57318e8de832f44904b6ed158f0c0f9 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 5 Oct 2015 17:43:44 -0700 Subject: [PATCH] midway --- examples/toys/basketball.js | 62 +++++---- examples/toys/basketball_hoop/createHoop.js | 1 - examples/toys/basketball_hoop/createRack.js | 136 ++++++++++++++++++++ 3 files changed, 172 insertions(+), 27 deletions(-) create mode 100644 examples/toys/basketball_hoop/createRack.js diff --git a/examples/toys/basketball.js b/examples/toys/basketball.js index d30dce6e72..96b6218b3d 100644 --- a/examples/toys/basketball.js +++ b/examples/toys/basketball.js @@ -17,34 +17,39 @@ var collisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav"; var basketball = null; var originalPosition = null; -var hasMoved = false; +var hasMoved = false; var GRAVITY = -9.8; var DISTANCE_IN_FRONT_OF_ME = 1.0; var START_MOVE = 0.01; -var DIAMETER = 0.30; +var DIAMETER = 0.30; -function makeBasketball() { +function makeBasketball() { var position = Vec3.sum(MyAvatar.position, - Vec3.multiplyQbyV(MyAvatar.orientation, - { x: 0, y: 0.0, z: -DISTANCE_IN_FRONT_OF_ME })); + Vec3.multiplyQbyV(MyAvatar.orientation, { + x: 0, + y: 0.0, + z: -DISTANCE_IN_FRONT_OF_ME + })); var rotation = Quat.multiply(MyAvatar.orientation, - Quat.fromPitchYawRollDegrees(0, -90, 0)); + Quat.fromPitchYawRollDegrees(0, -90, 0)); basketball = Entities.addEntity({ - type: "Model", - position: position, - rotation: rotation, - dimensions: { x: DIAMETER, - y: DIAMETER, - z: DIAMETER }, - collisionsWillMove: true, - collisionSoundURL: collisionSoundURL, - modelURL: basketballURL, - restitution: 1.0, - linearDamping: 0.00001, - shapeType: "sphere" - }); - originalPosition = position; + type: "Model", + position: position, + rotation: rotation, + dimensions: { + x: DIAMETER, + y: DIAMETER, + z: DIAMETER + }, + collisionsWillMove: true, + collisionSoundURL: collisionSoundURL, + modelURL: basketballURL, + restitution: 1.0, + linearDamping: 0.00001, + shapeType: "sphere" + }); + originalPosition = position; } function update() { @@ -55,28 +60,33 @@ function update() { var moved = Vec3.length(Vec3.subtract(originalPosition, newProperties.position)); if (!hasMoved && (moved > START_MOVE)) { hasMoved = true; - Entities.editEntity(basketball, { gravity: {x: 0, y: GRAVITY, z: 0 }}); + Entities.editEntity(basketball, { + gravity: { + x: 0, + y: GRAVITY, + z: 0 + } + }); } var MAX_DISTANCE = 10.0; var distance = Vec3.length(Vec3.subtract(MyAvatar.position, newProperties.position)); if (distance > MAX_DISTANCE) { deleteStuff(); } - } + } } function scriptEnding() { deleteStuff(); } -function deleteStuff() { +function deleteStuff() { if (basketball != null) { Entities.deleteEntity(basketball); basketball = null; - hasMoved = false; + hasMoved = false; } } Script.update.connect(update); -Script.scriptEnding.connect(scriptEnding); - +Script.scriptEnding.connect(scriptEnding); \ No newline at end of file diff --git a/examples/toys/basketball_hoop/createHoop.js b/examples/toys/basketball_hoop/createHoop.js index 3887e0b421..b0c76b4a53 100644 --- a/examples/toys/basketball_hoop/createHoop.js +++ b/examples/toys/basketball_hoop/createHoop.js @@ -1,6 +1,5 @@ // // createHoop.js -// examples/entityScripts // // Created by James B. Pollack on 9/29/2015 // Copyright 2015 High Fidelity, Inc. diff --git a/examples/toys/basketball_hoop/createRack.js b/examples/toys/basketball_hoop/createRack.js new file mode 100644 index 0000000000..8019aca283 --- /dev/null +++ b/examples/toys/basketball_hoop/createRack.js @@ -0,0 +1,136 @@ +// +// createRack.js +// +// Created by James B. Pollack on10/5/2015 +// Copyright 2015 High Fidelity, Inc. +// +// This is a script that creates a persistent basketball rack. +// +// Distributed under the Apache License, Version 2.0. +// See the accompanying file LICENSE or http://www.apache.org/licenses/LICENSE-2.0.html +/*global MyAvatar, Entities, AnimationCache, SoundCache, Scene, Camera, Overlays, HMD, AvatarList, AvatarManager, Controller, UndoStack, Window, Account, GlobalServices, Script, ScriptDiscoveryService, LODManager, Menu, Vec3, Quat, AudioDevice, Paths, Clipboard, Settings, XMLHttpRequest, randFloat, randInt */ +var HIFI_PUBLIC_BUCKET = "http://s3.amazonaws.com/hifi-public/"; + +var basketballURL = HIFI_PUBLIC_BUCKET + "models/content/basketball2.fbx"; +var collisionSoundURL = HIFI_PUBLIC_BUCKET + "sounds/basketball/basketball.wav"; +var rackURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_rack.fbx"; +var rackCollisionHullURL = HIFI_PUBLIC_BUCKET + "models/basketball_hoop/basketball_hoop_collision_hull.obj"; +var DIAMETER = 0.30; + +var rackStartPosition = + Vec3.sum(MyAvatar.position, + Vec3.multiplyQbyV(MyAvatar.orientation, { + x: 0, + y: 0.0, + z: -2 + })); + +var rack = Entities.addEntity({ + type: "Model", + modelURL: rackURL, + position: rackStartPosition, + shapeType: 'compound', + // gravity: { + // x: 0, + // y: -9.8, + // z: 0 + // }, + dimensions: { + x: 0.4, + y: 1.37, + z: 1.73 + }, + collisionsWillMove: false, + ignoreForCollisions: true, + compoundShapeURL: rackCollisionHullURL +}); + +var nonCollidingBalls = []; +var collidingBalls = []; + +function createNonCollidingBalls() { + var i; + var j; + var position = rackStartPosition; + for (i = 0; i < 4; i++) { + var nonCollidingBall = Entities.addEntity({ + type: "Model", + name: 'Static Basketball', + position: { + x: position.x, + y: position.y, + z: position.z + (DIAMETER) - (DIAMETER * i) + }, + dimensions: { + x: DIAMETER, + y: DIAMETER, + z: DIAMETER + }, + collisionsWillMove: true, + ignoreForCollisions: false, + modelURL: basketballURL + }); + nonCollidingBalls.push(nonCollidingBall); + } + for (i = 0; i < 4; i++) { + var nonCollidingBall = Entities.addEntity({ + type: "Model", + name: 'Static Basketball', + position: { + x: position.x, + y: position.y + DIAMETER, + z: position.z + (DIAMETER) - (DIAMETER * i) + }, + dimensions: { + x: DIAMETER, + y: DIAMETER, + z: DIAMETER + }, + collisionsWillMove: true, + ignoreForCollisions: false, + modelURL: basketballURL + }); + nonCollidingBalls.push(nonCollidingBall); + } +} + +function createCollidingBalls() { + var position = rackStartPosition; + for (i = 0; i < 4; i++) { + var collidingBall = Entities.addEntity({ + type: "Model", + name: 'Colliding Basketball', + position: { + x: position.x, + y: position.y + DIAMETER * 2, + z: position.z + (DIAMETER) - (DIAMETER * i) + }, + dimensions: { + x: DIAMETER, + y: DIAMETER, + z: DIAMETER + }, + // restitution: 1.0, + // linearDamping: 0.00001, + gravity: { + x: 0, + y: -9.8, + z: 0 + }, + collisionsWillMove: true, + ignoreForCollisions: false, + modelURL: basketballURL + }); + collidingBalls.push(collidingBall); + } +} + +function adjustBallPositions() { + var i; + for (i = 0; i < nonCollidingBalls.length; i++) { + Entities.editEntity(nonCollidingBalls[i]) + } +} + +createNonCollidingBalls(); +createCollidingBalls(); \ No newline at end of file