CM30075 Software Guide

CM30075 Software Guide

CM30075 – software guide

This is a rough guide to equally rough software – comprising a library of functions to help you build up a ray caster. The library files are divided into families.

Type help <filename> to get MATLAB help for any library file. For example

> help Cam_canonical

will print a description of the file to the MATLAB console. Not all files contain embedded help (this is part of the roughness).

The demo family: examples of code in use

demo_camera

demo_wirecam

The Brep family: deals with objects

Brep_cylinder – makes a cylinder

Brep_fprintf – writes a Brep object to a file

Brep_fscanf – reads a Brep object from a file

The Brep file format is first for give vertex points inside [], then to give triangles that index to these points, again inside [], and then colour data for each triangle, inside []. Note each colour has five entries. The first three are diffuse colour coefficients used in local lighting computation. The last two are used in global lighting; the first specifies the fraction of globally reflected light returned in the “parent ray” direction, the second is the same but for refracted light – both greater than zero but less than 1. Call the first a2 and the second a3, then [a1 a2 a3] = [1 a2 a3]/(1+a2+a3) gives the ratio of local light, globally reflected and globally refracted light in the parent ray direction. This is not a good physical model, but is easy to code and use.

Example: plane.brep

[-0.5 -0.5 0

0.5 -0.5 0

0.5 0.5 0

-0.5 0.5 0

]

[ 1 2 4

3 4 2

]

[

1 1 1 1 0

1 1 1 1 0

]

Brep_move – transforms a Brep object by a given transform

Brep_nrm _ computes the normals at each triangle for a moved Brep object

Brep_wireframe – renders a Brep object as a wireframe in 2D,

which assumes the object has been projected

Brep_wireframe3D – renders a Brep object as a wireframe in 3D

The Cam family: deals with cameras

Cam_canonical – makes a canonical camera

Cam_move – moves the camera by the give transform

Cam_flen_set – sets the focal length

CamObj_project – projects a Brep object using the given camera

Cam_project – projects points x to give y

Cam_visualise – makes a 3D visualisation of a camera

The Trns family: deals with transforms

Trns_scale – scale

Trns_shift – shift (displacement)

Trns_xrot - turn about x axis by given radians

Trns_yrot - same

Trns_zrot – same, all use a right-handed coordinate system

The scene family: deals with whole scenes

scene_fscanf – reads a scene file

The scene file has the following format

The number of objects

A list of each objects by name, followed by some transform (use the identity transform if you do wish to leave the object where it is defined)

The camera pixels counts and window width, both in the X direction first.

The ambient lighting coefficients and the direction of the point light.

Example. Shadwscene.dat

2

plane.brep

Trns_scale( [6 4 1])*Trns_xrot( 70*pi/180 )*Trns_shift( [0 -0.5 4] );

cube.brep

Trns_shift( [0 0 -0.5] )*Trns_zrot(pi*30/180)*Trns_xrot( 70*pi/180 )*Trns_shift( [0.4 -0.5 4] );

256 256 1 1

0.3 0.3 0.3

1 0.5 -0.5

Other files

Other files exist to support, it is assumed reading these is sufficient. Please contact the author if this is not so.