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 -
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.