Rotating Objects

Rotating your objects is similar to moving them in that you need to define which keys you want to use to rotate your objects and on which axis you’d like to rotate them. The axis for the rotation will determine how your objects will spin. Rotation can occur along the x axis, the y axis, or the z axis (see Figures 6.2, 6.3, and 6.4).

Figure 6.2. Rotation along the x axis.


Figure 6.3. Rotation along the y axis.


Figure 6.4. Rotation along the z axis.


Using the same program as above, let’s add the following code above the RenderWorld line to add rotation controls:

; Change rotation values depending on the key pressed
If KeyDown(N_KEY)= True Then pitch#=pitch#-1
If KeyDown(M_KEY)=True Then pitch#=pitch#+1
If KeyDown(COMMA)=True Then yaw#=yaw#-1
If KeyDown(PERIOD)=True Then yaw#=yaw#+1
If KeyDown(X_KEY)=True Then roll#=roll#-1
If KeyDown(C_KEY)=True Then roll#=roll#+1

;Rotate
RotateEntity sphere,pitch#,yaw#,roll#

Now, run the program and you’ll see that, by pressing the keys M, N, comma, period, X, and C, you can rotate your object along the different axes. Here’s a breakdown of the code that we just entered:

If KeyDown (N_KEY)= True means that when the letter “n” is pressed on the keyboard, then do the following. Pitch#=pitch#+1 basically says that the pitch of the object should change positively (in other words, rotate clockwise) on the x axis by one unit. The rest of this section of code is the same but changes the values positively and negatively for pitch, yaw, and roll.

The next section tells Blitz3D what to rotate:

RotateEntity sphere,pitch#,yaw#,roll#

Here we are telling Blitz3D to rotate the object called sphere by the amount we defined in the previous section of code.

..................Content has been hidden....................

You can't read the all page of ebook, please click here login for view all page.
Reset
3.133.133.233