Birdy
by devangkantharia
October 06, 2015
HTML
<script src="//cdnjs.cloudflare.com/ajax/libs/three.js/r70/three.min.js"></script>
<script src="//cdnjs.cloudflare.com/ajax/libs/gsap/1.16.1/TweenMax.min.js"></script>
<script src="https://s3-us-west-2.amazonaws.com/s.cdpn.io/264161/OrbitControls.js"></script>
<div id="world"></div>
<div id="instructions">^
<br/>Move the head of this bird
<br/><span class="lightInstructions">and watch how the 2 others<br/>interact with him</span>
</div>
CSS
@import url(http://fonts.googleapis.com/css?family=Open+Sans:800);
#world {
background: #e0dacd;
position:absolute;
width:100%;
height:100%;
overflow:hidden;
}
#instructions {
position:absolute;
width:100%;
top:50%;
margin: auto;
margin-top:50px;
font-family:'Open Sans', sans-serif;
color:#b75505;
font-size:.9em;
text-transform: uppercase;
text-align : center;
}
.lightInstructions {
color:#b59b63;
font-size:.8em;
}
#credits {
position:absolute;
width:100%;
margin: auto;
bottom:0;
margin-bottom:20px;
font-family:'Open Sans', sans-serif;
color:#b59b63;
font-size:0.7em;
text-transform: uppercase;
text-align : center;
}
#credits a {
color:#b59b63;
}
JavaScript
//THREEJS RELATED VARIABLES
var scene,
camera,
controls,
fieldOfView,
aspectRatio,
nearPlane,
farPlane,
shadowLight,
backLight,
light,
renderer,
container;
//SCENE
var floor, brid1, bird2;
//SCREEN VARIABLES
var HEIGHT,
WIDTH,
windowHalfX,
windowHalfY,
mousePos = {
x: 0,
y: 0
};
//INIT THREE JS, SCREEN AND MOUSE EVENTS
function init() {
scene = new THREE.Scene();
HEIGHT = window.innerHeight;
WIDTH = window.innerWidth;
aspectRatio = WIDTH / HEIGHT;
fieldOfView = 60;
nearPlane = 1;
farPlane = 2000;
camera = new THREE.PerspectiveCamera(
fieldOfView,
aspectRatio,
nearPlane,
farPlane);
camera.position.z = 1000;
camera.position.y = 300;
camera.lookAt(new THREE.Vector3(0, 0, 0));
renderer = new THREE.WebGLRenderer({
alpha: true,
antialias: true
});
renderer.setSize(WIDTH, HEIGHT);
renderer.shadowMapEnabled = true;
container = document.getElementById('world');
container.appendChild(renderer.domElement);
windowHalfX = WIDTH / 2;
windowHalfY = HEIGHT / 2;
window.addEventListener('resize', onWindowResize, false);
document.addEventListener('mousemove', handleMouseMove, false);
document.addEventListener('touchstart', handleTouchStart, false);
document.addEventListener('touchend', handleTouchEnd, false);
document.addEventListener('touchmove', handleTouchMove, false);
/*
controls = new THREE.OrbitControls( camera, renderer.domElement);
//*/
}
function onWindowResize() {
HEIGHT = window.innerHeight;
WIDTH = window.innerWidth;
windowHalfX = WIDTH / 2;
windowHalfY = HEIGHT / 2;
renderer.setSize(WIDTH, HEIGHT);
camera.aspect = WIDTH / HEIGHT;
camera.updateProjectionMatrix();
}
function handleMouseMove(event) {
mousePos = {
x: event.clientX,
y: event.clientY
};
}
function handleTouchStart(event) {
if (event.touches.length > 1) {
event.preventDefault();
...