Projector syntax

Document conventions

Each word written in lowercase in command syntax is a literal (keyword) that as to be reproduced verbatim. Uppercase words are argument names, these need to be substituted with the corresponding argument value when building the command.

Optional arguments are specified in brackets, e.g. [NX NY NZ]. Some commands require literal brackets, this is indicated by having space on both sides of the bracket, e.g. gtri VERT1 [ COLOR1 ] VERT2 [ COLOR2 ] VERT3 [ COLOR3 ].

When there are two or more discrete options, they are listed with | separating them, e.g. keepalive on|off.

Common constructs

Coordinates

Coordinates are unitless rational numbers along 3 axes (x, y and z). Coordinates are written in decimal format accepted by atof(3).

Vertex reference

Vertices are specified in the vertex array of the object. A vertex reference is an integer that addresses an element of the object vert array. The first vertex is at index 0.

The Syntax is colon integer, e.g. :5 is the 6th vertex in the array.

Colorspec

Specifies a color in one of the following formats:

Matrix expression

A matrix has 16 values, shown here in row-major order:


  IX IY IZ _
  JX JY JZ _
  KX KY KZ _
  SX SY SZ _
	
These matrices specify object transformations and coordinate systems using three basis vectors I J K and a shift vector S. An input vector VX xy Vz is mapped as Vx * I + Vy * J + Vz * K + S. The values shown with an underscore are not used for the transformation, but can still make a difference with matrix multiplication.

Matrices can be specified as matrix expressions, which consist of one or more matrices multiplied (which works as if transformations were applied one after another - note that this is not a commutative operation!). Two matrices can be multiplied using the * operator.

A matrix can be specified using one of the following formats:

Typical examples:
obj "foo" mat rotx 45 * roty 90 * shift 10 7 11 - change the rotation and move the previously created object foo
cube scale 4 * shift 1 0 0 - create an 1x1x1 cube, scale it up to 4x4x4 and move it 1 unit on the X axis

Order of operations obviosuly does matter: a matrix expression starts with the identity matrix as the working matrix and executes each multiplication in order. At the end the final working matrix is used as the value of the expression.

Common template modifiers

When adding templates to objects, new templates are normally created with surface triangles facing outwards (normal vector pointing outwards). Triangles are one-sided, which means that if viewed from the inside, these objects would be invisible. This can be modified by specifying one of the following optional modifiers:

Note: anything else than "double" is a rendering optimization and makes any difference only if object culling is not turned off.

Strings

When a textual name or string has to be specified, one of two formats can be used:

Light reflection

Brigthness of surface fragments are calculated a formula similar t the oversimplified one:

output_brighthess = clamp(diffuse * light_angle + object_ambient)

Global commands

obj NAME

Begin describing an object with the specified NAME. Object commands are documented in the object commands section. Object description lasts until the next global command. Entering an object definition doesn't "empty" the object - existing primitives aren't deleted (so new primitives will be appended). To redefine an object, use the empty or realempty command.

cam EYEX EYEY EYEZ CENTERX CENTERY CETNERZ [UPX UPY UPZ]

Move camera to specified eye position, looking at specified center point. The up vector is a vector pointing upwards from the camera (specifying camera orientation). The up vector can be omitted; in this case, projector tries to calculate a reasonable up vector, so that the plane defined by the (eye-center) vector and the up vector contains the Z axis, and the up vector points towards positive Z.

light X Y Z

Place light source at coordinates X;Y;Z.

light diffuse NUM

Sets diffuse intensity of the light. Acts as a multiplier to the material diffuse reflection factor. Default 1.

fov NUM

Set field of view (in degrees). Default 90.

visibility NUM

Object with distance greater than NUM from the camera are not rendered. Useful on large landscape scenes to omit wasting CPU cycles on objects so far that they would be behind something else or would be a sub-pixel anyway. Default value is 1024.

render

Render frame.

renderdelay DLY

Render frame then stop reading the input for DLY seconds timed from the last renderdelay (thus time spent on rendering is not added and a stable frame rate can be achieved). DLY is a positive rational number. Reports RENDERDELAY on STDOUT if events are enabled.

sleep DLY

Stop reading the input for DLY seconds. DLY is a positive rational number. Unlike renderdelay, sleep does not try to time precisely and does not have any side effect.

bg CLR

Set background color to CLR (see colorspec).

default ambient NUM

Sets default ambient lighting factor. Default 1.

default diffuse NUM

Sets default diffuse lighting factor. Default 0.

keepalive on|off

When on, do not exit upon EOF on STDIN.

events on|off

When on, print events to STDOUT.

mousegrab on|off

When on, hides the mouse cursor and grabs mouse input (mouse can not leave window).

fog on|off

When on, renders fog so distant objects gradually phase out instead of suddenly disappearing (see also: visibility). Supported only in opengl rendering (-g), software rendering ignores this.

gsense 1 2 3 4 5 6 7 8 9

Sets sensitive plane using 3 points. Sensitive plane is used to report a second set of coordinates (after screen coords) mapped onto this plane for mouse events. It is useful to get mouse coords in an absolute coordinate system within the 3d scene regardless of camera location and orientation. The coordinates are applied in the global coordinate system (not under any particular object).

sense POINT1 POINT2 POINT3

Similar to gsense, but specifies the plane in the current coordinate system of the current object (relative to object position and transformations).

load texture NAME PATH

Load a texture from file at PATH and store it in memory as NAME. Name is an unique identifier of the texture. Both PATH and NAME are strings. File format of the texture is anything libsdl-image can load; typically png or jpeg. A texture file must contain exactly 256*256 pixels.

default texture NAME|off

Specify the name of the texture used for all objects that are otherwise not textured locally. This option takes effect in rendering, not in object creation! If off is used instead of a texture name, non-textured objects remain non-textured in rendering.

echo STRING

Print STRING to STDOUT.

Object commands

Points for primitives can be described in two ways: X Y Z - three numbers; add new vertex to object, use that vertex :N - use existing vertex reference

show

Show object (default).

hide

Hide object.

empty

Delete all primitives but not vertices or normals.

realempty

Delete all primitives, vertices and normals.

pos X Y Z

Set object position.

mat MEXPR

Set transformation matrix of current object. MEXPR is a matrix expression.

mat3 MEXPR

Set transformation matrix of current object. The shift/translation vector of the input matrix is ignored, only the basis vectors are applied. MEXPR is a matrix expression.

color CLR

Set default color for primitives. Default black, but this isn't reset with entering new object definitions, so it has a global effect. CLR is a colorspec.

texture MODE NAME

Specifies object texture and mapping mode. MODE is one of:

texture off

Removes local texture from object. Note: default (global) texture may still appply to the object at rendering.

lines POINT1 POINT2 ...

Add a new primitive with the current color, that draws a line of multiple connected segments.

verts X1 Y1 Z1 [X2 Y2 Z2 ...]

Append new vertices to the object vertex array.

tri POINT1 POINT2 POINT3 [NX NY NZ]

Specify a triangle using 3 POINTs. Optional NX NY NZ specify surface normal vector; when not specified, it is calculated automatically. (Manually specified normal vectors can be used for bump maps.)

quad POINT1 POINT2 POINT3 POINT4 [NX NY NZ]

Same as tri but creates a quad.

gtri POINT1 [ COLOR1 ] POINT2 [ COLOR2 ] POINT3 [ COLOR3 ]

Triangle colored in gradient with a target color specified for each vertex. COLOR1, COLOR2, COLOR3 are colorspec, POINT1, POINT2, POINT3 are the same as in tri.

gquad POINT1 [ COLOR1 ] POINT2 [ COLOR2 ] POINT3 [ COLOR3 ] POINT4 [ COLOR4 ]

Same as gtri, but creates a gquad.

ttri POINT1 POINT2 POINT3 U1 V1 U2 V2 U3 V3

Textured triangle. POINT1, POINT2, POINT3 are the same as in tri. The U and V numbers specify the texture coordinates for the three vertices (mapping a range of 0 to 1 on the texture image).

tquad POINT1 POINT2 POINT3 POINT4 U1 V1 U2 V2 U3 V3 U4 V4

Same as ttri but creates a tquad.

specular NUM

Sets specular value on opengl material. Supported only in opengl rendering (-g), software rendering ignores this.

shiny NUM

Sets shiny value on opengl material. Supported only in opengl rendering (-g), software rendering ignores this.

diffuse NUM

Set diffuse reflection factor of the object material (from 0 to 1).

ambient NUM

Set ambient lighting value of the object material (from 0 to 1).

copy NAME

Render other object by name (usually useful when other object is hidden). Transformation matrix is local * other (the matrices of the local and the referenced objects are multiplied).

lcopy NAME

Render other object by name. Transformation matrix is local only (the transformation matrix of the referenced object is ignored).

call NAME

Render other object name. Transformation matrix is other only (the transformation matrix of the referenced object is used; the local matrix is ignored).

inc MEXPR NAME

Render other object by name. Transformation matrix is MEXPR * other * local. Can be used to copy the same object in different positions. MEXPR is a matrix expression.

attr NAME

Use material attributes of other object (color, texture, diffuse, ambient). Basically like "copy" & friends, but only for material attributes.

lod CAMDIST NAME

If camera distance exceeds CAMDIST, does a call NAME then stops processing this object. Can be used to have multiple versions of an object with different levels of detail.

lodcopy CAMDIST NAME

If camera distance exceeds CAMDIST, does a copy NAME then stops processing this object. Can be used to have multiple versions of an object with different levels of detail.

static

Makes the current object static. The object is no longer allowed to be modified (can't add primitives or set transformation matrix). In return, the object can participate in frustum culling. Note that static objects can't reference (copy, call, etc.) non-static objects.

normals

Generates vertex normals for all vertices in this object (as sums of the normals of the triangles that reference each vertex). Afterwards the triangles will be rendered using gouraud shading (with normal vector interpolation) instead of flat shading (using the same normal vector for the entire triangle).

Note: this command is not used for calculating simple surface normals of primitives like triangles or quads - that is done automatically if normals are not specified in the drawing command.

hotpoint POINT NAME

Create a named hot point in 3d space. NAME is an arbitrary string of at most 8 characters that identifies the hot point. When hot points are declared in a scene, mouse events report the name of the closest hot point as last argument of the event.

nocull

Turn off back-face culling of the current object. Normally objects are culled, which means each surface triangle is drawn only when its normal vector is facing the camera. When the normal vector is facing away, the triangle is not drawn. This is an optimization, which usually saves drawing half the triangles of somewhat symmetric objects.

See also: Common template modifiers when using template primitives.

Culling is turned on by default and is controlled on a per object basis.

mapuv [MEXPR]

Enable UV-mapping for this object. Instead of manually specifying U, V texture coordinates using TTRI, TQUAD commands, the specified matrix is used to transform object coordinates into UV (the resulting x and y are used for UV, z is ignored). Afterwards, normal trianges and quads become textured triangles and quads. Can be used to make object templates (like cube, cone, etc.) with textures. MEXPR is a matrix expression.

cube [invert|double] [MEXPR]

Add a transformed cube to current object. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

cone [invert|double] [VERTNUM] [MEXPR]

Add a transformed cone to current object. VERTNUM specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

hat [invert|double] [VERTNUM] [MEXPR]

Add a transformed hat to current object. A hat is a cone without bottom disc. VERTNUM specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

cylinder [invert|double] [/TOPDIA] [VERTNUM] [MEXPR]

Add a transformed cylinder to current object. TOPDIA is the diameter of the top circle (1 if not specified). Bottom circle diameter is always 1. VERTNUM specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

tube [invert|double] [/TOPDIA] [VERTNUM] [MEXPR]

Add a transformed tube to current object. A tube is a cylinder without top and bottom discs. TOPDIA is the diameter of the top circle (1 if not specified). Bottom circle diameter is always 1. VERTNUM specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

disc [invert|double] [VERTNUM] [MEXPR]

Add a transformed disc to current object. VERTNUM specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

wedge [invert|double] [VERTNUM] [MEXPR]

Add a transformed wedge to current object. VERTNUM1 specifies the number of vertices along the base circle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

sphere [invert|double] [VERTNUM1 VERTNUM2] [MEXPR]

Add a transformed sphere to current object. VERTNUM1 and VERTNUM2 specify the number of vertices along the meridian and equator. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

hemisphere [invert|double] [VERTNUM1 VERTNUM2] [MEXPR]

Add a transformed hemisphere (a sphere cut in half with a horizontal plane along its equator) to current object. VERTNUM1 and VERTNUM2 specify the number of vertices along the meridian and equator. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

dome [invert|double] [VERTNUM1 VERTNUM2] [MEXPR]

Add a transformed dome (a sphere cut in half with a horizontal plane along its equator) to current object. A dome is a hemisphere without bottom discs. VERTNUM1 and VERTNUM2 specify the number of vertices along the meridian and equator. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

torus [invert|double] [VERTNUM1 VERTNUM2 THICK] [MEXPR]

Add a transformed torus to current object. VERTNUM1 and VERTNUM2 specify the number of vertices along the meridian and equator of the bounding sphere. THICK is the dimater of the "tube" of the torus, between 0 and 1, relative to the overall diameter of the torus; a value close to 0 mean thin, a value close to 1 means the inner circle of the tube touch and there's no hole left in the middle. The transformation is done using the matrix expressionMEXPR. Invert and double are the common template modifiers.

Event syntax

Events are reported to STDOUT when enabled. Each report is a single line of text starting with the event name, written all uppercase. Event arguments are:

List of events printed by projector:

event name arguments printed when
PRESS BTN X Y SX SY SZ HOT mouse button pressed
RELEASE BTN X Y SX SY SZ HOT mouse button released
MOTION BTN X Y SX SY SZ HOT mouse cursor moved (when not grabbed)
RMOTION BTN RX RY mouse cursor moved (when grabbed)
RESIZE WIDTH HEIGHT window resized to WIDTH * HEIGHT pixels
KEYDOWN KMOD KUNI KNAME keyboard key is pressed
KEYUP KMOD KNAME keyboard key is released
RENDERDELAY DT RNDT renderdelay has finished rendering and sleeping, input is read again