-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathBasicAnimation.html
77 lines (71 loc) · 2.03 KB
/
BasicAnimation.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
<!DOCTYPE html>
<html>
<head>
<title>Getting Started with Three.js</title>
<script src="../build/three.min.js"></script>
<script src="js/renderers/Projector.js"></script>
<script src="js/renderers/CanvasRenderer.js"></script>
<script src="js/libs/stats.min.js"></script>
<script>
window.onload = function() {
var renderer = new THREE.WebGLRenderer();
renderer.setSize( 1400, 700 );
document.body.appendChild( renderer.domElement );
var scene = new THREE.Scene();
var camera = new THREE.PerspectiveCamera(
35, // Field of view
800 / 600, // Aspect ratio
0.1, // Near plane
10000 // Far plane
);
camera.position.z = 500;
camera.lookAt( scene.position );
var light = new THREE.PointLight( 0xFFFF00 );
light.position.set( 10, 0, 10 );
scene.add( light );
cube = new THREE.Mesh( new THREE.CubeGeometry( 20, 20, 20 ), new THREE.MeshNormalMaterial() );
cube.position.x = 0;
scene.add(camera);
scene.add(cube );
xForce = 1;
zForce = 3;
zAcceleratorCounter = 1; // to control the speed of object move in z Axis
animate();
function animate() {
render();
requestAnimationFrame( animate );
}
function render() {
zAcceleratorCounter += 1;
if (zAcceleratorCounter < 1)
{ zForce = zForce + cube.position.z *(.008);
}
if (zAcceleratorCounter >200)
{ zForce = zForce - cube.position.z *(.008);
}
if (cube.position.z > 400)
{
zForce = zForce * (-1);
}
if (cube.position.z < 0)
{
zForce =zForce * (-1);
}
if(cube.position.x >100)
{
xForce = xForce * (-1);
}
if(cube.position.x <-100)
{
xForce = xForce * (-1);
}
cube.position.z = cube.position.z + zForce;
cube.rotation.z += .01;
cube.rotation.y += .01;
renderer.render( scene, camera );
}
};
</script>
</head>
<body></body>
</html>