Return to index

NAME

c_hvertex, c_getvert, c_cvname, c_cvertex - vertex entity support

SYNOPSIS

#include "parser.h"

int c_hvertex( int argc, char **argv )

C_VERTEX *c_getvert( char *name )

extern char *c_vname

extern C_VERTEX *c_cvertex

DESCRIPTION

The c_hvertex function handles the MGF vertex entities, v, p and n. If either p or n is supported, then v must be also. The assignments are normally made to the mg_ehand array prior to parser initialization, like so:

mg_ehand[MG_E_VERTEX] = c_hvertex;		/* support "v" entity */
mg_ehand[MG_E_POINT] = c_hvertex;		/* support "p" entity */
mg_ehand[MG_E_NORMAL] = c_hvertex;		/* support "n" entity */
/* other entity handler assignments... */
mg_init();			/* initialize parser */
If vertex normals are not understood by any of the program-supported entities, then the MG_E_NORMAL entry may be left with its original NULL assignment.

The c_getvert call takes the name of a defined vertex and returns a pointer to its C_VERTEX structure, defined in "parser.h" as:

typedef FLOAT  FVECT[3];	/* a 3-d real vector */

typedef struct {
	int	clock;		/* incremented each change -- resettable */
	FVECT	p, n;		/* point and normal */
} C_VERTEX;		/* vertex context */
The clock member will be incremented each time the value gets changed by a p or n entity, and may be reset by the controlling program if desired. This is a convenient way to keep track of whether or not a vertex has changed since its last use. To link identical vertices, one must also check that the current transform has not changed, which is uniquely identified by the global xf_context -> xid variable, but only if one is using the parser libraries transform handler. (See the xf_handler page.)

It is possible but not recommended to alter the contents of the vertex structure returned by c_getvert. Normally it is read during the interpretation of entities using named vertices.

The name of the current vertex is given by the global c_cvname variable, which is set to NULL if the unnamed vertex is current. The current vertex value is pointed to by the global variable c_cvertex, which should never be NULL.

DIAGNOSTICS

The c_hvertex function returns MG_OK (0) if the vertex 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.)

The c_getvert function returns NULL if the specified vertex name is undefined, at which point the calling function should return an MG_EUNDEF error.

SEE ALSO

c_hcolor, c_hmaterial, mg_init, mg_load, xf_handler