BRender x86 Installation Guide:Appendices: Program Listings and Errata
Next|Prev|Up

Appendices: Program Listings and Errata

Documentation Errata
BRTUTOR1.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Illuminated Cube.
 */
#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"
int main()
{
	/*
	 * Need screen and back buffers for double-buffering, a Z-Buffer to store
	 * depth information, and a storage buffer for the currently loaded palette
	 */
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	/*
	 * The actors in the world: Need a root actor, a camera actor, a light actor,
	 * and a model actor
	 */
	br_actor *world, *observer, *light, *cube;
	int i;						/*counter*/	

/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	/*
	 * Initialise z-buffer renderer
	 */
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	/* 
	 * Allocate Back Buffer and Depth Buffer
	 */
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Start with None actor at root of actor tree and call it `world'
	 */
	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	/* 
	 * Add a camera actor as a child of None actor `world'
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	/* 
	 * Add and enable the default light source
	 */
	light = BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL));
	BrLightEnable(light);
	/* 
	 * Move camera 5 units along +z axis so model becomes visible
	 */
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Add a model actor, the default cube
	 */
	cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	/*
	 * Rotate cube to enhance visibility
	 */
	cube->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30)); 

 /********************** Animation Loop **********************************/
	/*
	 * Rotate cube around x-axis
	 */
	for(i=0; i < 360; i++)  {
					/*
					 * Initialise depth buffer and set background colour to black
					 */
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					/*
					 * Render scene
					 */
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					/*
					 * Rotate cube
					 */
					BrMatrix34PostRotateX(&cube->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR1.C

BRTUTOR2.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to display a scene containing a Box, a Sphere and a Torus
 */
#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"
int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *world, *observer, *light, *box, *sphere, *torus;
	int i;
	br_camera *camera_data;
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Load root actor
	 */

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	/* 
	 * Add and enable the default light source
	 */
	light = BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL));
	BrLightEnable(light);
	/* 
	 * Load and position camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(10.0));
	camera_data = (br_camera *)observer->type_data;
	camera_data->yon_z = BR_SCALAR(50);
	/* 
	 * Load and position Box model
	 */
	box = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	box->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&box->t.t.mat,BR_ANGLE_DEG(30)); 
	BrMatrix34PostTranslate(&box->t.t.mat,BR_SCALAR(-2.5), BR_SCALAR(0.0),
						BR_SCALAR(0.0));
	BrMatrix34PreScale(&box->t.t.mat,BR_SCALAR(2.0),BR_SCALAR(1.0),
							BR_SCALAR(1.0));
	/*
	 * Load and Position Sphere Model
	 */
	sphere = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	sphere->model = BrModelLoad("sph32.dat");
	BrModelAdd(sphere->model);
	sphere->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Translate(&sphere->t.t.mat,BR_SCALAR(2.0), BR_SCALAR(0.0),
						BR_SCALAR(0.0));
	/*
	 * Load and Position Torus Model
	 */
	torus = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	sphere->model = BrModelLoad("torus.dat");
	BrModelAdd(torus->model);
	torus->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Translate(&torus->t.t.mat,BR_SCALAR(0.0), BR_SCALAR(0.0),
						BR_SCALAR(3.0));

 /********************** Animation Loop **********************************/
	for(i=0; i < 360; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateX(&box->t.t.mat,BR_ANGLE_DEG(2.0));
					BrMatrix34PreRotateZ(&torus->t.t.mat,BR_ANGLE_DEG(4.0));
					BrMatrix34PreRotateY(&torus->t.t.mat,BR_ANGLE_DEG(-6.0));
					BrMatrix34PreRotateX(&torus->t.t.mat,BR_ANGLE_DEG(2.0));
					BrMatrix34PostRotateX(&torus->t.t.mat,BR_ANGLE_DEG(1.0));
					BrMatrix34PostRotateY(&sphere->t.t.mat,BR_ANGLE_DEG(0.8));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR2.C

BRTUTOR3.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to display a Planet, Moon, Satellite animation
 */
#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"
int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *universe, *observer, *light, *planet, *moon, *satellite;
	int i;
	br_camera *camera_data ;
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Load Root Actor
	 */
	universe = BrActorAllocate(BR_ACTOR_NONE,NULL);
	/* 
	 * Load and Enable Default Light Source
	 */
	light = BrActorAdd(universe,BrActorAllocate(BR_ACTOR_LIGHT,NULL));
	BrLightEnable(light);
	/* 
	 * Load and Position Camera
	 */
	observer = BrActorAdd(universe,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(6.0));
	camera_data = (br_camera *)observer->type_data;
	camera_data->yon_z = BR_SCALAR(50);
	/* 
	 * Load Planet Model
	 */
	planet = BrActorAdd(universe,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	planet->model = BrModelLoad("sph16.dat");
	BrModelAdd(planet->model);
	/*
	 * Load and Position Moon Model
	 */
	moon = BrActorAdd(planet,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	moon->model = BrModelLoad("sph8.dat");
	BrModelAdd(moon->model);
	moon->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Scale(&moon->t.t.mat,BR_SCALAR(0.5),BR_SCALAR(0.5),
											BR_SCALAR(0.5));
	BrMatrix34PostTranslate(&moon->t.t.mat,BR_SCALAR(0.0), BR_SCALAR(0.0),
						BR_SCALAR(2.0));
	/*
	 * Load and Position Satellite Model
	 */
	satellite = BrActorAdd(moon,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	satellite->model = BrModelLoad("sph8.dat");
	BrModelAdd(satellite->model);
	satellite->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Scale(&satellite->t.t.mat,BR_SCALAR(0.25), BR_SCALAR(0.25),
						BR_SCALAR(0.25));
	BrMatrix34PostTranslate(&satellite->t.t.mat,BR_SCALAR(1.5), BR_SCALAR(0.0),
						BR_SCALAR(0.0));

 /********************** Animation Loop **********************************/
	for(i=0; i < 1000; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(universe,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PreRotateY(&planet->t.t.mat,BR_ANGLE_DEG(1.0));
					BrMatrix34PreRotateY(&satellite->t.t.mat,BR_ANGLE_DEG(4.0));
					BrMatrix34PreRotateZ(&moon->t.t.mat,BR_ANGLE_DEG(1.5));
					BrMatrix34PostRotateZ(&satellite->t.t.mat,BR_ANGLE_DEG(-2.5));
					BrMatrix34PostRotateY(&moon->t.t.mat,BR_ANGLE_DEG(-2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR3.C

BRTUTOR4.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to display a Planet-Satellite animation
 */
#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"
int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *world, *observer, *cube, *planet, *sat, *wings1, *wings2;
	int i;
	br_camera *camera_data;					

/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	/* 
	 * Load and Position Camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(8.0));
	camera_data = (br_camera *)observer->type_data;
	camera_data->yon_z = BR_SCALAR(350);
	camera_data->hither_z = BR_SCALAR(0.5);
	/* 
	 * Load and Position Planet Actor
	 */
	planet = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	planet->model = BrModelLoad("sph32.dat");
	BrModelAdd(planet->model);
	planet->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Translate(&planet->t.t.mat,BR_SCALAR(14.0), BR_SCALAR(14.0),
						BR_SCALAR(-40.0));
	/*
	 * Load and Position Satellite 
	 */
	sat = BrActorAdd(planet,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	sat->model = BrModelLoad("sph16.dat");
	BrModelAdd(sat->model);
	sat->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Scale(&sat->t.t.mat,BR_SCALAR(0.5), BR_SCALAR(0.5),
						BR_SCALAR(0.5));
	BrMatrix34PostTranslate(&sat->t.t.mat,BR_SCALAR(2.0), BR_SCALAR(0.0),
						BR_SCALAR(0.0));
	/* Add `wings' to Satellite 
	 */
	wings1 = BrActorAdd(sat,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	wings1->model = BrModelLoad("cylinder.dat");
	BrModelAdd(wings1->model);
	wings1->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Scale(&wings1->t.t.mat,BR_SCALAR(0.25), BR_SCALAR(0.25),
						BR_SCALAR(2.0));
	/* Add more `wings' to Satellite 
	 */
	wings2 = BrActorAdd(sat,BrActorAllocate(BR_ACTOR_MODEL,NULL);
	wings2->model = BrModelLoad("cylinder.dat");
	BrModelAdd(wings2->model);
	wings2->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34Scale(&wings2->t.t.mat,BR_SCALAR(0.25), BR_SCALAR(0.25),
						BR_SCALAR(2.0));
	BrMatrix34PostRotateY(&wings2->t.t.mat,BR_ANGLE_DEG(90.0));

 /********************** Animation Loop **********************************/
	for(i=0; i < 500; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(universe,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostTranslate(&planet->t.t.mat,BR_SCALAR(-0.033),
							BR_SCALAR(-0.032),BR_SCALAR(0.1));
					BrMatrix34PreRotateY(&planet->t.t.mat,BR_ANGLE_DEG(1.0));
					BrMatrix34PreRotateX(&sat->t.t.mat,BR_ANGLE_DEG(15.0));
					BrMatrix34PreRotateY(&sat->t.t.mat,BR_ANGLE_DEG(10.0));
					BrMatrix34PostRotateZ(&sat->t.t.mat,BR_ANGLE_DEG(1.0));
					BrMatrix34PostRotateY(&sat->t.t.mat,BR_ANGLE_DEG(3.0));
	}
	/* Close down */
	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR4.C

BRTUTOR5.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Illuminated Blue Cube.
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer;
	br_actor *world, *observer, *cube;
	br_material *cube_material;
	int i;			
			
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("VESA,B:15");
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Load Root Actor. Load and Enable Deault Light Source
	 */
	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	/* 
	 *Load and Position Camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Position Cube Model
	 */
	cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	cube->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30));

	/*
	 * Load and Apply Cube's Material
	 */
	cube_material - BrFmtScriptMaterialLoad("cube.mat");
	BrMaterialAdd(cube_material);
	cube->material = BrMaterialFind("BLUE MATERIAL");

 /********************** Animation Loop **********************************/
	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateX(&cube->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR5.C

BRTUTR5B.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Illuminated Blue Cube (8-bit mode)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *world, *observer, *cube;
	br_material *cube_material;
	int i;			
			
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Load Root Actor. Load and Enable Deault Light Source
	 */
	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	/* 
	 *Load and Position Camera
	 */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Position Cube Model
	 */
	cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	cube->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30));
	/*
	 * Load and Apply Cube's Material
	 */
	cube_material - BrFmtScriptMaterialLoad("cube8.mat");
	BrMaterialAdd(cube_material);
	cube->material = BrMaterialFind("BLUE MATERIAL");
 /********************** Animation Loop **********************************/
	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateX(&cube->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}
BRTUTR5B.C

BRTUTOR6.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Sphere (15-bit colour)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer;
	br_actor *world, *observer, *planet;
	br_material *planet_material;
	int i;			
			
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("VESA,B:15");
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/* 
	 * Load and Position Planet Actor
	 */

	planet = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	planet->model = BrModelLoad("sph32.dat");
	BrModelAdd(planet->model);
	planet->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&planet->t.t.mat,BR_ANGLE(90));

	/* 
	 * Load and Register `earth' Texture
	 */
	BrMapAdd(BrPixelmapLoad("earth15.pix"));

	/*
	 * Load and Apply `earth' Material
	 */

	planet_material = BrFmtScriptMaterialLoad("earth.mat");
	BrMaterialAdd(planet_material);
	planet->material = BrMaterialFind("earth_map");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateY(&planet->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTOR6.C

BRTUTR6B.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Sphere (8-bit colour)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette, *shade;
	br_actor *world, *observer, *planet;
	br_material *planet_material;
	int i;			
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

	/*
	 * Load Shade Table
	 */

	shade = BrPixelmapLoad("shade.tab");
	if (shade==NULL);
		BR_ERROR("Couldn't load shade.tab");
	BrTableAdd(shade);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/* 
	 * Load and Position Planet Actor
	 */

	planet = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	planet->model = BrModelLoad("sph32.dat");
	BrModelAdd(planet->model);
	planet->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&planet->t.t.mat,BR_ANGLE(90));

	/* 
	 * Load and Register `earth' Texture
	 */

	BrMapAdd(BrPixelmapLoad("earth8.pix"));

	/*
	 * Load and Apply 'earth' Material
	 */

	planet_material - BrFmtScriptMaterialLoad("earth8.mat");
	BrMaterialAdd(planet_material);
	planet->material = BrMaterialFind("earth_.map");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateY(&planet->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTR6B.C

BRTUTOR7.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Yellow Duck (15-bit)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer;
	br_actor *world, *observer, *duck;
	br_material *mats[10]; /*for storing pointers to material descriptions*/
	int i;		
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("VESA,B:15");
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Apply Duck Materials
	 */

	i = BrFmtScriptMaterialLoadMany("duck.mat",mats,BR_ASIZE(mats));
	BrMaterialAddMany(mats,i);

	/* 
	 * Load and Position Duck Actor
	 */

	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&duck->t.t.mat,BR_ANGLE(30));

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateX(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTOR7.C

BRTUTR7B.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Yellow Duck (8-bit)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	br_actor *world, *observer, *duck;
	br_material *mats[10]; /*for storing pointers to material descriptions*/
	int i;		
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Apply Duck Materials
	 */

	i = BrFmtScriptMaterialLoadMAny("duck8.mat",mats,BR_ASIZE(mats));
	BrMaterialAddMany(mats,i);

	/* 
	 * Load and Position Duck Actor
	 */

	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&duck->t.t.mat,BR_ANGLE(30));

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);

					BrMatrix34PostRotateX(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTR7B.C

BRTUTOR8.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Duck (15-bit)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer;
	br_actor *world, *observer, *duck;
	br_pixelmap *gold_pm;
	int i;		
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("VESA,B:15");
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Register `gold' Texture
	 */
	gold_pm = BrPixelmapLoad("gold15.pix");
	if (gold_pm==NULL);
		BR_ERROR("Couldn't load gold15.pix");
	BrMapAdd(gold_pm);

	/*
	 * Load and Apply `gold' Material
	 */
	BrMaterialAdd(BrFmtScriptMaterialLoad("gold15.mat"));
	
	/* 
	 * Load and Position Duck Actor
	 */

	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	BrModelApplyMap(duck->model,BR_APPLYMAP_PLANE,NULL);
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&duck->t.t.mat,BR_ANGLE(30));
	duck->material = BrMaterialFind("gold15");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateY(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTOR8.C

BRTUTR8B.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Texture Mapped Duck (8-bit)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette, *shade;
	br_actor *world, *observer, *duck;
	br_pixelmap *gold_pm;
	int i;		
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

	/*
	 * Load Shade Table
	 */

	shade = BrPixelmapLoad("shade.tab");
	if (shade==NULL);
		BR_ERROR("Couldn't load shade.tab");
	BrTableAdd(shade);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Register `gold' Texture
	 */
	gold_pm = BrPixelmapLoad("gold8.pix");
	if (gold_pm==NULL);
		BR_ERROR("Couldn't load gold8.pix");
	BrMapAdd(gold_pm);

	/*
	 * Load and Apply `gold' Material
	 */

	BrMaterialAdd(BrFmtScriptMaterialLoad("gold8.mat"));
	
	/* 
	 * Load and Position Duck Actor
	 */

	duck = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	duck->model = BrModelLoad("duck.dat");
	BrModelAdd(duck->model);
	BrModelApplyMap(duck->model,BR_APPLYMAP_PLANE,NULL);
	duck->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&duck->t.t.mat,BR_ANGLE(30));
	duck->material = BrMaterialFind("gold8");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateY(&duck->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTR8B.C

BRTUTOR9.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Chrome-Textured Fork(8-bit)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette, *shade;
	br_actor *world, *observer, *fork;
	br_pixelmap *chrome_pm;
	int i;		
			
/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("MCGA");
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

	/*
	 * Load Shade Table
	 */

	shade = BrPixelmapLoad("shade.tab");
	if (shade==NULL);
		BR_ERROR("Couldn't load shade.tab");
	BrTableAdd(shade);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Register `chrome' Texture
	 */
	chrome_pm = BrPixelmapLoad("refmap.pix");
	if (chrome_pm==NULL);
		BR_ERROR("Couldn't load refmap.pix");
	BrMapAdd(chrome_pm);

	/*
	 * Load and Apply `fork' Material
	 */

	BrMaterialAdd(BrFmtScriptMaterialLoad("fork.mat"));
	
	/* 
	 * Load and Position Fork Actor
	 */

	fork = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	fork->model = BrModelLoad("fork.dat");
	BrModelAdd(fork->model);
	BrModelApplyMap(fork->model,BR_APPLYMAP_PLANE,NULL);
	fork->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateX(&fork->t.t.mat,BR_ANGLE(30));
	fork->material = BrMaterialFind("CHROME GIFMAP");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateX(&fork->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUTOR9.C

BRTUTR10.C

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Texture-Mapped Fork (15-bit mode)
 */

#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"

int main()
{
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer;
	br_actor *world, *observer, *fork;
	br_pixelmap *tile_pm;
	int i;					
	br_material *mats[10];

/************* Initialise BRender and Graphics Hardware *********************/

	BrBegin();

	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */

	screen_buffer = DOSGfxBegin("VESA,B:15");
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/

	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	BrLightEnable(BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL)));
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Load and Register TILE0011 Texture
	 */
	tile_pm = BrPixelmapLoad("refmap.pix");
	if (tile_pm==NULL);
		BR_ERROR("Couldn't load refmap.pix");
	BrMapAdd(tile_pm);

	/*
	 * Load and Apply fork Material
	 */

	i = BrMaterialAdd(BrFmtScriptMaterialLoad("fork.mat",mats,BR_ASIZE(mats));
	BrMaterialAddMany(mats,i);
	/* 
	 * Load and Position fork Actor
	 */

	fork = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	fork->model = BrModelLoad("fork.dat");
	BrModelAdd(fork->model);
	BrModelApplyMap(fork->model,BR_APPLYMAP_PLANE,NULL);
	fork->t.type = BR_TRANSFORM_MATRIX34;
	/*
	 * Assign fork material
	 */
	fork->material = BrMaterialFind("CHROME GIFMAP");

 /********************** Animation Loop **********************************/

	for(i=0; i < 200; i++)  {
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					BrZbSceneRender(world,observer,back_buffer,depth_buffer);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					BrMatrix34PostRotateY(&fork->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	DOSGfxEnd();
	BrEnd();
	return 0;
}

BRTUR10.C

BRTUTOR1.C WITH 3DMAX SUPPORT

/*
 * Copyright (c) 1996 Argonaut Technologies Limited. All rights reserved.
 * Program to Display a Revolving Illuminated Cube.
 */
#include <stddef.h>
#include <stdio.h>
#include "brender.h"
#include "dosio.h"
#include "stereo.h"
#define kInterocular BR_SCALAR( 0.05 )

#define kYaw BR_ANGLE_DEG( 1 )

int main(int argc, char **argv)
{
	/*
	 * Need screen and back buffers for double-buffering, a Z-Buffer to store
	 * depth information, and a storage buffer for the currently loaded palette
	 */
	br_pixelmap *screen_buffer, *back_buffer, *depth_buffer, *palette;
	/*
	 * The actors in the world: Need a root actor, a camera actor, a light actor,
	 * and a model actor
	 */
	br_actor *world, *observer, *light, *cube;
	int i;						/*counter*/	
/************* Initialise BRender and Graphics Hardware *********************/
	BrBegin();
	/*
	 * Initialise screen buffer and set up CLUT (ignored in true colour) 
	 */
	screen_buffer = KasanGfxBegin(NULL);
	palette = BrPixelmapLoad("std.pal");
	if(palette)
		DOSGfxPaletteSet(palette);
	/*
	 * Initialise z-buffer renderer
	 */
	BrZbBegin(screen_buffer->type, BR_PMT_DEPTH_16);
	/* 
	 * Allocate Back Buffer and Depth Buffer
	 */
	back_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_OFFSCREEN);
	back_buffer->origin_x = back_buffer->width/2;
	back_buffer->origin_y = back_buffer->height/2;
	depth_buffer = BrPixelmapMatch(screen_buffer,BR_PMMATCH_DEPTH_16);

/*************** Build the World Database **********************************/
	/* 
	 * Start with None actor at root of actor tree and call it `world'
	 */
	world = BrActorAllocate(BR_ACTOR_NONE,NULL);
	/* 
	 * Add a camera actor as a child of None actor `world */
	observer = BrActorAdd(world,BrActorAllocate(BR_ACTOR_CAMERA,NULL));
	/* 
	 * Add and enable the default light source
	 */
	light = BrActorAdd(world,BrActorAllocate(BR_ACTOR_LIGHT,NULL));
	BrLightEnable(light);
	/* 
	 * Move camera 5 units along +z axis so model becomes visible
	 */
	observer->t.type = BR_TRANSFORM_MATRIX34;  
	BrMatrix34Translate(&observer->t.t.mat,BR_SCALAR(0.0),BR_SCALAR(0.0), 
                                                         BR_SCALAR(5.0));
	/*
	 * Add a model actor, the default cube
	 */
	cube = BrActorAdd(world,BrActorAllocate(BR_ACTOR_MODEL,NULL));
	/*
	 * Rotate cube to enhance visibility
	 */
	cube->t.type = BR_TRANSFORM_MATRIX34;
	BrMatrix34RotateY(&cube->t.t.mat,BR_ANGLE_DEG(30)); 

 /********************** Animation Loop **********************************/
	/*
	 * Rotate cube around x-axis
	 */
	for(i=0; i < 360; i++)  {
					/*
					 * Initialise depth buffer and set background colour to black
					 */
					BrPixelmapFill(back_buffer,0);
					BrPixelmapFill(depth_buffer,0xFFFFFFFF);
					/*
					 * Render scene
					 */
					KasanZbSceneRender(world, observer, back_buffer, depth_buffer, kInterocular, kYaw);
					BrPixelmapDoubleBuffer(screen_buffer,back_buffer);
					/*
					 * Rotate cube
					 */
					BrMatrix34PostRotateX(&cube->t.t.mat,BR_ANGLE_DEG(2.0));
	}
	/* Close down */

	BrPixelmapFree(depth_buffer);
	BrPixelmapFree(back_buffer);
	BrZbEnd();
	KasanGfxEnd();
	BrEnd();
	return 0;
}
BRTUTOR1.C WITH 3DMAX SUPPORT

KASAN.C

/*
Wrappers around Kasan's 3D BIOS calls. 
Copyright (c) 1995 Stainless Software Ltd. and Argonaut Technologies Ltd.
*/
#include <i86.h>
#include <kasan.h>

/* INT 0x10 / AX = kKasan_presence_detect should return kKasan_signature */
#define kKasan_presence_detect			0x4ED0
#define kKasan_signature				0x3344

/* Most 3D BIOS calls are INT 0x10 / AX = kKasan_BIOS / BX = one of these: */
#define kKasan_BIOS						0x4FD0
#define kKasan_screen_off				0x3D00
#define kKasan_screen_on				0x3D01
#define kKasan_glasses_off				0x3D02
#define kKasan_glasses_on				0x3D03
#define kKasan_glasses_phase_toggle	0x3D04
#define kKasan_BIOS_information		0x3D10
#define kKasan_3D_information			0x3D13
#define kKasan_modify_IRQ_parameter	0x3D14

/* The next one goes in BH and a screen mode code goes in BL */
#define kKasan_mode_change				0x3D
#define kKasan_320x400x8				0x31
#define kKasan_512x700x8				0x35
#define kKasan_1024x700x8				0x39
#define kKasan_512x700x16				0x36
#define kKasan_1024x700x16				0x3A

/* Return presence of 3DMax glasses */
int KasanPresent( void )
{
	union REGPACK		regs;

	/* according to the Watcom manual the segment registers should always be valid and can be 0 */
	regs.w.ds = 0;
	regs.w.es = 0;
	regs.w.fs = 0;
	regs.w.gs = 0;

	regs.w.ax = kKasan_presence_detect;
	intr( 0x10, &regs );
	return (regs.w.dx == kKasan_signature);
}

void KasanScreenOn( void )
{
	union REGPACK		regs;


	regs.w.ds = 0;
	regs.w.es = 0;
	regs.w.fs = 0;
	regs.w.gs = 0;
	regs.w.ax = kKasan_BIOS;
	regs.w.bx = kKasan_screen_on;
	intr( 0x10, &regs );
}

void KasanGlassesOn( void )
{
	union REGPACK		regs;

	regs.w.ds = 0;
	regs.w.es = 0;
	regs.w.fs = 0;
	regs.w.gs = 0;
	regs.w.ax = kKasan_BIOS; /* required */
	regs.w.bx = kKasan_glasses_on;
	intr( 0x10, &regs );
}

void KasanGlassesOff( void )
{
	union REGPACK		regs;

	regs.w.ds = 0;
	regs.w.es = 0;
	regs.w.fs = 0;
	regs.w.gs = 0;
	regs.w.ax = kKasan_BIOS;
	regs.w.bx = kKasan_glasses_off;
	intr( 0x10, &regs );
}

void KasanScreenOff( void )
{
	union REGPACK		regs;

	regs.w.ds = 0;
	regs.w.es = 0;
	regs.w.fs = 0;
	regs.w.gs = 0;
	regs.w.ax = kKasan_BIOS;
	regs.w.bx = kKasan_screen_off;
	intr( 0x10, &regs );
}

KASAN.C

STEREO.C

/*
	Copyright (c) 1995 Stainless Software Ltd. and Argonaut Technologies Ltd.
*/
#include <stdlib.h>
#include <brender.h>
#include <dosio.h>
#include <kasan.h>
#include <stereo.h>

br_pixelmap * BR_PUBLIC_ENTRY KasanGfxBegin( char *pNew_setup_string )
{
	br_pixelmap *res;
	
	if (!KasanPresent())
		return (NULL);

	res = DOSGfxBegin( pNew_setup_string );
	KasanScreenOn();
	KasanGlassesOn();
	return (res);
}

void BR_PUBLIC_ENTRY KasanGfxEnd( void )
{
	KasanGlassesOff();
	KasanScreenOff();
	DOSGfxEnd();
}
/*
 * Matrix multiply for top 3x3 only
 */
#define A(x,y) A->m[x][y]
#define B(x,y) B->m[x][y]
#define C(x,y) C->m[x][y]

static void Matrix33Mul(br_matrix34 *A, br_matrix34 *B, br_matrix34 *C)
{
        A(0,0) = BR_MAC3(B(0,0),C(0,0), B(0,1),C(1,0), B(0,2),C(2,0));
        A(0,1) = BR_MAC3(B(0,0),C(0,1), B(0,1),C(1,1), B(0,2),C(2,1));
        A(0,2) = BR_MAC3(B(0,0),C(0,2), B(0,1),C(1,2), B(0,2),C(2,2));

        A(1,0) = BR_MAC3(B(1,0),C(0,0), B(1,1),C(1,0), B(1,2),C(2,0));
        A(1,1) = BR_MAC3(B(1,0),C(0,1), B(1,1),C(1,1), B(1,2),C(2,1));
        A(1,2) = BR_MAC3(B(1,0),C(0,2), B(1,1),C(1,2), B(1,2),C(2,2));

        A(2,0) = BR_MAC3(B(2,0),C(0,0), B(2,1),C(1,0), B(2,2),C(2,0));
        A(2,1) = BR_MAC3(B(2,0),C(0,1), B(2,1),C(1,1), B(2,2),C(2,1));
        A(2,2) = BR_MAC3(B(2,0),C(0,2), B(2,1),C(1,2), B(2,2),C(2,2));
}


#undef A
#undef B
#undef C

static void Rotate33YInPlace( br_matrix34 *m, br_angle a )
{
	br_matrix34	temp, 
				rot;
	int			i,
				j;

	BrMatrix34RotateY( &rot, a );
	Matrix33Mul( &temp, &rot, m);
	/* copy the 'top' of the matrix out but leave the bottom row alone */
	for (i=0; i<3; i++)
	{
		for (j=0; j<3; j++)
			(*m).m[i][j]=temp.m[i][j];
	}
}

void BR_PUBLIC_ENTRY KasanZbSceneRender(	br_actor 	*pWorld,
											br_actor 	*pCamera,
											br_pixelmap *pCol_buffer,
											br_pixelmap *pDepth_buffer,
											br_scalar 	pInterocular_distance,
											br_angle 	pCamera_yaw )
{
	br_matrix34		saved_camera_mat;
	br_uint_16		old_height,
					old_field_bytes,
					old_Z_bytes;	
			
	/* take copies of pixelmap fields which we frob to restore later */
	old_height = pCol_buffer->height;
	old_field_bytes = pCol_buffer->row_bytes;
	old_Z_bytes = pDepth_buffer->row_bytes;

	pCol_buffer->height /= 2;
	pCol_buffer->row_bytes *= 2;
	pDepth_buffer->row_bytes *= 2;

	saved_camera_mat = pCamera->t.t.mat;
	/* render the left field */
	pCamera->t.t.mat.m[3][0] -= BR_MUL(	pInterocular_distance / 2,
										pCamera->t.t.mat.m[0][0] );
	pCamera->t.t.mat.m[3][1] -= BR_MUL(	pInterocular_distance / 2,
										pCamera->t.t.mat.m[0][1] );
	pCamera->t.t.mat.m[3][2] -= BR_MUL(	pInterocular_distance / 2,
										pCamera->t.t.mat.m[0][2] );
	Rotate33YInPlace( &pCamera->t.t.mat, -pCamera_yaw );
	BrZbSceneRender(pWorld, pCamera, pCol_buffer, pDepth_buffer);
	pCamera->t.t.mat = saved_camera_mat;
	/* render the right field */
	pCol_buffer->pixels =	(char*)pCol_buffer->pixels + 
							pCol_buffer->row_bytes / 2;
	pDepth_buffer->pixels =	(char*)pDepth_buffer->pixels + 
						pDepth_buffer->row_bytes / 2;
	pCamera->t.t.mat.m[3][0] += BR_MUL(	pInterocular_distance / 2,
									pCamera->t.t.mat.m[0][0] );
	pCamera->t.t.mat.m[3][1] += BR_MUL(	pInterocular_distance / 2,
									pCamera->t.t.mat.m[0][1] );	 
	pCamera->t.t.mat.m[3][2] += BR_MUL(	pInterocular_distance / 2,
									pCamera->t.t.mat.m[0][2] );
	Rotate33YInPlace( &pCamera->t.t.mat, pCamera_yaw );
	BrZbSceneRender(pWorld, pCamera, pCol_buffer, pDepth_buffer);

	/* restore all we frobbed */
	pCol_buffer->pixels =	(char*)pCol_buffer->pixels -
							pCol_buffer->row_bytes / 2;
	pDepth_buffer->pixels =	(char*)pDepth_buffer->pixels -
						pDepth_buffer->row_bytes / 2;
	pCamera->t.t.mat = saved_camera_mat;
	pCol_buffer->height = old_height;
	pCol_buffer->row_bytes = old_field_bytes;
	pDepth_buffer->row_bytes = old_Z_bytes;
}

STEREO.C

MAIN.C

/*
   General BRender/Stereo glasses test code.
   Build a simple world and let the user fly around it.
   Bruce Mardle, Stainless Software, 1995.
*/

#include <stdio.h>
#include <stdlib.h>
#include <stdarg.h>
#include <string.h>

#include <brender.h>
#include <dosio.h>
#include "stereo.h"

#define SCALE_MIN BR_SCALAR(0.15)
#define SCALE_MAX BR_SCALAR(0.4)
#define SCALE_ITERATOR BR_DIV(SCALE_MAX - SCALE_MIN,BR_SCALAR(20))

#if defined(__WATCOMC__)
#define vsnprintf(str, size, format, args) _vbprintf(str, size, format, args)
#elif !defined(__bsdi__)
#define vsnprintf(str, size, format, args) sprintf(str, format, args)
#endif

#define kInterocular    BR_SCALAR( 0.05 )
#define kYaw                    BR_ANGLE_DEG( 1 )

#define kSmoothSwitch "smooth"

/* Fatal error messages. These all have "Error:" plonked before them. */
#define kUsageMsg  \
  "usage: %s image-width image-height distance-to-monitor ["kSmoothSwitch"]\n"
#define kDOSGfxMsg "failed to access graphics.\n"
#define kMemoryMsg "not enough memory.\n"
#define kStdPalMsg "failed to load std.pal\n"
#define kMatScrMsg "failed to load mat.scr\n"
#define kLoadFailedMsg "failed to load %s\n"

/* Measurements in the same units as the program arguments, nominally m: */
#define k4hedronEdge 1
#define kCameraHither 0.1
#define kCameraYon 200
#define kInitCameraHeight 1.6
#define kInitCameraDistance 9
#define kGndSide 20
  /* if kGndSide is too big it's displayed incorrectly. Hmm */

#define kGroundPixelmapName "256xlogo.pix"
#define kGroundShadeTableName "std.tab"
#define kSpin 10
#define kGravity 0.01
#define kParticles 20
#define kGndN 10
  /* number of triangles on each side of the 'ground' */
#define kBallRadius 100
  /* 'mickeys'. bigger numbers give less sensitivity */

#define MAX_MATERIALS 10

/* GLOBALS */
int flag3d,numMaterials;
br_material *material[MAX_MATERIALS];

static void cleanUp(void)
{
  DOSClockEnd();
  DOSMouseEnd();
  if(flag3d){
    KasanGfxEnd();
  }
  else{ 
    DOSGfxEnd();
  }
}

static void bomb(char *format, ...)
{
  va_list args;
  char msg[160];
  cleanUp();
  va_start(args, format);
  vsnprintf(msg, sizeof msg, format, args);
  BR_ERROR(msg);
  BrEnd();
  exit(1);
}

static br_actor *allocateAndAddActor
  (br_uint_8 actor_type, void *type_data, br_actor *parent)
{
  br_actor *n;
  if ((n=BrActorAllocate(actor_type, type_data))==NULL
      || (n=BrActorAdd(parent, n))==NULL /* impossible? */)
    bomb(kMemoryMsg);
  return(n);
}

typedef struct
{
  br_actor *actor;
  br_vector3 initV;
  int birthFrame;
} particle_t;
static void initParticle(particle_t *p, int frame) {
  static char count=0;
  count++;
  count%=numMaterials;
  /* Generate random initial velocity. */
  BrVector3Set(&p->initV,
    BR_SCALAR( (double)(rand()-(int)RAND_MAX/2)/RAND_MAX/5),
    BR_SCALAR(((double)(rand()-(int)RAND_MAX/2)/RAND_MAX+1)/2),
    BR_SCALAR( (double)(rand()-(int)RAND_MAX/2)/RAND_MAX/5));
      /* for some reason Watcom define RAND_MAX as an unsigned. Grr */
  p->birthFrame=frame;
  BrMatrix34Translate(&p->actor->t.t.mat, 0, 0, 0);
  /* Colour those hedrons */
  p->actor->material=material[count];
}

static void updateParticle(particle_t *p, int frame) {
  br_scalar y, t=BR_SCALAR(frame-p->birthFrame);
  /* Set particle pos.n to initV*t+(0,-kGravity,0)*t^2 */
  BrMatrix34Translate(&p->actor->t.t.mat,
    BR_MUL(p->initV.v[0], t),
    (y=BR_MUL(BR_SUB(p->initV.v[1], BR_MUL(BR_SCALAR(kGravity), t)), t)),
    BR_MUL(p->initV.v[2], t));
  BrMatrix34PreRotateY(&p->actor->t.t.mat,
    BrDegreeToAngle(BR_MUL(t, BR_SCALAR(kSpin))));
  if (y<-BR_SCALAR(k4hedronEdge))
    initParticle(p, frame);
}

int main(int argc, char **argv)
{
  unsigned imageWidth, imageHeight; /* as seen on the monitor */
  unsigned monitorDistance;
  br_pixelmap *screenBuffer, *backBuffer, *ZBuffer, *palette;
  br_actor *world, *viewpoint, *camera, *tetra, *ground, *actor /* temp */;
  particle_t particle[kParticles];
  br_model *model /* temp */;
  br_int_32 oldMouseX, mouseX, oldMouseY, mouseY;
  br_uint_32 mouseButtons;
  int frame, i, j, smooth,scaleDirection=!NULL;
  br_material *groundMaterial;
  br_scalar scale=SCALE_MIN;

  /*
     Set up all the things which can cause chaos and confusion
     so we know which things to tidy up when if we bomb out.
  */
  BrBegin();
  if (argc!=4 && argc!=5
      || sscanf(argv[1], "%u", &imageWidth)!=1
      || sscanf(argv[2], "%u", &imageHeight)!=1
      || sscanf(argv[3], "%u", &monitorDistance)!=1
      || (smooth=argc==5) && strcmp(argv[4], kSmoothSwitch))
  {
    BR_ERROR1(kUsageMsg, argv[0]);
    exit(1);
  }
  if (!(flag3d=(int)(screenBuffer=KasanGfxBegin(NULL))))
    if ((screenBuffer=DOSGfxBegin(NULL))==NULL){
      BR_ERROR0(kDOSGfxMsg);
      exit(1);
    }
  DOSMouseBegin();
  DOSClockBegin();

  /* Set up other vital things. */
  if ((backBuffer=BrPixelmapMatch(screenBuffer, BR_PMMATCH_OFFSCREEN))==NULL)
    bomb(kMemoryMsg);
  if ((ZBuffer=BrPixelmapMatch(screenBuffer, BR_PMMATCH_DEPTH_16))==NULL)
    bomb(kMemoryMsg);
  BrZbBegin(screenBuffer->type, ZBuffer->type);
  if ((palette=BrPixelmapLoad("std.pal"))==NULL)
    bomb(kStdPalMsg);
  DOSGfxPaletteSet(palette);
  if (!(numMaterials=BrFmtScriptMaterialLoadMany(smooth?"smooth.scr":"flat.scr",material,MAX_MATERIALS)))
    bomb(kMatScrMsg);
  BrMaterialAddMany(material,numMaterials);

  /* Create the world. */
  if ((world=BrActorAllocate(BR_ACTOR_NONE, NULL))==NULL)
    bomb(kMemoryMsg);
  viewpoint=allocateAndAddActor(BR_ACTOR_NONE, NULL, world);
  BrMatrix34Translate(&viewpoint->t.t.mat,
    0, BR_SCALAR(kInitCameraHeight), BR_SCALAR(kInitCameraDistance));
  camera=allocateAndAddActor(BR_ACTOR_CAMERA, NULL, viewpoint);
  ((br_camera*)camera->type_data)->type=BR_CAMERA_PERSPECTIVE_OLD;
  ((br_camera*)camera->type_data)->aspect=
    BR_DIV(BR_SCALAR(imageWidth),BR_SCALAR(imageHeight));
  ((br_camera*)camera->type_data)->field_of_view=2*
    BR_ATAN2(BR_CONST_DIV(BR_SCALAR(imageWidth),2),BR_SCALAR(monitorDistance));
  ((br_camera*)camera->type_data)->hither_z=BR_SCALAR(kCameraHither);
  ((br_camera*)camera->type_data)->yon_z=BR_SCALAR(kCameraYon);
  BrLightEnable(actor=allocateAndAddActor(BR_ACTOR_LIGHT, NULL, viewpoint));
  ((br_light*)actor->type_data)->type=BR_LIGHT_POINT|BR_LIGHT_VIEW;
  ((br_light*)actor->type_data)->attenuation_c=BR_SCALAR(1.0);
  ((br_light*)actor->type_data)->attenuation_l=BR_SCALAR(0.0);
  ((br_light*)actor->type_data)->attenuation_q=BR_SCALAR(0.001);
  /* Parent of lots of tetrahedra: */
  tetra=allocateAndAddActor(BR_ACTOR_NONE, NULL, world);
  if ((model=BrModelAllocate("", 4, 4))==NULL)
    bomb(kMemoryMsg);
#define pa BR_SCALAR(0.353*k4hedronEdge)
#define pb BR_SCALAR(0.5*k4hedronEdge)
#define na (-pa)
#define nb (-pb)
  BrVector3Set(&model->vertices[0].p, pb,pa,0);
  BrVector3Set(&model->vertices[1].p, nb,pa,0);
  BrVector3Set(&model->vertices[2].p, 0,na,pb);
  BrVector3Set(&model->vertices[3].p, 0,na,nb);
  model->faces[0].vertices[0]=3;
  model->faces[0].vertices[1]=2;
  model->faces[0].vertices[2]=1;
  model->faces[1].vertices[0]=2;
  model->faces[1].vertices[1]=3;
  model->faces[1].vertices[2]=0;
  model->faces[2].vertices[0]=1;
  model->faces[2].vertices[1]=0;
  model->faces[2].vertices[2]=3;
  model->faces[3].vertices[0]=0;
  model->faces[3].vertices[1]=1;
  model->faces[3].vertices[2]=2;
  BrModelUpdate(model, BR_MODU_ALL);
  tetra->model=model;
#undef pa
#undef pb
#undef na
#undef nb
  /* The ground: a big triangle chopped into smaller ones: */
  actor=allocateAndAddActor(BR_ACTOR_MODEL, NULL, world);
  if ((model=BrModelAllocate("", (kGndN+1)*(kGndN+2)/2, kGndN*kGndN))==NULL)
    bomb(kMemoryMsg);
  for (i=0; i<=kGndN; i++)
    for (j=0; j<=i; j++)
      BrVector3Set(&model->vertices[i*(i+1)/2+j].p,
	BR_SCALAR((j*2-i)*0.5*kGndSide/kGndN),
	BR_SCALAR(0),
	BR_SCALAR((i*-1.732+2*kGndN/1.732)*0.5*kGndSide/kGndN));
  for (i=0; i<kGndN; i++)
  {
    for (j=0; j<=i; j++)
    {
      model->faces[i*i+2*j].vertices[0]=i*(i+1)/2+j;
      model->faces[i*i+2*j].vertices[1]=(i+1)*(i+2)/2+j+1;
      model->faces[i*i+2*j].vertices[2]=(i+1)*(i+2)/2+j;
      model->faces[i*i+2*j].smoothing=1;
    }
    for (j=0; j<i; j++)
    {
      model->faces[i*i+2*j+1].vertices[0]=i*(i+1)/2+j+1;
      model->faces[i*i+2*j+1].vertices[1]=(i+1)*(i+2)/2+j+1;
      model->faces[i*i+2*j+1].vertices[2]=i*(i+1)/2+j;
      model->faces[i*i+2*j+1].smoothing=1;
    }
  }
  actor->model=model;
  if ((actor->material=BrMaterialAllocate(""))==NULL)
    bomb(kMemoryMsg);
  groundMaterial=actor->material;
  ground=actor;
  if (smooth){
    actor->material->flags|=BR_MATF_SMOOTH|BR_MATF_PERSPECTIVE;
  }
  else{
    actor->material->flags|=BR_MATF_PERSPECTIVE;
  }
  if ((actor->material->colour_map=BrPixelmapLoad(kGroundPixelmapName))==NULL)
    bomb(kLoadFailedMsg, kGroundPixelmapName);
  if ((actor->material->index_shade=BrPixelmapLoad(kGroundShadeTableName))==NULL)
    bomb(kLoadFailedMsg, kGroundShadeTableName);
  {
    br_matrix34 mm;
    BrModelFitMap(model, BR_FITMAP_PLUS_X, BR_FITMAP_PLUS_Z, &mm);
    BrModelApplyMap(model, BR_APPLYMAP_PLANE, &mm);
  }
 BrMapAdd(groundMaterial->colour_map);
 BrMaterialAdd(groundMaterial);
 BrModelAdd(model);

  /* Lots of little tetrahedra */
  for (i=0; i<kParticles; i++)
  {
    particle[i].actor=allocateAndAddActor(BR_ACTOR_MODEL, NULL, tetra);
    initParticle(particle+i, 0);
  }

  /* Display the scene */
  DOSMouseRead(&oldMouseX, &oldMouseY, &mouseButtons);
  for (frame=0;
       !(mouseButtons&BR_MSM_BUTTONR) || !(mouseButtons&BR_MSM_BUTTONL);
       frame++)
  {
    br_matrix34 m;
    
    groundMaterial->map_transform.m[0][0]=BR_MUL(scale,BR_COS(BrDegreeToAngle(BR_SCALAR(frame*3))));
    groundMaterial->map_transform.m[0][1]=BR_MUL(scale,BR_SIN(BrDegreeToAngle(BR_SCALAR(frame*3))));
    groundMaterial->map_transform.m[1][0]=BR_MUL(BR_SCALAR(-1),BR_MUL(scale,BR_SIN(BrDegreeToAngle(BR_SCALAR(frame*3)))));
    groundMaterial->map_transform.m[1][1]=BR_MUL(scale,BR_COS(BrDegreeToAngle(BR_SCALAR(frame*3))));
    BrMaterialUpdate(groundMaterial,BR_MATU_MAP_TRANSFORM);
    scale+=scaleDirection?SCALE_ITERATOR:BR_NEG(SCALE_ITERATOR);
    if (scale>SCALE_MAX||scale<SCALE_MIN)
	scaleDirection=!scaleDirection;
    /* Process user input */
    DOSMouseRead(&mouseX, &mouseY, &mouseButtons);
    /* Limit rate of change: */
    if (mouseX-oldMouseX>10)
      mouseX=oldMouseX+10;
    if (mouseX-oldMouseX<-10)
      mouseX=oldMouseX-10;
    if (mouseY-oldMouseY>10)
      mouseY=oldMouseY+10;
    if (mouseY-oldMouseY<-10)
      mouseY=oldMouseY-10;
    BrMatrix34RollingBall(&m, (br_int_16)(oldMouseX-mouseX),
      (br_int_16)(mouseY-oldMouseY), kBallRadius);
    BrMatrix34Pre(&viewpoint->t.t.mat, &m);
    if (mouseButtons&BR_MSM_BUTTONL)
      BrMatrix34PostTranslate(&viewpoint->t.t.mat,
	BR_CONST_MUL(viewpoint->t.t.mat.m[2][0], -1),
	BR_CONST_MUL(viewpoint->t.t.mat.m[2][1], -1),
	BR_CONST_MUL(viewpoint->t.t.mat.m[2][2], -1));
    if (mouseButtons&BR_MSM_BUTTONR)
      BrMatrix34PostTranslate(&viewpoint->t.t.mat,
	viewpoint->t.t.mat.m[2][0],
	viewpoint->t.t.mat.m[2][1],
	viewpoint->t.t.mat.m[2][2]);
    /* Update particles */
    for (i=0; i<kParticles; i++)
      updateParticle(particle+i, frame);
    /* Update display */
    BrPixelmapFill(backBuffer, 0);
    BrPixelmapFill(ZBuffer, 0xFFFFFFFF);
    if(flag3d){
      KasanZbSceneRender(world, camera, backBuffer, ZBuffer, kInterocular, kYaw);
    }
    else{ 
      BrZbSceneRender(world, camera, backBuffer, ZBuffer);
    }
    BrPixelmapDoubleBuffer(screenBuffer, backBuffer);
    /* Where were we? */
    oldMouseX=mouseX;
    oldMouseY=mouseY;
  }

  cleanUp();
  BrEnd();
  return(0);
}

MAIN.C


Generated with CERN WebMaker