3D Game Programming

(C. Jardin) #1
var scene = new Physijs.Scene({ fixedTimeStep: 2 / 60 });
scene.setGravity(new THREE.Vector3( 0, -20, 0 ));

// This is what sees the stuff:
var width = window.innerWidth,
height = window.innerHeight,
aspect_ratio = width / height;
var camera = new THREE.PerspectiveCamera(75, aspect_ratio, 1, 1e6);
// var camera = new THREE.OrthographicCamera(
// -width/2, width/2, height/2, -height/2, 1, 10000
// );

camera.position.set(250, 250, 250);
camera.lookAt(new THREE.Vector3(0, 0, 0));
scene.add(camera);

// This will draw what the camera sees onto the screen:
var renderer = new THREE.WebGLRenderer();
renderer.shadowMapEnabled = true;
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
document.body.style.backgroundColor = '#ffffff';

// ******** START CODING ON THE NEXT LINE ********

addSunlight(scene);
var scoreboard = addScoreboard();
var river = addRiver(scene);
var raft = addRaft(scene);
var game_items = [];
var paused;
startGame(raft, river, scoreboard);

function addSunlight(scene) {
var sunlight = new THREE.DirectionalLight();
sunlight.intensity = 0.5;
sunlight.castShadow = true;
sunlight.position.set(250, 250, 250);
sunlight.shadowCameraNear = 250;
sunlight.shadowCameraFar = 600;
sunlight.shadowCameraLeft = -200;
sunlight.shadowCameraRight = 200;
sunlight.shadowCameraTop = 200;
sunlight.shadowCameraBottom = -200;
sunlight.shadowMapWidth = 4096;
sunlight.shadowMapHeight = 4096;

scene.add(sunlight);
}

Appendix 1. Project Code • 266


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf