BRender Tutorial Guide:2 Getting Started:Setting up the World Database
Next|Prev|Up

Setting up the World Database


Having initialised BRender, we must build the world database. The information contained here defines the shape, colour and texture of the models in a scene, as well as how they are related to one another in the world hierarchy. It also describes how the scene is lit and how much of it is initially `visible'.

Remember we build scenes using actors - camera actors, light actors, model actors. Another actor type, the None actor, is used as a reference point for scene building - it is used to structure the world database. A none actor is usually found at the root of an actor tree hierarchy.

BrActorAllocate allocates, or assigns, a new actor to the world database. BrActorAdd declares one allocated actor to be the child of another (and returns a pointer to the child actor). This is how actor hierarchies are constructed.

BRTUTOR1.C starts with a none (or `root') actor called `world',

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
It adds a model actor (the default cube) as a child of `world' and calls it `cube',

	cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
then adds a camera actor, also a child of `world', and calls it `observer',

	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
before adding and `turning on' the default light source,

	light = BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL));
	BrLightEnable(light);
A simple renderable world tree has been created:

Figure 32 Four-actor world tree

The world database now consists of -

This is the default condition depicted in Figure 31.

In order to make the cube visible we move, or translate, the camera position 5 units backwards along the positive z-axis:

	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat, BR_SCALAR(0.0) BR_SCALAR(0.0),
BR_SCALAR(5.0));
Note that the first line of the above code could have been omitted, as BR_TRANSFORM_MATRIX34 is the default transformation type.

Note that BRender uses a custom data type, br_scalar, to represent scalar values - it doesn't use the standard data types int and float . BR_SCALAR(), implemented as a macro, converts constants to the br_scalar data type.

We then rotate the cube 30xb0 around the y-axis (to accentuate its shape):

	cube->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30)); 
BR_ANGLE_DEG() converts between degrees and BRender's angle representation br_angle. Before moving an actor, a transformation type must be defined. Refer to your technical reference manual for a list of the transformation types available.


Generated with CERN WebMaker