Skip to content

Instantly share code, notes, and snippets.

@mathdoodle
Last active August 29, 2015 14:22
Show Gist options
  • Save mathdoodle/fc5406bff5d333b64281 to your computer and use it in GitHub Desktop.
Save mathdoodle/fc5406bff5d333b64281 to your computer and use it in GitHub Desktop.
EIGHT
{
"uuid": "e4a961e2-9cf1-4947-8e8d-a7efe0e01e29",
"description": "EIGHT",
"dependencies": {
"DomReady": "latest",
"davinci-eight": "latest",
"davinci-threejs": "0.71.4"
},
"operatorOverloading": true
}
<!doctype html>
<html>
<head>
<style>
/* STYLE-MARKER */
</style>
<!-- SCRIPTS-MARKER -->
<script>
// CODE-MARKER
</script>
</head>
<body>
<canvas id='canvas' width='600' height='600'>
Your browser does not support the HTML5 canvas element.
</canvas>
</body>
</html>
DomReady.ready(function() {
try {
main();
}
catch(e) {
alert(e);
}
});
function main() {
var separation = 0.3;
var distance = 2;
var elevation = 5;
//var world = EIGHT.world();
var view = EIGHT.perspective(75 * Math.PI / 180, window.innerWidth / window.innerHeight);
// var renderer = EIGHT.renderer();
// renderer.setSize(window.innerWidth, window.innerHeight);
// document.body.appendChild(renderer.domElement)
var canvas = <HTMLCanvasElement>document.getElementById('canvas');
var context = <WebGLRenderingContext>canvas.getContext('webgl');
var e1 = blade.e3ga.e1;
var e2 = blade.e3ga.e2;
var e3 = blade.e3ga.e3;
var T = 5;
var f = 1/T;
var omega = 2 * Math.PI * f;
var mesh = new EIGHT.GeometryAdapter(new THREE.BoxGeometry(1, 1, 1), {drawMode: 2});
var model = new EIGHT.ModelMatrixUniformProvider();
var program = EIGHT.smartProgram(mesh.getAttributeMetaInfos(), [model.getUniformMetaInfos(), view.getUniformMetaInfos()]);
var cube = EIGHT.drawableModel(mesh, program, model);
view.eye = (12 * e3 + elevation * e2 - separation * e1).unit() * distance;
view.look = cube.uniforms.position;
var B = (e3 ^ e1).unit();
cube.contextGain(context, '');
cube.useProgram();
//world.add(cube);
var startTime = Date.now();
function render() {
try {
var time = (Date.now() - startTime) / 1000;
var theta = omega * time;
var rotor = Math.cos(theta/2) - B * Math.sin(theta/2);
cube.uniforms.attitude = rotor;
cube.draw(view)
//renderer.render(world, [view]);
requestAnimationFrame(render);
}
catch(e) {
console.log(e);
}
}
render();
}
body {
background-color: white;
margin: 0;
}
canvas {
background-color: black;
position: absolute;
width: 100%;
height: 100%;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment