3D Game Programming

(C. Jardin) #1

Figure 2—Avatar with Hands


3.3 Breaking It Down


Let’s take a quick look at why we used those numbers for the hands. If you’re
impatient, skip ahead to Section 3.4, Adding Feet for Walking, on page 29, to
keep building our game avatar.

When anything is added to a scene, it starts off in the very center. So when
we add the body and a hand, it starts off something like this:

In 3D programming and mathematics, left and right are called the X direction.
Up and down are called the Y direction.

This is why we change the X position of the hands:


varleft_hand =newTHREE.Mesh(hand, cover);
left_hand.position.set(150, 0, 0);
scene.add(left_hand);

The numbers inside left_hand.position.set(150, 0, 0) are the X, Y, and Z position of
the left hand (Z would be forward and backward). We set X to 150 while Y and
Z are both 0. This is really the same thing as left_hand.position.x = 150. As we’ll
see shortly, it can be very convenient to set multiple values on a single line.

Chapter 3. Project: Making an Avatar • 28


Prepared exclusively for Michael Powell report erratum • discuss

Free download pdf