|
AGL
0
3D graphics library
|
Functions | |
| void | normalizeVertices (Entity &e, float t=1) |
| Normalize all vertices of e. More... | |
| void | subdivideFaces (Entity &e) |
| Subdivide all faces of e. More... | |
| void | calcNormals (Entity &e, bool perFace=false) |
| Calculates the normals for the Entity algorithmically. More... | |
| void | calcTextureCoords (Entity &e, glm::vec3 px=glm::vec3(.5, 0,.5), glm::vec3 py=glm::vec3(.5,.5, 0), bool normalize=false) |
| Calculates texture coordinates for the Entity algorithmically. More... | |
| std::vector< GLuint > | triangulatePolygon (const std::vector< GLuint > &polygon) |
| Triangulates polygons with 3+ vertices. More... | |
These are utility functions that can be used on Entity or the shapes. These functions will modify the Entity they take in as parameter instead of returning a new Entity.
| void calcNormals | ( | Entity & | e, |
| bool | perFace = false |
||
| ) |
Calculates the normals for the Entity algorithmically.
| e | Entity to calculate the normals for. |
| perFace | If true, normals are calculated for each face, instead of each vertex. Currently unused. |
This function calculates the normals for each vertex of e. The normals are pointed radially outwards from the geometric center of the entity. Geometric center is calculated simply by averaging all the vertices.
| void calcTextureCoords | ( | Entity & | e, |
| glm::vec3 | px = glm::vec3(.5, 0,.5), |
||
| glm::vec3 | py = glm::vec3(.5,.5, 0), |
||
| bool | normalize = false |
||
| ) |
Calculates texture coordinates for the Entity algorithmically.
| e | Entity to calculate the Entity::uvs for. |
| px | Parameter for x coordinate of texture. |
| py | Parameter for y coordinate of texture. |
| normalize | If true, the coordinates are scaled to range from 0 to 1. |
This function calculates the texture coordinates for e automatically. The coordinates may not be what you expect, but are promised to be continuous. The coordinate for each vertex is generated by calculating the dot product of the vertex with the respective parameter. The default parameters works almost well to generate non-repetitive and smooth coordinates for vertices ranging between 0 to 1.
| void normalizeVertices | ( | Entity & | e, |
| float | t = 1 |
||
| ) |
Normalize all vertices of e.
| e | Entity to normalize vertices. |
| t | Amount of normalization. |
This function normalizes all the vertices of an Entity, it projects all the vertices on the surface of a unit sphere centered at the origin. The value of t defines the amount of normalization. 0 means no normalization, ie. the vertices will remain at their original position. 1 means complete normalization, ie. the vertices will be completely mapped on the surface of a unit sphere. For example, a value of 0.5 will bring all the vertices halfway to the surface of a unit sphere.
| void subdivideFaces | ( | Entity & | e | ) |
Subdivide all faces of e.
| e | The entity whose faces will be normalized. |
This function will insert a new vertex at the center of each of the edges of the entity. It'll then join the three vertices at the center of each of the edges of each of the triangular faces, thereby dividing each face into four face. This way more vertex and faces are introduced, which can later be modified for a smoother surface.
| std::vector< GLuint > triangulatePolygon | ( | const std::vector< GLuint > & | polygon | ) |
Triangulates polygons with 3+ vertices.
| polygon | Indices to triangulate. |
This function is used to triangulate non-triangular faces. This is different from a normal triangulation algorithm. This function do not require the actual vertices as it does not introduce new vertices. It just rearranges and copies the indices forming the faces (polygons) such that each triplet represents a non-overlapping triangle. This also means that this algorithm will fail for non-convex polygons. The algorithm tries to equally distribute the vertices among different faces to reduce crowding of edges. It also preserves the orientation of the face vertices in the new triangular faces.