CUGL 2.1
Cornell University Game Library
Public Member Functions | Public Attributes | List of all members
cugl::Mesh< T > Class Template Reference

#include <CUMesh.h>

Public Member Functions

 Mesh ()
 
 ~Mesh ()
 
 Mesh (const Mesh &mesh)
 
 Mesh (Mesh &&mesh)
 
 Mesh (const Poly2 &poly)
 
Meshoperator= (const Mesh &other)
 
Meshoperator= (Mesh &&other)
 
Meshoperator= (const Poly2 &poly)
 
Meshset (const Mesh &other)
 
Meshset (const Poly2 &poly)
 
Meshset (const std::vector< T > &verts)
 
Meshset (const std::vector< T > &verts, const std::vector< GLuint > &indx)
 
Meshclear ()
 
Meshoperator*= (const Mat4 &transform)
 
Mesh operator* (const Mat4 &transform) const
 
Meshoperator+= (const Mesh &other)
 
Mesh operator+ (const Mesh &other) const
 
bool isSliceable () const
 
Mesh slice (size_t start, size_t end) const
 
Mesh sliceFrom (size_t start) const
 
Mesh sliceTo (size_t end) const
 

Public Attributes

std::vector< Tvertices
 
std::vector< GLuint > indices
 
GLenum command
 

Detailed Description

template<typename T>
class cugl::Mesh< T >

This class represents an arbitrary drawing mesh.

A mesh is a collection of vertices, together with indices and a drawing command. The type of the indices and drawing command are fixed, but the vertex type is templated. This allows a mesh to be adapter to an arbitrary Shader.

The only requirement of a mesh vertex is that it have at least one field called position, and this type be one of Vec2, Vec3 or Vec4.

Constructor & Destructor Documentation

◆ Mesh() [1/4]

template<typename T>
cugl::Mesh< T >::Mesh ( )
inline

Creates an empty mesh with no data.

Access the attributes to add data to the mesh.

◆ ~Mesh()

template<typename T>
cugl::Mesh< T >::~Mesh ( )
inline

Deletes the given mesh, freeing all resources.

◆ Mesh() [2/4]

template<typename T>
cugl::Mesh< T >::Mesh ( const Mesh< T > &  mesh)
inline

Creates a copy of the given mesh.

Both the vertices and the indices are copied. No references to the original mesh are kept.

Parameters
meshThe mesh to copy

◆ Mesh() [3/4]

template<typename T>
cugl::Mesh< T >::Mesh ( Mesh< T > &&  mesh)
inline

Creates a copy with the resource of the given polygon.

It is unsafe to use the original mesh after this method is called.

Parameters
meshThe mesh to take from

◆ Mesh() [4/4]

template<typename T>
cugl::Mesh< T >::Mesh ( const Poly2 poly)
inline

Creates a mesh from the given Poly2 object.

No vertex attribute other than position is set. Additional information (such as color or texture coordinate) must be added later. The command will be GL_TRIANGLES if the polygon is solid, GL_LINES if it is a path, and GL_UNDEFINED otherwise.

Parameters
polyThe polygon defining this mesh

Member Function Documentation

◆ clear()

template<typename T>
Mesh& cugl::Mesh< T >::clear ( )
inline

Clears the contents of this mesh and sets the command to GL_LINES

Returns
This mesh for chaining

◆ isSliceable()

template<typename T>
bool cugl::Mesh< T >::isSliceable ( ) const
inline

Returns true is this mesh is sliceable.

The only sliceable mesh types are GL_LINES and GL_TRIANGLES. That is because the mesh is represented in regular, decomposable chunks. This method not only checks that the command is correct, but that the index size is correct as well.

Returns
true is this mesh is sliceable.

◆ operator*()

template<typename T>
Mesh cugl::Mesh< T >::operator* ( const Mat4 transform) const
inline

Returns a new mesh by transforming the vertices of this one.

Because we allow meshes to be of arbitrary dimension, the only guaranteed safe transforms are Mat4 objects.

Note: This method does not modify the mesh.

Parameters
transformThe transform matrix
Returns
The transformed mesh

◆ operator*=()

template<typename T>
Mesh& cugl::Mesh< T >::operator*= ( const Mat4 transform)
inline

Transforms all of the vertices of this mesh.

Because we allow meshes to be of arbitrary dimension, the only guaranteed safe transforms are Mat4 objects.

Parameters
transformThe transform matrix
Returns
This mesh with the vertices transformed

◆ operator+()

template<typename T>
Mesh cugl::Mesh< T >::operator+ ( const Mesh< T > &  other) const
inline

Return the concatenation of this mesh and other.

The vertices of other are appended to the end of this mesh. The indices are reindex to account for this shift.

This method will fail to append to the mesh if other does not share the same command as this mesh.

Note: This method does not modify the mesh.

Parameters
otherThe mesh to concatenate
Returns
the concatenation of this mesh and other.

◆ operator+=()

template<typename T>
Mesh& cugl::Mesh< T >::operator+= ( const Mesh< T > &  other)
inline

Appends the given mesh to this one.

The vertices of other are appended to the end of this mesh. The indices are reindex to account for this shift.

This method will fail to append to the mesh if other does not share the same command as this mesh.

Parameters
otherThe mesh to append
Returns
This mesh with the new vertices

◆ operator=() [1/3]

template<typename T>
Mesh& cugl::Mesh< T >::operator= ( const Mesh< T > &  other)
inline

Sets this mesh to be a copy of the given one.

All of the contents are copied, so that this mesh does not hold any references to elements of the other mesh. This method returns a reference to this mesh for chaining.

Parameters
otherThe mesh to copy
Returns
This mesh for chaining

◆ operator=() [2/3]

template<typename T>
Mesh& cugl::Mesh< T >::operator= ( const Poly2 poly)
inline

Sets the mesh to match the Poly2 object.

No vertex attribute other than position is set. Additional information (such as color or texture coordinate) must be added later. The command will be GL_TRIANGLES if the polygon is solid, GL_LINES if it is a path, and GL_UNDEFINED otherwise.

This method returns a reference to this polygon for chaining.

Parameters
polyThe polygon defining this mesh
Returns
This polygon, returned for chaining

◆ operator=() [3/3]

template<typename T>
Mesh& cugl::Mesh< T >::operator= ( Mesh< T > &&  other)
inline

Sets this mesh to be have the resources of the given one.

It is unsafe to use the original mesh after this method is called.

This method returns a reference to this mesh for chaining.

Parameters
otherThe mesh to take from
Returns
This mesh for chaining

◆ set() [1/4]

template<typename T>
Mesh& cugl::Mesh< T >::set ( const Mesh< T > &  other)
inline

Sets this mesh to be a copy of the given one.

All of the contents are copied, so that this mesh does not hold any references to elements of the other mesh. This method returns a reference to this mesh for chaining.

Parameters
otherThe mesh to copy
Returns
This mesh for chaining

◆ set() [2/4]

template<typename T>
Mesh& cugl::Mesh< T >::set ( const Poly2 poly)
inline

Sets the mesh to match the Poly2 object.

No vertex attribute other than position is set. Additional information (such as color or texture coordinate) must be added later. The command will be GL_TRIANGLES if the polygon is solid, GL_LINES if it is a path, and GL_UNDEFINED otherwise.

This method returns a reference to this polygon for chaining.

Parameters
polyThe polygon defining this mesh
Returns
This polygon, returned for chaining

◆ set() [3/4]

template<typename T>
Mesh& cugl::Mesh< T >::set ( const std::vector< T > &  verts)
inline

Sets the mesh to have the given vertices

The resulting mesh has no indices. The command will be reset to GL_UNDEFINED.

This method returns a reference to this mesh for chaining.

Parameters
vertsThe vector of vertices (as Vec2) in this mesh
Returns
This mesh for chaining

◆ set() [4/4]

template<typename T>
Mesh& cugl::Mesh< T >::set ( const std::vector< T > &  verts,
const std::vector< GLuint > &  indx 
)
inline

Sets a mesh to have the given vertices and indices.

This method will assign a command according to the multiplicity of the indices. If the number of indices n is divisible by 3, it will be GL_TRIANGLES. Otherwise, if it is even, it will be GL_LINES. All other values will be undefined and the user must manually set the type.

This method returns a reference to this mesh for chaining.

Parameters
vertsThe vector of vertices (as floats) in this mesh
indxThe vector of indices for the rendering
Returns
This mesh for chaining

◆ slice()

template<typename T>
Mesh cugl::Mesh< T >::slice ( size_t  start,
size_t  end 
) const
inline

Returns the slice of this mesh between start and end.

The sliced mesh will use the indices from start to end (not including end). It will include the vertices referenced by those indices, and only those vertices. The command will remain the same.

The only sliceable mesh types are GL_LINES and GL_TRIANGLES. That is because the mesh is represented in regular, decomposable chunks. Any attempt to slice another mesh type will fail.

Parameters
startThe start index
endThe end index
Returns
the slice of this mesh between start and end.

◆ sliceFrom()

template<typename T>
Mesh cugl::Mesh< T >::sliceFrom ( size_t  start) const
inline

Returns the slice of this mesh from the start index to the end.

The sliced mesh will use the indices from start to the end. It will include the vertices referenced by those indices, and only those vertices. The command will remain the same.

The only sliceable mesh types are GL_LINES and GL_TRIANGLES. That is because the mesh is represented in regular, decomposable chunks. Any attempt to slice another mesh type will fail.

Parameters
startThe start index
Returns
the slice of this mesh between start and end.

◆ sliceTo()

template<typename T>
Mesh cugl::Mesh< T >::sliceTo ( size_t  end) const
inline

Returns the slice of this mesh from the begining to end.

The sliced mesh will use the indices up to (but not including) end. It will include the vertices referenced by those indices, and only those vertices. The command will remain the same.

The only sliceable mesh types are GL_LINES and GL_TRIANGLES. That is because the mesh is represented in regular, decomposable chunks. Any attempt to slice another mesh type will fail.

Parameters
endThe end index
Returns
the slice of this mesh between start and end.

Member Data Documentation

◆ command

template<typename T>
GLenum cugl::Mesh< T >::command

The OpenGL drawing command

◆ indices

template<typename T>
std::vector<GLuint> cugl::Mesh< T >::indices

The mesh indices, providing a shape to the vertices

◆ vertices

template<typename T>
std::vector<T> cugl::Mesh< T >::vertices

The mesh vertices, to be passed to the shader


The documentation for this class was generated from the following files: