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.

Other Visual Effects<br />

Introduction<br />

Although adding texture to a 3D object is the commonest way of changing an<br />

object's appearance, it is by no means the only option available. In this section we'll<br />

see some other options that are available to us in <strong>DarkBASIC</strong> <strong>Pro</strong>.<br />

Changing Colour and Transparency<br />

FIG-32.23<br />

The COLOR OBJECT<br />

Statement<br />

LISTING-32.11<br />

The COLOR OBJECT Statement<br />

Using COLOR OBJECT<br />

Rather than add a texture to a 3D object, we can give it a surface of a specific colour<br />

using the COLOR OBJECT statement which has the format shown in FIG-32.23.<br />

In the diagram:<br />

COLOR OBJECT objno<br />

colour<br />

objno is an integer value specifying the object which is<br />

to be coloured.<br />

colour is an integer value specifying the colour to be<br />

used on the object's surface.<br />

For example, we could give object 1 a red surface using the line:<br />

COLOR OBJECT 1, RGB(255,0,0)<br />

An example of this statement in operation is given in LISTING-32.11 which colours<br />

a rotating cube in red, changing to green when a random event occurs.<br />

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

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

REM *** Seed random number generator ***<br />

RANDOMIZE TIMER()<br />

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

MAKE OBJECT CUBE 1, 40<br />

POSITION OBJECT 1,25,0,100<br />

REM *** Colour cube red ***<br />

COLOR OBJECT 1, RGB(255,0,0)<br />

REM *** Rotate Cube ***<br />

DO<br />

PITCH OBJECT DOWN 1, 1.0<br />

TURN OBJECT LEFT 1, 1.0<br />

REM *** <strong>On</strong>e chance in 1000 of changing to green ***<br />

IF RND(1000) = 500<br />

COLOR OBJECT 1, RGB(0,255,0)<br />

ENDIF<br />

LOOP<br />

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

END<br />

<strong>DarkBASIC</strong> <strong>Pro</strong>: Texturing 815<br />

,

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

Saved successfully!

Ooh no, something went wrong!