3D Game Programming

(C. Jardin) #1
var center = Math.sin(4*Math.PI*row/size);
center = center * 0.1 * size;
center = Math.floor(center + size/2);
center = row*size + center;

for (var distance=0; distance<12; distance++) {
shape.vertices[center + distance].z = -5 * (12 - distance);
shape.vertices[center - distance].z = -5 * (12 - distance);
}

center_points.push(shape.vertices[center]);
}
shape.computeFaceNormals();
shape.computeVertexNormals();
return center_points;
}

function addWater(ground, size) {
var water = new Physijs.ConvexMesh(
new THREE.CubeGeometry(1.4*size, 1.4*size, 10),
Physijs.createMaterial(
new THREE.MeshBasicMaterial({color: 0x0000bb}),
0, // No friction (slippery as ice)
0.01 // Not very bouncy at all
),
0 // Never move
);
water.position.z = -20;
water.receiveShadow = true;
ground.add(water);
}

function addLid(ground, size) {
var lid = new Physijs.ConvexMesh(
new THREE.CubeGeometry(size, size, 1),
new THREE.MeshBasicMaterial({visible:false})
);
ground.add(lid);
}

function addSharkJump(pos, ground) {
var ramp = new Physijs.ConvexMesh(
new THREE.CubeGeometry(10, 8, 3),
new THREE.MeshPhongMaterial({emissive: 0xbb0000})
);
ramp.receiveShadow = true;
ramp.rotation.x = -Math.PI/10;
ramp.position.copy(pos);
ramp.position.z = pos.z + 10;
ground.add(ramp);

Appendix 1. Project Code • 268


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf