Skip to content

Commit 6c03a21

Browse files
committed
3.1.1 Cube, Plane, Sphere
1 parent bb36b3d commit 6c03a21

File tree

1 file changed

+97
-0
lines changed

1 file changed

+97
-0
lines changed

Chapter3/3.1.1.html

Lines changed: 97 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,97 @@
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+
var camera = new THREE.OrthographicCamera(-5, 5, 3.75, -3.75, 0.1, 100);
16+
camera.position.set(25, 25, 25);
17+
camera.lookAt(new THREE.Vector3(0, 0, 0));
18+
scene.add(camera);
19+
20+
// draw axes to help you understand the coordinate
21+
drawAxes(scene);
22+
23+
var material = /*[new THREE.MeshBasicMaterial({
24+
color: 0
25+
}), */new THREE.MeshBasicMaterial({
26+
color: 0xffff00,
27+
wireframe: true,
28+
transparent: true
29+
});
30+
31+
//drawCube(scene, material);
32+
//drawPlane(scene, material);
33+
drawSphere(scene, material);
34+
35+
// render
36+
renderer.render(scene, camera);
37+
}
38+
39+
function drawCube(scene, material) {
40+
var cube = new THREE.Mesh(new THREE.CubeGeometry(1, 2, 3, 2, 2, 3), material);
41+
scene.add(cube);
42+
}
43+
44+
function drawPlane(scene, material) {
45+
var plane = new THREE.Mesh(new THREE.PlaneGeometry(2, 4), material);
46+
scene.add(plane);
47+
}
48+
49+
function drawSphere(scene, material) {
50+
var sphere = new THREE.Mesh(new THREE.SphereGeometry(3, 8, 6,
51+
Math.PI / 6, Math.PI / 3), material);
52+
//var sphere = new THREE.Mesh(new THREE.SphereGeometry(3, 8, 6,
53+
// 0, Math.PI * 2, Math.PI / 6, Math.PI / 2), material);
54+
//var sphere = new THREE.Mesh(new THREE.SphereGeometry(3, 8, 6,
55+
// Math.PI / 2, Math.PI, Math.PI / 6, Math.PI / 2), material);
56+
sphere.flipSided = true;
57+
scene.add(sphere);
58+
}
59+
60+
function drawAxes(scene) {
61+
// x-axis
62+
var xGeo = new THREE.Geometry();
63+
xGeo.vertices.push(new THREE.Vector3(0, 0, 0));
64+
xGeo.vertices.push(new THREE.Vector3(1, 0, 0));
65+
var xMat = new THREE.LineBasicMaterial({
66+
color: 0xff0000
67+
});
68+
var xAxis = new THREE.Line(xGeo, xMat);
69+
scene.add(xAxis);
70+
71+
// y-axis
72+
var yGeo = new THREE.Geometry();
73+
yGeo.vertices.push(new THREE.Vector3(0, 0, 0));
74+
yGeo.vertices.push(new THREE.Vector3(0, 1, 0));
75+
var yMat = new THREE.LineBasicMaterial({
76+
color: 0x00ff00
77+
});
78+
var yAxis = new THREE.Line(yGeo, yMat);
79+
scene.add(yAxis);
80+
81+
// z-axis
82+
var zGeo = new THREE.Geometry();
83+
zGeo.vertices.push(new THREE.Vector3(0, 0, 0));
84+
zGeo.vertices.push(new THREE.Vector3(0, 0, 1));
85+
var zMat = new THREE.LineBasicMaterial({
86+
color: 0x00ccff
87+
});
88+
var zAxis = new THREE.Line(zGeo, zMat);
89+
scene.add(zAxis);
90+
}
91+
</script>
92+
</head>
93+
94+
<body onload="init()">
95+
<canvas id="mainCanvas" width="400px" height="300px" ></canvas>
96+
</body>
97+
</html>

0 commit comments

Comments
 (0)