Skip to content

Commit bb36b3d

Browse files
committed
2.4.1 Perspective camera
1 parent b017e21 commit bb36b3d

File tree

3 files changed

+41
-1
lines changed

3 files changed

+41
-1
lines changed
File renamed without changes.

Chapter2/2.3.1.html

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,12 +15,14 @@
1515
// canvas size is 400x300
1616
var camera = new THREE.OrthographicCamera(-2, 2, 1.5, -1.5, 1, 10);
1717
camera.position.set(0, 0, 5);
18+
//camera.lookAt(new THREE.Vector3(0, 0, 0));
1819
scene.add(camera);
1920

2021
// a cube in the scene
2122
var cube = new THREE.Mesh(new THREE.CubeGeometry(1, 1, 1),
2223
new THREE.MeshBasicMaterial({
23-
color: 0xff0000
24+
color: 0xff0000,
25+
wireframe: true
2426
})
2527
);
2628
scene.add(cube);

Chapter2/2.4.1.html

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
2+
<html>
3+
<head>
4+
<script type="text/javascript" src="../lib/three.js"></script>
5+
6+
<script type="text/javascript">
7+
function init() {
8+
var renderer = new THREE.WebGLRenderer({
9+
canvas: document.getElementById('mainCanvas')
10+
});
11+
renderer.setClearColor(0x000000);
12+
var scene = new THREE.Scene();
13+
14+
// camera
15+
// canvas size is 400x300
16+
var camera = new THREE.PerspectiveCamera(45, 400 / 300, 1, 10);
17+
camera.position.set(0, 0, 5);
18+
scene.add(camera);
19+
20+
// a cube in the scene
21+
var cube = new THREE.Mesh(new THREE.CubeGeometry(1, 1, 1),
22+
new THREE.MeshBasicMaterial({
23+
color: 0xff0000,
24+
wireframe: true
25+
})
26+
);
27+
scene.add(cube);
28+
29+
// render
30+
renderer.render(scene, camera);
31+
}
32+
</script>
33+
</head>
34+
35+
<body onload="init()">
36+
<canvas id="mainCanvas" width="400px" height="300px" ></canvas>
37+
</body>
38+
</html>

0 commit comments

Comments
 (0)