<!DOCTYPE html>
<html lang="en">
<head>
<title>three.js</title>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, user-scalable=no, minimum-scale=1.0, maximum-scale=1.0">
<link type="text/css" rel="stylesheet" href="main.css">
</head>
<body>
<script src="js/three.js"></script>
<script>
var camera, scene, renderer;
var mesh;
//---- control camera ----
var my_control_x=0;
var my_control_z=0;
var rotation=0;
//-------------------------
init();
animate();
function init() {
camera = new THREE.PerspectiveCamera( 70, window.innerWidth / window.innerHeight, 1, 35000 );
camera.position.z = 5400;
scene = new THREE.Scene();
//========================================================================
function my_draw(a, b , c , x, y , z ,material_x) {//function
var geometry_x = new THREE.BoxBufferGeometry( a, b, c );
mesh_x = new THREE.Mesh( geometry_x, material_x );
mesh_x.position.x = x;
mesh_x.position.y = y;
mesh_x.position.z = z;
scene.add( mesh_x );
}//function
//-------------------------- skybox -------------------
var skyGeo = new THREE.SphereGeometry(15000, 25, 25);
//First the geometry. I wanted it big and made it big
var texture_x = new THREE.TextureLoader().load( 'textures/cube/skyboxsun25deg/nx.jpg' );
var material_sky = new THREE.MeshBasicMaterial( { map: texture_x } );
//Set everything together and add it to the scene here.
var sky = new THREE.Mesh(skyGeo, material_sky);
sky.material.side = THREE.BackSide;
scene.add(sky);
//--------------------------- grass ------------------------
var loader = new THREE.TextureLoader();
var texture4 = loader.load( 'textures/terrain/grasslight-big.jpg', function ( texture ) {
texture.wrapS = texture.wrapT = THREE.RepeatWrapping;
texture.offset.set( 0, 0 );
texture.repeat.set( 20, 35 );
// your code
} );
var material_zz4 = new THREE.MeshBasicMaterial( { map: texture4 } );
my_draw(8000,10,30000,0,-150,7000,material_zz4);
//-------------------- stone ------------
var geometry_stone = new THREE.BoxBufferGeometry( 200, 200, 200 );
var texture_stone = new THREE.TextureLoader().load( 'textures/terrain/stone.jpg' );
var material_stone = new THREE.MeshBasicMaterial( { map: texture_stone } );
mesh_stone = new THREE.Mesh( geometry_stone, material_stone );
mesh_stone.position.x = -650;
mesh_stone.position.y = -100;
mesh_stone.position.z = 5500;
scene.add( mesh_stone );
//======================================================================
renderer = new THREE.WebGLRenderer( { antialias: true } );
renderer.setPixelRatio( window.devicePixelRatio );
renderer.setSize( window.innerWidth, window.innerHeight );
document.body.appendChild( renderer.domElement );
window.addEventListener( 'resize', onWindowResize, false );
}// /init--------------------------------------------------------------------------------------------------
document.addEventListener('keydown',onKeyDown,false);
function onKeyDown(event){//onKeyDown
var delta =20;
//event = event || window.event;
var keycode = event.keyCode;
switch(keycode){
case 37 : //left arrow
camera.updateProjectionMatrix();
break;
case 38 : // up arrow
//
camera.position.z = camera.position.z - delta;
camera.updateProjectionMatrix();
break;
case 39 : // right arrow
camera.updateProjectionMatrix();
break;
case 40 : //down arrow
camera.position.z = camera.position.z + delta ;
camera.updateProjectionMatrix();
break;
}
}//onKeyDown
function onWindowResize() {
camera.aspect = window.innerWidth / window.innerHeight;
camera.updateProjectionMatrix();
renderer.setSize( window.innerWidth, window.innerHeight );
}
function animate() {
requestAnimationFrame( animate );
camera.rotation.y=rotation;
camera.position.x =camera.position.x - my_control_x;
camera.position.z =camera.position.z - my_control_z;
camera.updateProjectionMatrix();
renderer.render( scene, camera );
}
//======================================================================
function myFunction(x) {
if (x==1) {my_control_z=20; my_control_x=0; rotation=0; }
if (x==2) {my_control_z=-20; rotation=3.14159; }
if (x==3) {my_control_z=0; my_control_x=0; }
if (x==9) {my_control_z=-20; my_control_x=0; rotation=0; }
}
</script>
<center>
<img src="textures/buttons/up.png" height="120" size="120" alt="Img" onclick="myFunction('1')">
<img src="textures/buttons/stop.jpg" height="120" size="120" alt="Img" onclick="myFunction('3')">
<img src="textures/buttons/down.png" height="120" size="120" alt="Img" onclick="myFunction('9')">
<img src="textures/buttons/down.png" height="120" size="120" alt="Img" onclick="myFunction('2')">
</center>
</body>
</html>