Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Last active August 29, 2015 14:23
Show Gist options
  • Save mathdoodle/076dd6e8cd1031c00c0f to your computer and use it in GitHub Desktop.
Save mathdoodle/076dd6e8cd1031c00c0f to your computer and use it in GitHub Desktop.
Eight
{
"uuid": "a9ed377b-e750-4731-8c26-3a8e7d5d09da",
"description": "Eight",
"dependencies": {
"davinci-eight": "latest"
},
"operatorOverloading": true
}
<!doctype html>
<html>
<head>
<style>
/* STYLE-MARKER */
</style>
<!-- SCRIPTS-MARKER -->
</head>
<body>
<script>
// CODE-MARKER
</script>
</body>
</html>
var scene = EIGHT.world();
var camera = EIGHT.perspective(45 * Math.PI / 180, 1.0, 0.1, 100);
var renderer = EIGHT.viewport();
var box = EIGHT.box(camera);
scene.add(box);
box.model.position = blade.vectorE3(-1.0,-0.5,-5.0);
var workbench = EIGHT.workbench(renderer.canvas, renderer, camera, window);
function setUp() {
workbench.setUp();
monitor.start();
}
var B = blade.bivectorE3(0,1,1);
B = B / B.norm()
var angle: number = 0;
/**
* Performs the animation.
*/
function tick(time: number) {
var halfAngle = angle/2;
var c = Math.cos(halfAngle);
var s = Math.sin(halfAngle);
var R = c - B * s;
box.model.attitude = R;
renderer.render(scene, [camera]);
angle += 0.05;
}
/**
* Determines whether to terminate the animation.
*/
function terminate(time: number) {return false;}
function tearDown(e) {
monitor.stop();
if (e) {
console.log("Error during animation: " + e);
}
else {
console.log("Goodbye!");
workbench.tearDown();
}
}
var runner = EIGHT.animationRunner(tick, terminate, setUp, tearDown, window);
// TODO: Would be nicer to simply add dependents to the monitor. Is this just the same as the scene?
var monitor = EIGHT.contextMonitor(renderer.canvas);
monitor.addContextUser(scene);
monitor.addContextUser(renderer);
runner.start();
body { margin: 0; }
canvas { width: 100%; height: 100% }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment