The global constants and variables described in this chapter are found in pspglb.web. Others, of types defined in 3DLDF, are described in subsequent chapters.
Set to 0 or 1 to match the values of the preprocessor macros
LDF_REAL_FLOATandLDF_REAL_DOUBLE. The latter are used for conditional compilation and determine whetherrealis “typedeffed” tofloatordouble, i.e., whetherrealis made to be a synonym offloatordoubleusingtypedef.
ldf_real_floatandldf_real_doublecan be used to control conditional expressions in non-conditionally compiled code.
The value of
PIis calculated as 4.0 * arctan(1.0). I believe that a preprocessor macro “PI” was available when I compiled 3DLDF using the DEC C++ compiler, and that it wasn't, when I used GNU CC under Linux, but I'm no longer sure.
Contains four elements, all 0. Used for resetting the sets of coordinates belonging to
Points, but only when the DEC C++compiler is used. This doesn't work when GCC is used.
Actually,
INVALID_REALis the largest possiblerealvalue (i.e.,floatordouble) on a given machine. So, from the point of view of the compiler, it's not invalid at all. However, 3DLDF uses it to indicate failure of some kind. For example, the return value of a function returningrealcan be compared withINVALID_REALto check whether the function succeeded or failed.An alternative approach would be to use the exception handling facilities of C++ . I do use these, but only in a couple of places, so far.
The largest
realvalue permitted in the the elements ofTransformsand the coordinates ofPoints. It is the second largestrealvalue (i.e.,floatordouble) on a given machine (INVALID_REALis the largest).
MAX_REALis a variable, but it should be used like a constant. In other words, users should never reset its value. It can't be declaredconstbecause its value must be calculated using function calls, which can't be done before the entry point of the program, i.e.,main(). Therefore, the value ofMAX_REALis calculated at the beginning ofmain().
The square root of
MAX_REAL.
MAX_REAL_SQRTis a variable, but it should be used like a constant. In other words, users should never reset its value. It can't be declaredconstbecause its value is calculated using thesqrt()function, which can't be done before the entry point of the program, i.e.,main(). Therefore, the value ofMAX_REAL_SQRTis set afterMAX_REALis calculated, at the beginning ofmain().
MAX_REAL_SQRTis used inPoint::magnitude()(see Vector Operations). The magnitude of aPointis found by using the formula \sqrtx^2 + y^2 + z^2. x, y, and z are all tested againstMAX_REAL_SQRTto ensure that x^2, y^2, and z^2 will all be less than or equal toMAX_REALbefore trying to calculate them.Metafont implements an operation called Pythagorean addition, notated as “
++”which can be used to calculate distances without first squaring and then taking square roots: 1 a++b == \sqrt(a^2 + b^2) and a++b++c == \sqrt(a^2 + b^2 + c^2). This makes it possible to calculate distances for greater values of a, b, and c, that would otherwise cause floating point errors. Metafont also implements the inverse operation Pythagorean subtraction, notated as “+-+”: a+-+b == \sqrt(a^2 - b^2). Unfortunately, 3DLDF implements neither Pythagorean addition nor subtraction as yet, but it's on my list of “things to do”.