3D Game Programming

(C. Jardin) #1
// This is where stuff in our game will happen:
varscene =newPhysijs.Scene({ fixedTimeStep: 2 / 60 });
scene.setGravity(newTHREE.Vector3( 0, -100, 0 ));

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

camera.position.z = 500;
scene.add(camera);

// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.WebGLRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);
document.body.style.backgroundColor ='#9999aa';

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

/*
// Perspective camera border
function makeBorder(x, y, w, h) {
var border = new Physijs.BoxMesh(
new THREE.CubeGeometry(1.2*w, 1.2*h, 100),
Physijs.createMaterial(
new THREE.MeshBasicMaterial({color: 0x000000}), 0.2, 1.0
),
0
);
border.position.set(1.2*x, 1.2*y, 0);
return border;
}
*/
functionmakeBorder(x, y, w, h) {
varborder =newPhysijs.BoxMesh(
newTHREE.CubeGeometry(w, h, 100),
Physijs.createMaterial(
newTHREE.MeshBasicMaterial({color: 0x000000}), 0.2, 1.0
),
0
);
border.position.set(x, y, 0);
returnborder;
}

Appendix 1. Project Code • 260


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf