3D Game Programming

(C. Jardin) #1
function addScoreboard() {
var scoreboard = new Scoreboard();
scoreboard.score(0);
scoreboard.timer();
scoreboard.help(
'left / right arrow keys to turn. ' +
'space bar to move forward.'
);

return scoreboard;
}

function addRiver(scene) {
var ground = makeGround(500);
addWater(ground, 500);
addLid(ground, 500);

scene.add(ground);

return ground;
}

function makeGround(size) {
var faces = 100;
var shape = new THREE.PlaneGeometry(size, size, faces, faces);
var river_points = digRiver(shape, faces + 1);

var cover = Physijs.createMaterial(
new THREE.MeshPhongMaterial({
emissive: new THREE.Color(0x339933), // a little green
specular: new THREE.Color(0x333333) // dark gray / not shiny
}),
1, // high friction (hard to move across)
0.1 // not very bouncy
);

var ground = new Physijs.HeightfieldMesh(
shape, cover, 0
);
ground.rotation.set(-Math.PI/2, 0.2, -Math.PI/2);
ground.receiveShadow = true;
ground.castShadow = true;
ground.river_points = river_points;

return ground;
}

function digRiver(shape, size) {
var center_points = [];
for (var row=0; row<size; row++) {

report erratum • discuss

Code: River Rafting • 267


Prepared exclusively for Michael Powell

Free download pdf