Created
February 3, 2016 17:36
-
-
Save huffman/0ec1c70ba7af1904af8a to your computer and use it in GitHub Desktop.
AC Simulation Test
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var entities= []; | |
var WALL_THICKNESS = 0.2; | |
var BOX_WIDTH = 10; | |
var BOX_HEIGHT = 10; | |
var BOX_DEPTH = 10; | |
basePosition = { x: 0, y: 0, z: 0 }; | |
// Floor | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
position: Vec3.sum(basePosition, { x: 0, y: 0, z: 0 }), | |
dimensions: { x: BOX_WIDTH, y: WALL_THICKNESS, z: BOX_DEPTH}, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
// Left Wall | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
position: Vec3.sum(basePosition, { x: -BOX_WIDTH/2, y: BOX_HEIGHT/2, z: 0 }), | |
dimensions: { x: WALL_THICKNESS, y: BOX_HEIGHT, z: BOX_DEPTH}, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
// Right Wall | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
position: Vec3.sum(basePosition, { x: BOX_WIDTH/2, y: BOX_HEIGHT/2, z: 0 }), | |
dimensions: { x: WALL_THICKNESS, y: BOX_HEIGHT, z: BOX_DEPTH}, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
// Ceiling | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
position: Vec3.sum(basePosition, { x: 0, y: BOX_HEIGHT, z: 0 }), | |
dimensions: { x: BOX_WIDTH, y: WALL_THICKNESS, z: BOX_DEPTH}, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
// Back Wall | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
position: Vec3.sum(basePosition, { x: 0, y: BOX_HEIGHT/2, z: -BOX_DEPTH/2 }), | |
dimensions: { x: BOX_WIDTH, y: BOX_HEIGHT, z: WALL_THICKNESS }, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
// Front Wall | |
entities.push(Entities.addEntity({ | |
type: "Box", | |
visible: false, | |
position: Vec3.sum(basePosition, { x: 0, y: BOX_HEIGHT/2, z: BOX_DEPTH/2 }), | |
dimensions: { x: BOX_WIDTH, y: BOX_HEIGHT, z: WALL_THICKNESS }, | |
friction: 0, | |
restitution: 1.0 | |
})); | |
ballID = Entities.addEntity({ | |
type: "Sphere", | |
position: Vec3.sum(basePosition, { x: 0, y: BOX_HEIGHT/2, z: 0 }), | |
color: { red: 255, green: 0, blue: 0 }, | |
dynamic: true, | |
dimensions: { x: 0.3, y: 0.3, z: 0.3 }, | |
damping: 0.3, | |
angularDamping: 0, | |
friction: 0, | |
restitution: 1.0 | |
}); | |
entities.push(ballID); | |
Script.setInterval(function() { | |
var direction = Vec3.normalize({ x: Math.random(), y: Math.random(), z: Math.random() }); | |
var velocity = Vec3.multiply(3, direction); | |
Vec3.print('Setting velocity', velocity); | |
Entities.editEntity(ballID, { | |
velocity: velocity | |
}); | |
}, 4000); | |
Script.scriptEnding.connect(function() { | |
for (var i = 0; i < entities.length; ++i) { | |
Entities.deleteEntity(entities[i]); | |
} | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment