Skip to content

Commit faaee95

Browse files
author
Jos Dirksen
committed
Added camera explicitly to reflect book
1 parent 441c8d9 commit faaee95

File tree

4 files changed

+22
-28
lines changed

4 files changed

+22
-28
lines changed

chapter-02/05-custom-geometry.html

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -156,14 +156,14 @@
156156
gui.add(new function() {
157157
this.clone = function() {
158158

159-
var cloned = mesh.children[0].geometry.clone();
159+
var clonedGeometry = mesh.children[0].geometry.clone();
160160
var materials = [
161161
new THREE.MeshLambertMaterial( { opacity:0.6, color: 0xff44ff, transparent:true } ),
162162
new THREE.MeshBasicMaterial( { color: 0x000000, wireframe: true } )
163163

164164
];
165165

166-
var mesh2 = THREE.SceneUtils.createMultiMaterialObject(cloned,materials);
166+
var mesh2 = THREE.SceneUtils.createMultiMaterialObject(clonedGeometry,materials);
167167
mesh2.children.forEach(function(e) {e.castShadow=true});
168168

169169
mesh2.translateX(5);

chapter-02/06-mesh-properties.html

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -103,13 +103,14 @@
103103
this.visible = true;
104104

105105
this.translate = function() {
106-
cube.translateX(this.translateX);
107-
cube.translateY(this.translateX);
108-
cube.translateZ(this.translateX);
109106

110-
this.positionX = cube.position.x;
111-
this.positionY = cube.position.y;
112-
this.positionZ = cube.position.z;
107+
cube.translateX(controls.translateX);
108+
cube.translateY(controls.translateY);
109+
cube.translateZ(controls.translateZ);
110+
111+
controls.positionX = cube.position.x;
112+
controls.positionY = cube.position.y;
113+
controls.positionZ = cube.position.z;
113114
}
114115
}
115116

chapter-02/07-both-cameras.html

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@
102102
this.switchCamera = function() {
103103
if (camera instanceof THREE.PerspectiveCamera) {
104104
camera = new THREE.OrthographicCamera( window.innerWidth / - 16, window.innerWidth / 16, window.innerHeight / 16, window.innerHeight / - 16, -200, 500 );
105-
camera.position.x = 3;
106-
camera.position.y = 1;
107-
camera.position.z = 3;
105+
camera.position.x = 120;
106+
camera.position.y = 60;
107+
camera.position.z = 180;
108108
camera.lookAt(scene.position);
109109
this.perspective = "Orthographic";
110110
} else {
@@ -113,10 +113,6 @@
113113
camera.position.y = 60;
114114
camera.position.z = 180;
115115

116-
camera.zoom = 0.5;
117-
camera.updateProjectionMatrix();
118-
119-
120116
camera.lookAt(scene.position);
121117
this.perspective = "Perspective";
122118
}

chapter-02/08-cameras-lookat.html

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -64,12 +64,12 @@
6464

6565
var cubeGeometry = new THREE.BoxGeometry(4,4,4);
6666
var cubeMaterial = new THREE.MeshLambertMaterial({color: 0x00ee22});
67-
for (var j = 0 ; j < (planeGeometry.height/5) ; j++) {
68-
for (var i = 0 ; i < planeGeometry.width/5 ; i++) {
67+
for (var j = 0 ; j < (planeGeometry.parameters.height/5) ; j++) {
68+
for (var i = 0 ; i < planeGeometry.parameters.width/5 ; i++) {
6969
var cube = new THREE.Mesh(cubeGeometry, cubeMaterial);
7070

71-
cube.position.z=-((planeGeometry.height)/2)+2+(j*5);
72-
cube.position.x=-((planeGeometry.width)/2)+2+(i*5);
71+
cube.position.z=-((planeGeometry.parameters.height)/2)+2+(j*5);
72+
cube.position.x=-((planeGeometry.parameters.width)/2)+2+(i*5);
7373
cube.position.y=2;
7474

7575
scene.add(cube);
@@ -102,9 +102,10 @@
102102
this.switchCamera = function() {
103103
if (camera instanceof THREE.PerspectiveCamera) {
104104
camera = new THREE.OrthographicCamera( window.innerWidth / - 16, window.innerWidth / 16, window.innerHeight / 16, window.innerHeight / - 16, -200, 500 );
105-
camera.position.x = 2;
106-
camera.position.y = 1;
107-
camera.position.z = 3;
105+
camera.position.x = 120;
106+
camera.position.y = 60;
107+
camera.position.z = 180;
108+
108109
camera.lookAt(scene.position);
109110
this.perspective = "Orthographic";
110111
} else {
@@ -136,14 +137,10 @@
136137
stats.update();
137138
// render using requestAnimationFrame
138139
step+=0.02;
139-
if (camera instanceof THREE.PerspectiveCamera) {
140+
if (camera instanceof THREE.Camera) {
140141
var x = 10+( 100*(Math.sin(step)));
141142
camera.lookAt(new THREE.Vector3(x,10,0));
142-
lookAtMesh.position=new THREE.Vector3(x,10,0);
143-
} else {
144-
var x = ((Math.cos(step)));
145-
camera.lookAt(new THREE.Vector3(x,0,0));
146-
lookAtMesh.position=new THREE.Vector3(x,10,0);
143+
lookAtMesh.position.copy(new THREE.Vector3(x,10,0));
147144
}
148145

149146
// .position.x = 20+( 10*(Math.cos(step)));

0 commit comments

Comments
 (0)