APPENDIX-Alias defined API Functions

This section lists the functions (in ANSI C Prototype form) that Alias supplies for use in your ALIAS OpenRender C code modules. Each prototype listing is followed by a brief description of the arguments and what the function does. All of these prototypes are provided to you in the file OCR_api.h.

It should be pointed out that standard C library functions can be used in addition to any of the functions listed below.

float OCR_random ()
This function returns a pseudo-random number between 0.0 and 1.0.

int OCR_reflect_ray (
AR_Vector *ray,
AR_Vector *normal,
AR_Vector *newray
)
This function takes three arguments, the incident ray, the surface normal (both normalized), and space for the resultant reflected ray (newray). It returns a normalized ray that points in the reflection direction.

void OCR_INVOKE_MAPPING (
AR_TextureData *pData,
AR_TextureInfo *pInfo,
AR_Point *ray
)
This function calls the texture referenced by the AR_TextureInfo pointer and returns the result in pData->TDcolor, which must be initialized to point to an AR_Rgba before the call. The argument ray is a pointer to the incident ray. This macro returns the constant out value of the texture if no texture is present, or if the texture does not apply to the current point. pData->TD[uv] is modified by this routine to equal pData->TDgeom>[uv]center automatically.

int OCR_initialize_texture (
AR_TextureInfo *texture
)
This call initializes the texture referenced by the AR_TextureInfo pointer. This must be called for each texturable field in your INFO structure. It should be called in the INIT() routine only.

int OCR_init_texture_transforms (
AR_TextureInfo *texture,
float *inverse_determanent
)
This function should be called at the top of the solid and environment texture's CALC routine if you want to use save_transformation in the SDL to alter the orientation of your solid texture. See the solid and environment texture prototypes for an example of usage.

void
OCR_set_texture_type (
int status,
int type,
int absolute
)
This function is called from the ALIAS OpenRender Template File's Eval_Local routine and is used to tell the Alias Renderer what type of texture you have written. You should not have to call this function. If you are writing a texture, you only need to modify the three #defines that exist at the top of the example C files: TEXTURE_STATUS, TEXTURE_TYPE, and TEXTURE_ABSOLUTE. See the Texture section for further discussion of this function.

AR_Boolean
OCR_bind_forward_reference (
AR_Triple *original,
AR_Triple *thing_being_bound
)
This function is used in the COPY routine to allow a forward reference to be bound across copies of an object. This function should be used only for positional information where the value of the field is derived from a variable that is set to the value of a current_position() statement elsewhere in SDL. See the Initialize section of this document for more information on how to apply this function.

int
OCR_transform_point (
AR_Point* in_pt,
AR_Point* out_pt
)
This function applies the current transformation to in_pt and places the result in out_pt. This function is mostly useful for transforming a light's position into world space, and should only be called in the INIT routine (random results otherwise). The two arguments, in_pt and out_pt can point to the same AR_Point.

int
OCR_transform_normal (
AR_Point* in_norm,
AR_Point* out_norm
)
This function applies the current transformation to in_norm and places the result in out_norm. This function is mostly useful for transforming a light's direction based on the transformation matrix, and should only be called in the INIT routine (random results otherwise). The two arguments, in_norm and out_norm can point to the same AR_Point.

Caution: out_norm is not normalized, and in_norm is not required to be normalized.

int
OCR_transform_tangent (
AR_Point* in_tan,
AR_Point* out_tan
)
This function applies the current transformation to in_norm and places the result in out_norm. This function should only be called in the INIT routine (random results otherwise). Tangents should not be normalized. The two arguments, in_tan and out_tan can point to the same AR_Point.

int
OCR_texture_transform_point (
AR_Point* pt,
AR_Matrix matrix
)
This function applies the supplied matrix to the specified point (pt). It is used mostly in solid and environment textures to transform the current intersection point from world space back into object space (the space where the object was defined). Applying this matrix to the point applies any save_transformation matrices that were specified in the SDL.

int
OCR_texture_transform_vector (
AR_Vector* vector,
AR_Matrix matrix
)
This function applies the supplied matrix to the specified vector. In all other ways it is similar to OCR_texture_transform_point().

void OCR_NORMALIZE(
double length,
AR_Vector vector
)
This C macro normalizes the specified vector, and places the length of the vector (before normalization) in length.

int
OCR_matrix_initialize (
AR_Matrix matrix
)
This function sets the specified matrix to the identity matrix.

int
OCR_matrix_multiply (
float* matrix1,
float* matrix2,
float* result_matrix
)
This routine multiplies matrix1 by matrix2 and returns the resulting matrix in result_matrix. The routine allows result_matrix to be one of matrix1 or matrix2. This function can be called by casting your matrices to (float *).

int
OCR_matrix_invert (
AR_Matrix matrix_in,
AR_Matrix matrix_out
)
This routine inverts the matrix specified by matrix_in into matrix_out. The two matrices cannot be the same matrix. If the matrix is not invertable, OCR_fatal_error() is called and the renderer exits.

float OCR_noise3D (
double x,
double y,
double z
)
Given a location in three dimensions (x, y, z), this function returns a 3D, continuous pseudo-random scalar value. See Ken Perlin's paper on Solid Textures for more information.

float OCR_noise2D (
double x,
double y
)
Given a location in two dimensions (x, y), this function returns a 2D, continuous pseudo-random scalar value. See Ken Perlin's paper on Solid Textures for more information.

AR_Rgb OCR_color_noise2D (
double x,
double y
)
This function generates a continuous, non-repeating, 3D noise in two-dimensional space.

float OCR_check_shadow (
AR_LightInfo *light,
double length,
AR_Vector *direction,
AR_Point *pt,
AR_Rgba *shadow_color
)
Useful in the Alias Raytracer only.

Given a pointer to the light to check for shadows on, this routine traces a ray from the intersection point (pt) following the normalized direction vector that points towards the light (direction). The shadow ray tracing stops after length units, which should be passed in as the distance to the light source. The float value returned is for backwards compatibility. The shadow_colour point contains the r,g,b values to multiply into the final result to produce colored shadows in the raytracer. This function can only be called from a Light CALC function in the raytracer.

int OCR_copy_TextureType (
AR_TextureType *pTo,
AR_TextureType *pFrom
)
This function copies the texture pFrom into pTo. pTo must not be NULL, but all fields inside pTo are assumed to be NULL. If the structures cannot be copied for some reason, an error message is printed and the renderer aborts.

char *OCR_allocate (
unsigned int size
)
This routine allocates size bytes of memory. Upon failure, it prints an "Out of memory" message and aborts the renderer.

int
OCR_fatal_error (
char* error_string,
char* argument
)
This routine prints out an error message and then aborts the renderer. The error_string may contain a printf()-like directive that prints out the argument in the string.

For example:

OCR_fatal_error( "This integer is wrong: %d ", i );

If there is no printf()-like directive in the error_string, then the second argument should be NULL.

For example:

OCR_fatal_error( "Problem initializing code.", NULL );

int OCR_message (
char* message_string,
char* argument
)
This routine is similar to OCR_fatal_error() except the renderer is not aborted.

void OCR_want_tangents()
This routine is for use in the Evaluate section of your shaders. It allows you to tell the Alias renderer to create tangent information for objects that use that shader. By default, if the object is not bump or displacement mapped, tangents are not created for the object.






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