Bookshelf Contents Previous Next Glossary Index Search

MODEL Section

The MODEL section describes the instances of the objects that were defined in the DEFINITION section, along with information for position, orientation, relationships between objects, and behavior over time. The MODEL section contains statements about data items (for creating, inspecting, and transforming), and control statements (for conditional execution and looping).

The MODEL section is similar to the old GEOMETRY section, but uses objects defined in the DEFINITION section.

The MODEL section begins with the word MODEL in all caps on a seperate line with no punctuation. The section ends when the SDL file ends.

The following statements are described in this section:

assignment

Syntax:

<left hand side> = <right hand side> ;

Purpose:

This assigns the value of the item on the right to the item on the left. The item on the right is not modified or otherwise effected in any way. The <left hand side> may be a variable name, an array name, or an array element reference. The <right hand side> may be a literal, a variable reference, an array name, or an array ele-ment reference or a function. However, only certain of the possible combinations are valid. The following rules de-termine the validity.

If the <left hand side> is an array element reference, then any of the <right hand side> possibilities may be used.

If the <left hand side> is a variable name, the <right hand side> may be a literal, a variable reference, or an array element reference or a function, provided that the data types of the <left hand side> and the <right hand side> are the same.

Example:

switch = FALSE;
 bunch[1] = some_var;

for

Syntax:

for ( <initial statement>; <condition> ; <iteration statement>; ) <body statement>

Purpose:

The for statement provides a means of iterating loops of statements. The struc-ture of the for statement is considerably more powerful than that provided by most lan-guages. The particulars of it are different than "C", but have a similar flavor.

The <initial statement> is any statement valid in the MODEL section. Typically it will be an assignment, but it is not limited to that. (It could be a (null) grouping or even a nested for statement.) An <initial statement> must be specified.

The <condition> is just an expression interpreted as a truth value. An expression is considered true if its value is non-zero, and false if its value is zero. If <condition> is true, then the <body statement> will be executed. If <condition> is false, then control immediately passes to the statement following the for state-ment. A <condition> must be specified.

The <iteration statement> is any statement valid in the MODEL section. An <iteration statement> must be specified. The <body statement> is any statement valid in the MODEL section. A <body statement> must be specified.

All the elements of a for statement are always required. The parentheses and semi-colon are part of the syntax, and required. The end of a for statement is marked by the end of the <body statement>.

There are four parts to the execution of a for statement. First, the <initial state-ment> is executed. Second, the <condition> is tested. The result of this is either continued execution or the end of the for statement. Third, if execution is to be continued, the <body statement> is executed. Fourth, the <iteration statement> is executed. Following this, control reverts to the second step, testing the <condition>, and pro-ceeds from that point. Execution continues in this way until the <condition> evalu-ates to false.

Example:

for ( x=0; x < 10; x = x+1;) print("digit =", x );

{ }

Syntax:

{ <statement> <statement> <statement> }

Purpose:

An arbitrary number of MODEL section statements may be grouped together through the use of the brace bracket characters, { and }. The start of the group is marked by the opening brace, {. The end of the group is marked by the closing brace, }. All statements between the braces are treated as though they were one single statement. Transformation statements (rotate, translate and scale) only have effect within the group. Instances and literals create objects in the scene. Assignments effect the value of variables, which retain their values across the boundaries of the group. All other statements behave in their normal manner. Groups may be nested to any degree.

Groups are useful for two purposes. First, groups allow hierarchies of objects and transformations to be constructed. When used in this sense, they are identical to the groups found in the interactive package. Second, groups are useful for ex-tending the range of effect of if statements and for statements. This usage of groups is not presently available in the interactive package. It is, however, vary similar to syntactic constructs in "C" and other programming languages.

if

Syntax:

if ( <condition> ) <true statement> else <false statement>

or

if ( <condition> ) <true statement>

Purpose:

The if statement is used to conditionally execute statements. The <condition> is just an expression interpreted as a truth value. An expression is considered true if its value is non-zero, and false if its value is zero. If <condition> is true, the <true state-ment> is executed. Otherwise, the <false statement> is executed. The if statement can be abbreviated by omitting the else and the <false statement>.

In its abbreviated form, the if statement will execute the <true statement> if the <condition> is true, and pass on to the next statement if it is false. <true state-ment> and <false statement> may be any statement valid in the MODEL section (including if statements and {} groupings). The end of an if statement is marked by the end of the <false statement> (or by the end of the <true statement> in the abbreviated form).

Example:

if (frame > 1)  begun = TRUE;

instance

Syntax:

instance <object reference> ();

or

inst <object reference> ();

Purpose:

The instance statement creates an instance of an object. The <object reference> may be either a variable reference or an array element reference. In either case, an object is created from the data item. The data item being referenced must be of an appropriate type (that is, Light Data Type, Patch Data Type, Face Data Type, or Camera Data Type). If the <object reference> is a variable ref-erence, then the type check is performed at parse time, otherwise it is performed at instancing time. If an improper data type is given, a warning message is issued and execution continues with the instance ignored. The effect of an instance is the same as if a literal of the same type and having the compo-nent values of the <object refer-ence> were used instead.

The end of an instance statement is marked by a semi-colon.

Note that inst and instance keywords can be used interchangeably.

Example:

instance sphere_patch();

literal

Syntax:

The syntax of a literal definition varies, depending upon the data type of the lit-eral being defined. The reader is referred to the detailed description of the data types for the exact syntax of each. Note that only literals of "objects" may be used. That is, only Light Data Type, Patch Data Type, Face Data Type, and Camera Data Type are valid. If an improper data type is given, a warning is issued and execution continues with the literal ignored.

Purpose:

The specification of a literal object places that object in the scene at the location and with the size and orientation determined by the current transform matrix. The end of a literal statement is marked by a semi-colon.

(null)

Syntax:

;

Purpose:

The null statement (a lone semi-colon) is a valid and well-defined statement that does nothing. It is useful in those situations where a statement is required, but no action is desired. For example, a for statement with an empty initial statement could be writ-ten as

for ( ; x < 5; x = x+1; ) print("count =", x );

print

Syntax:

print ( "string", <scalar | triple> ) ;

or

print ( "string" ) ;

Purpose:

This statement prints a string and the value of a scalar, or just a string. The string is required, although it may be empty.

print may be used by itself, for example

print ("This just prints a comment");

Alternately, print may be used as a function within some larger construct. When used in this way, print passes the value of the variable through as though the print were not there at all. For example,

x = print ("x = ", a );

results in x being assigned the value of variable a. If only a string is given (no vari-able), the passed through value is scalar(0). Thus,

x = print ("This is just a comment");

is equivalent to assigning the scalar value 0 to variable x. The end of a print statement is marked by a semicolon.

If the item being printed is a triple, the return value of the print statement is also a triple.

Example:

print("a thing", thing);

rotate

Syntax:

rotate ( <axis index>, <scalar> ) ;

or

rot ( <axis index>, <scalar> ) ;

Purpose:

Rotations are performed about an axis. The <axis index> specifies which axis to ro-tate about. The <axis index> is just a scalar, interpreted as an integer. It must have a value of 0, 1 or 2, where a value of 0 indicates rotation about the x axis, 1 indicates rotation about the y axis, and 2 indicates rotation about the z axis. Three system de-fined constants are provided (xaxis, yaxis, and zaxis) for convenience in specifying the <axis index>. The <scalar> specifies the amount of rotation (measured in de-grees). The order of application for rotate statements is impor-tant. A rotate statement for the x axis followed by one for the z axis does not have the same effect as the re-verse order of application. The end of a rotate statement is marked by a semi-colon.

Note that rot and rotate keywords can be used interchangeably.

Example:

rotate(zaxis, 45);

translate

Syntax:

translate <triple> ;

or

trn <triple> ;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate statement is marked by a semi-colon.

Note that trn and translate keywords can be used interchangeably.

Example:

translate (0,15,0.2);

scale

Syntax:

scale <triple> ;

Purpose:

The components of the <triple> multiply the coordinate values of points for each of the x, y and z directions with respect to the origin. A scale of (1,1,1) has no ef-fect on the objects, while a scale of (1, 1, 1.5) creates a 50 percent increase in the z dimension. Note that a scale of (0, 0, 0) is an error; it is ignored by the renderer, and a warning message is given. The end of a scale statement is marked by a semi-colon.

Example:

scale (1,1,0.2);

translate_pivot

Syntax:

translate_pivot <triple>;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate_pivot statement is marked by a semi-colon. translate_pivot is similar to translate, except translations used in translate_pivot do not get used in cluster matrix building.

Example:

translate_pivot (0.1, 3.0, 2.5);

translate_ripivot

Syntax:

translate_ripivot <triple>;

or

trn_ri <triple>;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate_ripivot statement is marked by a semi-colon. translate_ripivot is similar to translate, except translations used in translate_ripivot do not get used in cluster matrix building and only affects rotation in.

Note that trn_ri and translate_ripivot can be used interchangeably.

Example:

translate_ripivot (0.1, 3.0, 2.5);

translate_ropivot

Syntax:

translate_ropivot <triple>;

or

trn_ro <triple>;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate_ropivot statement is marked by a semi-colon. translate_ropivot is similar to translate, except translations used in translate_ropivot do not get used in cluster matrix building and only affects rotation out.

Note that trn_ri and translate_ripivot can be used interchangeably.

Example:

translate_ropivot (0.1, 3.0, 2.5);

translate_sipivot

Syntax:

translate_sipivot <triple>;

or

trn_si <triple>;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate_sipivot statement is marked by a semi-colon. translate_sipivot is similar to scale, except translations used in translate_sipivot do not get used in cluster matrix building and only affects scale in.

Note that trn_si and translate_sipivot can be used interchangeably.

Example:

translate_sipivot (0.1, 3.0, 2.5);

translate_sopivot

Syntax:

translate_sopivot <triple>;

or

trn_so <triple>;

Purpose:

The <triple> indicates the direction in which the subsequent geometry is moved. The end of a translate_sopivot statement is marked by a semi-colon. translate_sopivot is similar to scale, except translations used in translate_sopivot do not get used in cluster matrix building and only affects rotation out.

Note that trn_si and translate_sipivot can be used interchangeably.

Example:

translate_sopivot (0.1, 3.0, 2.5);



Bookshelf Contents Previous Next Glossary Index Search

[email protected]
Copyright © 1998, Alias|Wavefront, a division of Silicon Graphics Limited. All rights reserved.