1
0
Fork 0
mirror of https://github.com/haselkern/Minecraft-ArmorStand.git synced 2025-05-17 15:05:33 +00:00

Shiny, colorful cube

Has not much to do with Minecraft, but it's worth committing.
This commit is contained in:
haselkern 2014-08-17 18:01:41 +02:00
parent 18ddc0426c
commit 54b1bdef3e
4 changed files with 35960 additions and 10 deletions

63
main.js Normal file
View file

@ -0,0 +1,63 @@
// BIG Thanks to tutsplus.com
// http://code.tutsplus.com/tutorials/webgl-with-threejs-basics--net-35688
// for helping me getting started
var width, height, renderer, scene, camera, cube;
var clock = new THREE.Clock;
$(document).ready(function(){
setup();
render();
$("input").on("input", function(){
handleInput();
});
$(':checkbox').change(function() {
handleInput();
});
});
function setup(){
width = $("#gl").width();
height = $("#gl").height();
renderer = new THREE.WebGLRenderer({ antialias: true, alpha:true });
renderer.setSize(width, height);
$("#gl").append(renderer.domElement);
scene = new THREE.Scene;
var cubeGeo = new THREE.CubeGeometry(1, 1, 1);
var cubeMat = new THREE.MeshLambertMaterial({ color: 0x1ec876 });
cube = new THREE.Mesh(cubeGeo, cubeMat);
cube.rotation.y = 45 * Math.PI/180;
scene.add(cube);
camera = new THREE.PerspectiveCamera(45, width/height, 0.1, 1000);
camera.position.y = 2;
camera.position.z = 4;
camera.lookAt(cube.position);
scene.add(camera);
var pointLight = new THREE.PointLight(0xffffff);
pointLight.position.set(0, 300, 200);
scene.add(pointLight);
}
function handleInput(){
cube.material.color.setHex(Math.random() * 0xFFFFFF);
}
function render(){
renderer.render(scene, camera);
var d = clock.getDelta();
cube.rotation.y += d;
requestAnimationFrame(render);
}