Skip to content

Commit

Permalink
Merge branch 'symfony' of github.com:GCalmels/CharityGame into symfony
Browse files Browse the repository at this point in the history
  • Loading branch information
rgranger committed Dec 4, 2014
2 parents f0ddb1c + 60e2a29 commit 4f1b51a
Show file tree
Hide file tree
Showing 8 changed files with 945 additions and 5 deletions.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
108 changes: 108 additions & 0 deletions src/CG/PlatformBundle/Resources/public/js/earth.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,108 @@

// Display objects
var container;
var camera, scene, renderer;
var windowHalfX = window.innerWidth / 2;
var windowHalfY = window.innerHeight / 2;

// Displayed object
var earthMesh;

// Mouse object
var mouse = {x : 0, y : 0, isClicked: false};

init();
animate();


function init()
{
container = document.getElementById("canvas_container")

// Camera
camera = new THREE.PerspectiveCamera(45, window.innerWidth / window.innerHeight, 0.01, 1000 );
camera.position.x = 0;
camera.position.y = 0;
camera.position.z = 1.5;

// Scene
scene = new THREE.Scene();
scene.add( camera );

// Light
var light = new THREE.AmbientLight( 0xaaaaaa )
scene.add( light )

var light = new THREE.DirectionalLight( 0xaaaaaa, 1 )
light.position.set(5,3,5)
scene.add( light )

// EarthMesh
var geometry = new THREE.SphereGeometry(0.5, 32, 32)
var material = new THREE.MeshPhongMaterial()
material.map = THREE.ImageUtils.loadTexture('earthmap1k.jpg')
earthMesh = new THREE.Mesh(geometry, material)

scene.add(earthMesh)

// Rendering
renderer = new THREE.WebGLRenderer({alpha:true});
renderer.setClearColor( 0xeeeeee, 1);
renderer.setSize(window.innerWidth, window.innerHeight);
container.appendChild( renderer.domElement );

window.addEventListener( 'resize', onWindowResize, false );

}

function onWindowResize()
{
windowHalfX = window.innerWidth / 2;
windowHalfY = window.innerHeight / 2;

camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();

renderer.setSize( window.innerWidth, window.innerHeight );
}


document.addEventListener('mousemove', function(event)
{
if(mouse.isClicked)
{
mouse.x = (event.clientX / window.innerWidth ) - 0.5
mouse.y = (event.clientY / window.innerHeight) - 0.5
}
}, false)

document.addEventListener('mousedown', function(event)
{
mouse.isClicked = true;
})

document.addEventListener('mouseup', function(event)
{
mouse.isClicked = false;
mouse.x = 0;
mouse.y = 0;
})

function animate()
{
requestAnimationFrame( animate );
render();
}

function render()
{
if(!( (mouse.y>0 && earthMesh.rotation.x>1) || (mouse.y<0 && earthMesh.rotation.x<-1) ) )
{
earthMesh.rotation.x += mouse.y/10
}
earthMesh.rotation.y += mouse.x/5

camera.lookAt( scene.position )

renderer.render( scene, camera );
}
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
4 changes: 4 additions & 0 deletions src/CG/PlatformBundle/Resources/public/js/jquery-2.1.1.min.js

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -1,3 +0,0 @@
var b_canvas = document.getElementById("world_canvas");
var b_context = b_canvas.getContext("2d");
b_context.fillRect(0, 0, b_canvas.width, b_canvas.height);
827 changes: 827 additions & 0 deletions src/CG/PlatformBundle/Resources/public/js/three.min.js

Large diffs are not rendered by default.

8 changes: 6 additions & 2 deletions src/CG/PlatformBundle/Resources/views/Platform/home.html.twig
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
</div>


<div class="col-md-8 col-md-offset-2">
<canvas id="world_canvas" width="640" height="480"></canvas>
<div id="canvas_container">

</div>


Expand All @@ -26,4 +26,8 @@
{% block javascripts %}
{{ parent() }}
<script src="{{ asset('bundles/cgplatform/js/load_canvas_content.js') }}"></script>
<script src="{{ asset('bundles/cgplatform/js/jquery-2.1.1.min.js') }}"></script>
<script src="{{ asset('bundles/cgplatform/js/three.min.js') }}"></script>
<script src="{{ asset('bundles/cgplatform/js/earth.js') }}"></script>

{% endblock javascripts %}

0 comments on commit 4f1b51a

Please sign in to comment.