-
Notifications
You must be signed in to change notification settings - Fork 7
/
5-using-matrices.html
87 lines (64 loc) · 2.06 KB
/
5-using-matrices.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
<html>
<head>
<title>Working with Matrices</title>
<style>
body {
font-family: Monospace;
background-color: #f0f0f0;
margin: 0px;
overflow: hidden;
}
canvas {
width: 100%;
height: 100%;
}
</style>
<script src="lib/three.min.js"></script>
<script src="lib/stats.min.js"></script>
<script src="lib/Coordinates.js"></script>
<script src="lib/OrbitControls.js"></script>
</head>
<body>
<script>
var scene, camera, renderer, controls, stats;
function Start() {
scene = new THREE.Scene();
camera = new THREE.PerspectiveCamera( 75, window.innerWidth / window.innerHeight, 0.1, 1000 );
renderer = new THREE.WebGLRenderer();
renderer.setSize( window.innerWidth, window.innerHeight );
renderer.setClearColor( 0xf0f0f0 );
document.body.appendChild( renderer.domElement );
camera.position.set(3,4,6);
camera.lookAt( new THREE.Vector3(0,0,0));
var geometry = new THREE.BoxGeometry(3,3,3);
var material = new THREE.MeshBasicMaterial( { color: 0xaaaaaa, transparent: true, opacity:0.4 } );
var cube = new THREE.Mesh( geometry, material );
scene.add( cube );
var cylinder_geometry = new THREE.CylinderGeometry(0.5,0.5,5);
var cylinder_material = new THREE.MeshBasicMaterial( { color: 0xaaaaff });
var cylinder = new THREE.Mesh(cylinder_geometry, cylinder_material);
cylinder.matrix.makeRotationAxis( new THREE.Vector3(1,0,1).normalize(), 45*Math.PI/180);
cylinder.matrixAutoUpdate = false;
scene.add( cylinder );
stats = new Stats();
stats.domElement.style.position = 'absolute';
stats.domElement.style.top = '0px';
document.body.appendChild( stats.domElement );
Coordinates.drawAllAxes();
controls = new THREE.OrbitControls( camera );
controls.addEventListener( 'change', Render );
}
function Update() {
requestAnimationFrame( Update );
controls.update();
stats.update();
Render();
}
function Render() {
renderer.render(scene, camera);
}
Start();
Update();
</script>
</body>
</html>