Return to index


xf_handler, xf_clear, xf_context, xf_argend - transformation support


int xf_handler( int argc, char **argv )

void xf_clear( void )

extern XF_SPEC *xf_context

extern char **xf_argend


The xf_handler routine should be assigned to the MG_E_XF entry of the parser's mg_ehand array prior to calling mg_load if the loader/translator wishes to support hierarchical transformations. (Note that all MGF geometric entities require this support.)

The xf_clear function may be used to clear the transform stack and free any associated memory, but this is usually not necessary since xf begin and end entities are normally balanced in the input.

The global xf_context variable points to the current transformation context, which is of the type XF_SPEC, described in "parser.h":

typedef struct xf_spec {
	long	xid;			/* unique transform id */
	short	xac;			/* context argument count */
	short	rev;			/* boolean true if vertices reversed */
	XF	xf;			/* cumulative transformation */
	struct xf_array	*xarr;		/* transformation array pointer */
	struct xf_spec	*prev;		/* previous transformation context */
} XF_SPEC;		/* followed by argument buffer */
The xid member is a identifier associated with this transformation, which should be the same for identical transformations, as an aid to vertex sharing. (See also the c_hvertex page.) The xac member indicates the total number of transform arguments, and is used to indicate the position of the first argument relative to the last one pointed to by the global xf_argend variable.

The first transform argument starts at xf_argv, which is a macro defined in "parser.h" as:

#define xf_argv		(xf_argend - xf_context -> xac)
Note that accessing this macro will result in a segmentation violation if the current context is NULL, so one should first test the second macro xf_argc against zero. This macro is defined as:

#define xf_argc		(xf_context==NULL ? 0 : xf_context -> xac)

Normally, neither of these macros will be used, since there are routines for transforming points, vectors and scalars directly based on the current transformation context. (See the xf_xfmpoint page for details.)

The rev member of the XF_SPEC structure indicates whether or not this transform reverses the order of polygon vertices. This member will be 1 if the transformation mirrors about an odd number of coordinate axes, thus inverting faces. The usual thing to do in this circumstance is to interpret the vertex arguments in the reverse order, so as to bring the face back to its original orientation in the new position.

The xf member contains the transformation scalefactor (in and 4x4 homogeneous matrix (in xf.xfm), but these will usually not be accessed directly. Likewise, the xarr and prev members point to data that should not be needed by the calling program.


The xf_handler function returns MG_OK (0) if the color is handled correctly, or one of the predefined error values if there is a problem. (See the mg_load page for a list of errors.)


c_hvertex, mg_init, mg_load, obj_handler, xf_xfmpoint