13.01.2013 Views

Hands On DarkBASIC Pro - Digital Skills

Hands On DarkBASIC Pro - Digital Skills

Hands On DarkBASIC Pro - Digital Skills

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

LISTING-31.3<br />

Rotating an Object about<br />

all Three Axes<br />

FIG-31.26<br />

The ROTATE<br />

OBJECT Statement<br />

The program in LISTING-31.3 revolves a cube about all three axes at the same<br />

time.<br />

REM ** Set display mode ***<br />

SET DISPLAY MODE 1280,1024,32<br />

REM *** Create and position cube ***<br />

MAKE OBJECT CUBE 1, 40<br />

POSITION OBJECT 1, 0, 0, 200<br />

REM *** Rotate cube 1 degree at a time ***<br />

REM *** around all three axes ***<br />

FOR angle = 1 TO 360<br />

XROTATE OBJECT 1, angle<br />

YROTATE OBJECT 1, angle<br />

ZROTATE OBJECT 1, angle<br />

WAIT 10<br />

NEXT angle<br />

REM *** End program ***<br />

WAIT KEY<br />

END<br />

Activity 31.8<br />

Type in and test the program given above (object3D05.dbpro).<br />

The ROTATE OBJECT Statement<br />

Rather than use three separate statements to rotate an object about all three axes,<br />

the same effect can be achieved using the ROTATE OBJECT statement. This<br />

statement takes three values specifying, for each axis, the degree of rotation. The<br />

format of the statement is shown in FIG-31.26.<br />

ROTATE OBJECT objno<br />

, xangle , yangle , zangle<br />

In the diagram:<br />

objno is the integer value previously assigned to the object.<br />

xangle is a real number giving the angle (in degrees) to which the<br />

object is to be rotated about its x-axis.<br />

yangle is a real number giving the angle (in degrees) to which the<br />

object is to be rotated about its y-axis.<br />

zangle is a real number giving the angle (in degrees) to which the<br />

object is to be rotated about its z-axis.<br />

Activity 31.9<br />

, , ,<br />

Rewrite the program you created in the previous Activity, replacing the<br />

XROTATE, YROTATE and ZROTATE statements with a single ROTATE<br />

OBJECT statement, producing the same effect as before.<br />

All statements in the previous section rotate an object to a specific angle,<br />

768 <strong>DarkBASIC</strong> <strong>Pro</strong>: 3D Primitives

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!