GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
SG_OBJECT(3) FreeBSD Library Functions Manual SG_OBJECT(3)

SG_ObjectAgar-SG polyhedral object node

#include <agar/core.h>
#include <agar/sg.h>

The SG_Object describes a geometrical object bounded by a polyhedral approximation. The data format used by SG_Object is based on Baumgart's 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:

      1       4
      ________
    /  \    /
  /______\/

 2        3
Would be described as follows:
               o---[ HalfEdge1 ]---[ Vertex1 ]---o
               |                                 |
  [ Facet1 ]---+---[ HalfEdge2 ]---[ Vertex2 ]   |
      |        |                                 |
      |        o---[ HalfEdge3 ]---[ Vertex3 ]   |
      |                 |                        |
  [ Facet2 ]---+--------o                        |
               |                                 |
               |---[ HalfEdge4 ]---[ Vertex4 ]   |
               |                                 |
               +---[ HalfEdge5 ]-----------------o

Surfaces as well as solid objects may be represented. The link between facets and halfedges expresses handedness (for surfaces this is the notion of "side", for closed solids this is the notion of being "inside" or "outside"). When SG_Object is used to describe closed solids, the convention is: if one looks at an object from the outside and an edge is pointing up, its HEAD halfedge references the facet at the LEFT.

AG_Object(3) -> SG_Node(3) -> SG_Object.

SG_Object *
(SG_Node *parent, const char *name);


int
(SG_Object *so, const char *name, Uint flags);


void
(SG_Object *so);

The () function allocates, initializes, and attaches a SG_Object object.

() loads a mesh from a Stanford PLY file in either ASCII or binary format. Returns 0 on success or -1 if an error occurred. Acceptable flags options include:

SG_PLY_LOAD_VTX_NORMALS
Read vertex normals.
SG_PLY_LOAD_VTX_COLORS
Read vertex colors.
SG_PLY_LOAD_TEXCOORDS
Read texture coordinates.
SG_PLY_DUP_VERTICES
Check for, and eliminate duplicate vertices.

The () function clears all vertices, edges and facets associated with an object.

void
SG_VertexInit(SG_Vertex *vtx);


int
(SG_Object *so, const M_Vector3 pos);


int
(SG_Object *so, const M_Vector3 *pos);


int
(SG_Object *so, const M_Vector3 *pos, const M_Vector3 *normal);


int
(SG_Object *so, M_Real x, M_Real y);


int
(SG_Object *so, M_Real x, M_Real y, M_Real z);


int
(SG_Object *so, const SG_Vertex *vtx);

The () function initializes a vertex vtx that has already been allocated.

The () 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).

() is a variant of SG_VertexNew() which accepts a pointer to a M_Vector3.

() 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 () and SG_VertexNew3() variants of SG_VertexNew() accept coordinates as individual M_Real(3) arguments.

() creates a vertex using the coordinates from an existing vertex vtx.

SG_Edge *
SG_Edge2(SG_Object *so, int vTail, int vHead);


SG_Edge *
(SG_Object *so, int v1, int v2);


Uint
(SG_Object *so, int v1, int v2);


int
(SG_Object *so, Uint nBuckets);

The () 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 () 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 () function returns the index of the edgeTbl bucket corresponding to the edge between vertices v1 and v2.

() 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.

SG_Facet *
SG_FacetNew(SG_Object *so, int n);


SG_Facet *
(SG_Object *so);


SG_Facet *
(SG_Object *so);


SG_Facet *
(SG_Object *so, int v1, int v2, int v3);


SG_Facet *
(SG_Object *so, int v1, int v2, int v3, int v4);


void
(SG_Facet *f);

The () 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 () 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 () function deletes a facet, and removes any reference to it.

() 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:

SG_EXTRUDE_REGION
Create 2n edges and n+1 faces.
SG_EXTRUDE_EDGES
Create 2n edges and n faces.
SG_EXTRUDE_VERTICES
Create n edges and no faces.

M_Vector3
(SG_Object *so, SG_Facet *f);


M_Real
(SG_Object *so, SG_Facet *f);


M_Real
(SG_Object *so, SG_Facet *f);


M_Vector3
(SG_Object *so, SG_Facet *f);

The () function computes the normal vector for a given facet f. Mathematically, this is the vector cross-product of three vertices of the facet (for quad facets, the 4th vertex is ignored), normalized.

() computes the (unsigned) area covered by a facet SG_FacetAreaSigned() computes the signed area of a facet.

() computes the center of mass (centroid) of a facet.

int
SG_ObjectCheckConnectivity(SG_Object *so, AG_Console *console);


int
(SG_Object *so);


Uint
(SG_Object *so);


Uint8 *
(SG_Object *so, Uint *n);


Uint8 *
(SG_Object *so, Uint *n);

The () 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 non-NULL, errors are reported as AG_Console(3) messages, otherwise messages are printed using AG_Verbose(3).

() calculates the normal vector for every facet of the object, using SG_FacetNormal() on the individual facets.

The () converts all quad facets to triangular facets, returning the total number of facets that have been converted.

The () 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.

The following public SG_Object flags are defined:

SG_OBJECT_STATIC
Advise to the scene-partitioning algorithms that the geometry of the object will not change once it is attached to the scene. This allows some important optimizations to be performed.
SG_OBJECT_NODUPVERTEX
In SG_VertexNew(), test for an existing vertex at the new vertex coordinates. If a match is found, return the existing vertex instead of creating a new one.

The following public SG_Vertex flags are defined:

SG_VERTEX_SELECTED
Vertex is currently selected for edition.
SG_VERTEX_HIGHLIGHTED
Vertex is currently highlighted.

For the SG_Object object:

Uint flags
Option flags, see “FLAGS” section for details.
SG_Vertex *vtx
Array of vertices; see below.
Uint nvtx
Vertex count.
SG_EdgeEnt *edgeTbl
Hash table of halfedges; see below.
Uint nEdgeTbl
Number of buckets in halfedge table.
SLIST facets
Facets (quads or triangles); see below.
SG_Material *mat
Associated material, see SG_Material(3).

For the SG_EdgeEnt (halfedge bucket) structure:

SLIST edges
List of halfedges in bucket

For the SG_Edge (halfedge) structure:

int v
Index of incident vertex
SG_Facet *f
Pointer to incident facet
SG_Edge *oe
Pointer to opposite halfedge

For the SG_Vertex structure:

M_Real s,t
Texture coordinates (T2F)
M_Color c
Vertex color (C4F)
M_Vector3 n
Normal vector (N3F)
M_Vector3 v
Vertex position (V3F)
Uint flags
Vertex option flags (see “FLAGS” section for details).

AG_Queue(3), M_Real(3), M_Vector(3), SG(3), SG_Intro(3), SG_Material(3), SG_Node(3)

The SG_Object node class first appeared in Agar 1.6.0.

December 21, 2022 Agar 1.7

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.