From 43f69a0be995ace51dfa0440f775b4bfb9dabef5 Mon Sep 17 00:00:00 2001 From: "James B. Pollack" Date: Mon, 5 Oct 2015 13:23:19 -0700 Subject: [PATCH] initial knockover blocks --- examples/toys/createKnockoverBlocks.js | 152 +++++++++++++++++++++---- 1 file changed, 130 insertions(+), 22 deletions(-) diff --git a/examples/toys/createKnockoverBlocks.js b/examples/toys/createKnockoverBlocks.js index b5fe22ca73..417dc6cadd 100644 --- a/examples/toys/createKnockoverBlocks.js +++ b/examples/toys/createKnockoverBlocks.js @@ -1,47 +1,155 @@ // // createKnockoverBlocks.js // +// Script Type: Entity Spawner // Created by James B. Pollack on 9/29/2015 // Copyright 2015 High Fidelity, Inc. // // +// This script creates a 'stonehenge' formation of physical blocks for testing knock over properties. // 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 blockDimensions={ - x:0.12, - y:0.25, - z:0.50 + +var BLOCK_GRAVITY = { + x: 0, + y: -9.8, + z: 0 +}; + +var LINEAR_DAMPING = 0.2; + +var RED = { + red: 255, + green: 0, + blue: 0 +}; + +var GREEN = { + red: 0, + green: 255, + blue: 0 +}; + +var BLUE = { + red: 0, + green: 0, + blue: 255 +}; + +var blockDimensions = { + x: 0.12, + y: 0.25, + z: 0.50 }; var centerPosition = { - x: - y: - z: + x: 0, + y: 0, + z: 0 }; +var DISTANCE_IN_FRONT_OF_ME = 2.0; +var position = Vec3.sum(MyAvatar.position, + Vec3.multiplyQbyV(MyAvatar.orientation, { + x: 0, + y: 0.0, + z: -DISTANCE_IN_FRONT_OF_ME + })); + +// var position={ +// x:0, +// y:0, +// z:0 +// }; var sideBlock1_position = { - x: - y: - z: + x: position.x, + y: position.y, + z: position.z - 0.25 }; - - var sideBlock2_position = { - x: - y: - z: + x: position.x, + y: position.y, + z: position.z + 0.25 }; +var topBlock_position = { + x: position.x, + y: position.y + 0.31, + z: position.z +}; -var sideBlock1_rotation = Quat.fromPitchYawRollDegrees(); -var sideBlock2_rotation = Quat.fromPitchYawRollDegrees(); -var topBlock_rotation = Quat.fromPitchYawRollDegrees(); +var sideBlock1_rotation = Quat.fromPitchYawRollDegrees(90, 90, 0); +var sideBlock2_rotation = Quat.fromPitchYawRollDegrees(90, 90, 0); +var topBlock_rotation = Quat.fromPitchYawRollDegrees(0, 0, 90); -var sideBlock1 = Entities.addEntity(); -var sideBlock2 = Entities.addEntity(); -var topBlock = Entities.addEntity(); -var ground = Entities.addEntity(); \ No newline at end of file +var topBlock = Entities.addEntity({ + name: 'Top Block', + color: BLUE, + type: 'Box', + shapeType: 'box', + dimensions: blockDimensions, + position: topBlock_position, + rotation: topBlock_rotation, + linearDamping: LINEAR_DAMPING, + gravity: BLOCK_GRAVITY, + collisionsWillMove: true, + velocity: { + x: 0, + y: -0.01, + z: 0 + } +}); + +var sideBlock1 = Entities.addEntity({ + name: 'Top Block', + color: GREEN, + type: 'Box', + shapeType: 'box', + dimensions: blockDimensions, + position: sideBlock1_position, + rotation: sideBlock1_rotation, + linearDamping: LINEAR_DAMPING, + gravity: BLOCK_GRAVITY, + collisionsWillMove: true +}); + +var sideBlock2 = Entities.addEntity({ + name: 'Side Block', + color: GREEN, + type: 'Box', + shapeType: 'box', + dimensions: blockDimensions, + position: sideBlock2_position, + rotation: sideBlock2_rotation, + collsionsWillMove: true, + linearDamping: LINEAR_DAMPING, + gravity: BLOCK_GRAVITY, + collisionsWillMove: true +}); + +var ground = Entities.addEntity({ + type: 'Box', + dimensions: { + x: 2, + y: 0.02, + z: 1 + }, + color: RED, + position: { + x: position.x, + y: position.y - 0.25, + z: position.z + } +}); + +function cleanUp() { + Entities.deleteEntity(ground); + Entities.deleteEntity(topBlock); + Entities.deleteEntity(sideBlock1); + Entities.deleteEntity(sideBlock2); +}; +Script.scriptEnding.connect(cleanUp); \ No newline at end of file