SYNOPSIS

DESCRIPTION
The
SG_Object describes a geometrical object bounded by a polyhedral approximation.
The data format used by
SG_Object is based on Baumgart's
wingededge data structure.
The structure describes a set of facets (triangles or quads).
Each facet references 3 or 4 halfedges, and each halfedge references the
incident vertex (and incident facet).
Facets and halfedges also contain pointers to their opposites.
A mesh of two triangles:

INHERITANCE HIERARCHY
AG_Object(3)> SG_Node(3)> SG_Object. 
INITIALIZATION
SPECIFYING VERTICES
The SG_VertexInit() function initializes a vertex vtx that has already been allocated. The SG_VertexNew() function allocates, initializes and attaches a new vertex specified as a M_Vector(3), and returns an index to the new vertex (or to an existing vertex, if there is currently a vertex with the same coordinates, as compared up to machine precision). SG_VertexNewv() is a variant of SG_VertexNew() which accepts a pointer to a M_Vector3. M_VertexNewvn() is also a variant of SG_VertexNew(), which allows a normal vector norm to be specified. This normal vector will be used subsequently for lighting and physics calculations. The SG_VertexNew2() and SG_VertexNew3() variants of SG_VertexNew() accept coordinates as individual M_Real(3) arguments. SG_VertexNewCopy() creates a vertex using the coordinates from an existing vertex vtx. 
SPECIFYING EDGES
The SG_Edge2() function creates an edge (i.e., two halfedges) incident to the given vertices vTail and vHead. The function returns a pointer to the SG_Edge structure describing the HEAD halfedge. By convention, the HEAD halfedge points to the facet at the left of the edge. If the edge already exists, SG_Edge2() returns a pointer to (the HEAD halfedge of) the existing edge. The SG_EdgeFindByVtx() function searches for an (half)edge between vertices v1 and v2, returning a pointer to the SG_Edge structure on success, or NULL if no match was found. SG_EdgeFindByVtx() is an O(1) operation. The SG_HashEdge() function returns the index of the edgeTbl bucket corresponding to the edge between vertices v1 and v2. SG_EdgeRehash() resizes an object's hash table of (half)edges to contain nBuckets buckets in total. If insufficient memory is available, the existing table is preserved and the function returns 1. 
SPECIFYING FACETS
The SG_FacetNew() function allocates, initializes and attaches a new facet. The n must be either 3 for a triangle, or 4 for a quad facet. New facets don't have any associated edges / vertices. The SG_Facet3() and SG_Facet4() variants create triangle and quad facets, respectively. The SG_FacetFromTri3() and SG_FacetFromQuad4() functions create a triangular or quad facet from a contour of specified vertices, creating edges as necessary. Note that if the contour includes one or more existing edges, the orientation of the facet may be reversed in order to remain consistent with the existing facets sharing those edges. The SG_FacetDelete() function deletes a facet, and removes any reference to it. SG_FacetExtrude() creates, from an existing facet f, an extrusion along direction d. The function returns 0 on success or 1 if the feature could not be created. The mode argument may be one of:

GEOMETRICAL QUERIES ON FACETS
The SG_FacetNormal() function computes the normal vector for a given facet f. Mathematically, this is the vector crossproduct of three vertices of the facet (for quad facets, the 4th vertex is ignored), normalized. SG_FacetArea() computes the (unsigned) area covered by a facet SG_FacetAreaSigned() computes the signed area of a facet. SG_FacetCentroid() computes the center of mass (centroid) of a facet. 
MISCELLANEOUS OPERATIONS
The SG_ObjectCheckConnectivity() function performs (potentially very expensive) checks for inconsistencies in the edge/facet/vertex connectivity of an object. If any error is found, the function immediately returns 1 and sets the error message accordingly. If cons argument is nonNULL, errors are reported as AG_Console(3) messages, otherwise messages are printed using AG_Verbose(3). SG_ObjectNormalize() calculates the normal vector for every facet of the object, using SG_FacetNormal() on the individual facets. The SG_ObjectConvQuadsToTriangles() converts all quad facets to triangular facets, returning the total number of facets that have been converted. The SG_ObjectEdgeMatrix() function generates a vertex/edge adjacency matrix for the object. SG_ObjectFacetMatrix() generates a vertex/facet adjacency matrix. Both functions will allocate the matrix and return the size into n. The functions may fail and return NULL. 
FLAGS
The following public
SG_Object flags are defined:
The following public SG_Vertex flags are defined:

STRUCTURE DATA
For the
SG_Object object:
For the SG_EdgeEnt (halfedge bucket) structure:
For the SG_Edge (halfedge) structure:
For the SG_Vertex structure:

SEE ALSO
AG_Queue(3), M_Real(3), M_Vector(3), SG(3), SG_Intro(3), SG_Material(3), SG_Node(3) 
HISTORY
The SG_Object node class first appeared in Agar 1.6.0. 