Skip to content

Instantly share code, notes, and snippets.

@brunofarache
Forked from anonymous/y3d-script.js
Last active December 18, 2015 22:19
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save brunofarache/5853591 to your computer and use it in GitHub Desktop.
Save brunofarache/5853591 to your computer and use it in GitHub Desktop.
/**
* Click on the left canvas and then move camera with wasd keys.
* Use mouse wheel to zoom in and zoom out.
*
* https://gist.github.com/brunofarache/5853591
*/
YUI().use('y3d-anim', 'y3d-scene', 'y3d-camera', 'y3d-geometry-box', 'y3d-geometry-sphere', 'y3d-texture', function(Y) {
var camera = new Y.Camera({
position: {
z: 20
}
});
var scene = new Y.Scene({
camera: camera,
background: '#272822'
});
var box = new Y.Box({
texture: 'examples/images/grass.png',
position: {
x: 4,
z: -10
}
});
var sphere = new Y.Sphere({
radius: 2,
texture: 'examples/images/moon.gif',
position: {
x: -4
}
});
scene.add(box);
scene.add(sphere);
var x = 0, y = 0;
var animFn = function() {
x = x + 3;
y = y + 1;
box.set('rotation', { x: x, y: y });
sphere.set('rotation', { y: y });
};
// assign animation object to playground.anim, otherwise the editor won't
// stop animation before running a different template.
playground.anim = new Y.WebGLAnim(scene, animFn);
new Y.TextureLoader({
onLoad: function() {
playground.anim.start();
},
textures: [box.get('texture'), sphere.get('texture')]
});
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment