Section 7.1.2
Comments

Comments are text in the scene file included to make the scene file easier to read or understand. They are ignored by the ray-tracer and are there for your information. There are two types of comments in POV-Ray.

Two slashes are used for single line comments. Anything on a line after a double slash ( // ) is ignored by the ray-tracer. For example:

// This line is ignored

You can have scene file information on the line in front of the comment as in:

object { FooBar } // this is an object

The other type of comment is used for multiple lines. It starts with " /* " and ends with " */ ". Everything in-between is ignored. For example:

/* These lines are ignored by the ray-tracer */

This can be useful if you want to temporarily remove elements from a scene file. /* ... */ comments can comment out lines containing other // comments and thus can be used to temporarily or permanently comment out parts of a scene. /* ... */ comments can be nested, the following is legal:

/* This is a comment // This too /* This also */ */

Use comments liberally and generously. Well used, they really improve the readability of scene files.


Section 7.1.3
Float Expressions

Many parts of the POV-Ray language require you to specify one or more floating point numbers. A floating point number is a number with a decimal point. Floats may be specified using literals, identifiers or functions which return float values. You may also create very complex float expressions from combinations of any of these using various familiar operators.

Where POV-Ray needs an integer value it allows you to specify a float value and it truncates it to an integer. When POV-Ray needs a logical or boolean value it interprets any non-zero float as true and zero as false. Because float comparisons are subject to rounding errors POV-Ray accepts values extremely close to zero as being false when doing boolean functions. Typically values whose absolute values are less than a preset value epsilon are considered false for logical expressions. The value of epsilon is system dependent but is generally about 1.0e-10. Two floats a and b are considered to be euqal if abs(a-b) < epsilon. %%% LATEX-ONLY \subsubsection {Float Literals} \label {Float Literals} %%% END

Float literals are represented by an optional sign ("+" or "-") digits, an optional decimal point and more digits. If the number is an integer you may omit the decimal point and trailing zero. If it is all fractional you may omit the leading zero. POV-Ray supports scientific notation for very large or very small numbers. The following are all valid float literals:

  -2.0    -4    34    3.4e6    2e-5    .3    0.6

Section 7.1.3.1
Float Identifiers

Float identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows.

#declare IDENTIFIER = EXPRESSION

Where IDENTIFIER is the name of the identifier up to 40 characters long and EXPRESSION is any valid expression which evaluates to a float value. Here are some examples.

#declare Count = 0 #declare Rows = 5.3 #declare Cols = 6.15 #declare Number = Rows*Cols #declare Count = Count+1

As the last example shows, you can re-declare a float identifier and may use previously declared values in that re-declaration. There are several built-in identifiers which POV-Ray declares for you. See "Built-in Identifiers" for details.


Section 7.1.3.2
Float Operators

Arithmetic float expressions can be created from float literals, identifiers or functions using the following operators in this order of precedence...

  ()             expressions in parentheses first
  +A   -A   !A   unary minus, unary plus and logical "not"
  A*B  A/B       multiplication and division
  A+B  A-B       addition and subtraction

Relational, logical and conditional expressions may also be created. However there is a restriction that these types of expressions must be enclosed in parentheses first. This restriction, which is not imposed by most computer languages, is necessary because POV-Ray allows mixing of float and vector expressions. Without the parentheses there is an ambiguity problem. Parentheses are not required for the unary logical not operator "!" as shown above. The operators and their precedence are shown here.

Relational expressions: The operands are arithmetic expressions and the result is always boolean with 1 for true and 0 for false. All relational operators have the same precedence.

(A < B) A is less than B
(A <= B) A is less than or equal to B
(A = B) A is equal to B (actually abs(A-B)<EPSILON)
(A != B) A is not equal to B (actually abs(A-B)>=EPSILON)
(A >= B) A is greater than or equal to B
(A > B) A is greater than B

Logical expressions: The operands are converted to boolean values of 0 for false and 1 for true. The result is always boolean. All logical operators have the same precedence. Note that these are not bitwise operations, they are logical.

(A & B) true only if both A and B are true, false otherwise
(A | B) true if either A or B or both are true

Conditional expressions: The operand C is boolean while operands A and B are any expressions. The result is of the same type as A and B.

(C ? A : B) if C then A else B

Assuming the various identifiers have been declared, the following are examples of valid expressions...

  1+2+3       2*5         1/3         Row*3       Col*5
  (Offset-5)/2            This/That+Other*Thing
  ((This<That) & (Other>=Thing)?Foo:Bar) 

Expressions are evaluated left to right with innermost parentheses evaluated first, then unary +, - or !, then multiply or divide, then add or subtract, then relational, then logical, then conditional.


Section 7.1.4
Vector Expressions

POV-Ray often requires you to specify a vector . A vector is a set of related float values. Vectors may be specified using literals, identifiers or functions which return vector values. You may also create very complex vector expressions from combinations of any of these using various familiar operators.

POV-Ray vectors may have from two to five components but the vast majority of vectors have three components. Unless specified otherwise, you should assume that the word vector means a three component vector. POV-Ray operates in a 3D x, y, z coordinate system and you will use three component vectors to specify x, y and z values. In some places POV-Ray needs only two coordinates. These are often specified by a 2D vector called an UV vector . Fractal objects use 4D vectors. Color expressions use 5D vectors but allow you to specify 3, 4 or 5 components and use default values for the unspecified components. Unless otherwise noted, all 2, 4 or 5 component vectors work just like 3D vectors but they have a different number of components.


Section 7.1.4.1
Vector Literals

Vectors consist of two to five float expressions that are bracketed by angle brackets \langle and > . The terms are separated by commas. For example here is a typical three component vector:

< 1.0, 3.2, -5.4578 >

The commas between components are necessary to keep the program from thinking that the 2nd term is the single float expression 3.2-5.4578 and that there is no 3rd term. If you see an error message such as Float expected but '>' found instead you probably have missed a comma.

Sometimes POV-Ray requires you to specify floats and vectors side-by-side. The rules for vector expressions allow for mixing of vectors with vectors or vectors with floats so commas are required separators whenever an ambiguity might arise. For example \langle 1,2,3>-4 evaluates as a mixed float and vector expression where 4 is subtracted from each component resulting in \langle -3,-2,-1>. However the comma in <1,2,3>,-4 means this is a vector followed by a float.

Each component may be a full float expression. For example \langle This+3,That/3,5*Other_Thing> is a valid vector.


Section 7.1.4.2
Vector Identifiers

Vector identifiers may be declared to make scene files more readable and to parameterize scenes so that changing a single declaration changes many values. An identifier is declared as follows...

#declare IDENTIFIER = EXPRESSION

Where IDENTIFIER is the name of the identifier up to 40 characters long and EXPRESSION is any valid expression which evaluates to a vector value. Here are some examples...

#declare Here = <1,2,3> #declare There = <3,4,5> #declare Jump = <Foo*2,Bar-1,Bob/3> #declare Route = There-Here #declare Jump = Jump+<1,2,3>

Note that you invoke a vector identifier by using its name without any angle brackets. As the last example shows, you can re-declare a vector identifier and may use previously declared values in that re-declaration. There are several built-in identifiers which POV-Ray declares for you. See "Built-in Identifiers" for details.


Next Section
Table Of Contents