3D Game Programming

(C. Jardin) #1

APPENDIX 1


Project Code


This appendix contains completed versions of all of the projects created in
this book. Your code may not be exactly the same as the code that follows
—that’s OK. The code is included in case you run into problems and want to
be able to compare your code to a working version.

A1.1 Code: Creating Simple Shapes


This is the final version of the shapes code from Chapter 1, Project: Creating
Simple Shapes, on page 1.

<body></body>
<script src="http://gamingJS.com/Three.js"></script>
<script src="http://gamingJS.com/ChromeFixes.js"></script>
<script>
// This is where stuff in our game will happen:
varscene =newTHREE.Scene();

// This is what sees the stuff:
varaspect_ratio = window.innerWidth / window.innerHeight;
varcamera =newTHREE.PerspectiveCamera(75, aspect_ratio, 1, 10000);
camera.position.z = 400;
scene.add(camera);

// This will draw what the camera sees onto the screen:
varrenderer =newTHREE.CanvasRenderer();
renderer.setSize(window.innerWidth, window.innerHeight);
document.body.appendChild(renderer.domElement);

// ******** START CODING ON THE NEXT LINE ********
varshape =newTHREE.SphereGeometry(100);
varcover =newTHREE.MeshNormalMaterial();
varball =newTHREE.Mesh(shape, cover);
scene.add(ball);
ball.position.set(-250,250,-250);

Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf