-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathindex4.html
149 lines (122 loc) · 3.87 KB
/
index4.html
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
<!doctype html>
<html lang="en">
<head>
<title>Keyboard Input (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 rel=stylesheet href="css/base.css"/>
</head>
<body>
<script src="js/lib/Detector.js"></script>
<script src="js/lib/Three.js"></script>
<script src="js/lib/Stats.js"></script>
<script src="js/lib/OrbitControls.js"></script>
<script src="js/lib/KeyboardState.js"></script>
<script src="js/lib/THREEx.FullScreen.js"></script>
<script src="js/lib/THREEx.WindowResize.js"></script>
<!-- Code to display an information button and box when clicked. -->
<script src="js/lib/jquery-1.9.1.js"></script>
<script src="js/lib/jquery-ui.js"></script>
<link rel=stylesheet href="css/jquery-ui.css" />
<link rel=stylesheet href="css/info.css"/>
<script src="js/lib/info.js"></script>
<div id="infoButton"></div>
<div id="infoBox" title="Demo Information">
Controls: Press A/D to move continuously, press LEFT/RIGHT to move in discrete jumps,
and press R to change color (will return to original color when key is released).
<br/><br/>
This three.js demo is part of a collection at
<a href="http://stemkoski.github.io/Three.js/">http://stemkoski.github.io/Three.js/</a>
</div>
<!-- ------------------------------------------------------------ -->
<div id="ThreeJS" style="position: absolute; left:0px; top:0px"></div>
<script>
/*
Three.js "tutorials by example"
Author: Lee Stemkoski
Date: August 2013 (three.js v60)
*/
// MAIN
// standard global variables
var container, scene, camera, renderer, controls, stats;
var clock = new THREE.Clock();
var keyboard = new KeyboardState();
// custom global variables
var mesh;
init();
animate();
// FUNCTIONS
function init()
{
// SCENE
scene = new THREE.Scene();
// CAMERA
var SCREEN_WIDTH = window.innerWidth, SCREEN_HEIGHT = window.innerHeight;
var VIEW_ANGLE = 45, ASPECT = SCREEN_WIDTH / SCREEN_HEIGHT, NEAR = 0.1, FAR = 20000;
camera = new THREE.PerspectiveCamera( VIEW_ANGLE, ASPECT, NEAR, FAR);
scene.add(camera);
camera.position.set(0,150,400);
// RENDERER
if ( Detector.webgl )
renderer = new THREE.WebGLRenderer( {antialias:true} );
else
renderer = new THREE.CanvasRenderer();
renderer.setSize(SCREEN_WIDTH, SCREEN_HEIGHT);
container = document.getElementById( 'ThreeJS' );
container.appendChild( renderer.domElement );
// EVENTS
THREEx.WindowResize(renderer, camera);
THREEx.FullScreen.bindKey({ charCode : 'm'.charCodeAt(0) });
// CONTROLS
controls = new THREE.OrbitControls( camera, renderer.domElement );
// STATS
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.bottom = '0px';
stats.domElement.style.zIndex = 100;
container.appendChild( stats.domElement );
// LIGHT
// FLOOR
// SKYBOX
////////////
// CUSTOM //
////////////
var geometry = new THREE.SphereGeometry( 30, 32, 16 );
var material = new THREE.MeshLambertMaterial( { color: 0x0000ff } );
mesh = new THREE.Mesh( geometry, material );
mesh.position.set(0,40,0);
scene.add(mesh);
}
function animate()
{
requestAnimationFrame( animate );
render();
update();
}
function update()
{
keyboard.update();
var moveDistance = 50 * clock.getDelta();
if ( keyboard.down("left") )
mesh.translateX( -50 );
if ( keyboard.down("right") )
mesh.translateX( 50 );
if ( keyboard.pressed("A") )
mesh.translateX( -moveDistance );
if ( keyboard.pressed("D") )
mesh.translateX( moveDistance );
if ( keyboard.down("R") )
mesh.material.color = new THREE.Color(0xff0000);
if ( keyboard.up("R") )
mesh.material.color = new THREE.Color(0x0000ff);
}
function render()
{
var time = Date.now() * 0.00005;
mesh.rotation.y = time * 3;
mesh.rotation.x = time * 3;
renderer.render( scene, camera );
}
</script>
</body>
</html>