3D Game Programming

(C. Jardin) #1

3.1 Getting Started


Let’s open the ICE Code Editor^1 again and create a new project named My
Avatar (check Start a New Project, on page 17, if you don’t remember how).

Be sure to leave the template set to 3D starter project. With that, we’re ready to
start programming on the line following START CODING ON THE NEXT LINE.

3.2 Making a Whole from Parts


From Chapter 1, Project: Creating Simple Shapes, on page 1, we already know
how to make basic shapes. Let’s start building our player avatar by making
a sphere for the body.

varcover =newTHREE.MeshNormalMaterial();
varbody =newTHREE.SphereGeometry(100);
varavatar =newTHREE.Mesh(body, cover);
scene.add(avatar);

We already know what happens when we type that in—we get a ball in the
center of the scene.

Let’s add a hand next to the body. Add the following lines below the code that
you already entered to create the body.

varhand =newTHREE.SphereGeometry(50);

varright_hand =newTHREE.Mesh(hand, cover);
right_hand.position.set(-150, 0, 0);
scene.add(right_hand);


  1. http://gamingJS.com/ice


Chapter 3. Project: Making an Avatar • 26


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf