CUGL
Cornell University Game Library
Public Member Functions | List of all members
cugl::PathExtruder Class Reference

#include <CUPathExtruder.h>

Public Member Functions

 PathExtruder ()
 
 PathExtruder (const std::vector< Vec2 > &points, bool closed)
 
 PathExtruder (const Poly2 &poly)
 
 ~PathExtruder ()
 
void set (const Poly2 &poly)
 
void set (const std::vector< Vec2 > &points, bool closed)
 
void reset ()
 
void clear ()
 
void calculate (float stroke, PathJoint joint=PathJoint::ROUND, PathCap cap=PathCap::ROUND)
 
Poly2 getPolygon ()
 
Poly2getPolygon (Poly2 *buffer)
 

Detailed Description

This class is a factory for extruding wireframe paths into a solid path.

An extrusion of a path is a second polygon that follows the path of the first one, but gives it width. Hence it takes a path and turns it into a solid shape. This is more complicated than simply triangulating the original polygon. The new polygon has more vertices, depending on the choice of joint (shape at the corners) and cap (shape at the end).

Unlike the traverse option, this method cannot be used to extrude an internal polygon tesselation. it assumes that the path is continuous.

As with all factories, the methods are broken up into three phases: initialization, calculation, and materialization. To use the factory, you first set the data (in this case a set of vertices or another Poly2) with the initialization methods. You then call the calculation method. Finally, you use the materialization methods to access the data in several different ways.

This division allows us to support multithreaded calculation if the data generation takes too long. However, note that this factory is not thread safe in that you cannot access data while it is still in mid-calculation.

CREDITS: This code is ported from the Kivy implementation of Line in package kivy.vertex_instructions. We believe that this port is acceptable within the scope of the Kivy license. There are no specific credits in that file, so there is no one specific to credit. However, thanks to the Kivy team for doing the heavy lifting on this method.

Because they did all the hard work, we will recommend their picture of how joints and end caps work:

 http://kivy.org/docs/_images/line-instruction.png

Constructor & Destructor Documentation

cugl::PathExtruder::PathExtruder ( )
inline

Creates an extruder with no vertex data.

cugl::PathExtruder::PathExtruder ( const std::vector< Vec2 > &  points,
bool  closed 
)
inline

Creates an extruder with the given vertex data.

The vertex data is copied. The extruder does not retain any references to the original data.

Parameters
pointsThe vertices to extrude
closedWhether the path is closed
cugl::PathExtruder::PathExtruder ( const Poly2 poly)
inline

Creates an extruder with the given vertex data.

The extrusion only uses the vertex data from the polygon. It ignores any existing indices. The constructor assumes the polygon is closed if the number of indices is twice the number of vertices.

The vertex data is copied. The extruder does not retain any references to the original data.

Parameters
polyThe vertices to extrude
cugl::PathExtruder::~PathExtruder ( )
inline

Deletes this extruder, releasing all resources.

Member Function Documentation

void cugl::PathExtruder::calculate ( float  stroke,
PathJoint  joint = PathJoint::ROUND,
PathCap  cap = PathCap::ROUND 
)

Performs a extrusion of the current vertex data.

An extrusion of a polygon is a second polygon that follows the path of the first one, but gives it width. Hence it takes a path and turns it into a solid shape. This is more complicated than simply triangulating the original polygon. The new polygon has more vertices, depending on the choice of joint (shape at the corners) and cap (shape at the end).

CREDITS: This code is ported from the Kivy implementation of Line in package kivy.vertex_instructions. We believe that this port is acceptable within the scope of the Kivy license. There are no specific credits in that file, so there is no one specific to credit. However, thanks to the Kivy team for doing the heavy lifting on this method.

Because they did all the hard work, we will plug their picture of how joints and end caps work:

 http://kivy.org/docs/_images/line-instruction.png
Parameters
strokeThe stroke width of the extrusion
jointThe extrusion joint type.
capThe extrusion cap type.
void cugl::PathExtruder::clear ( )
inline

Clears all internal data, the initial vertex data.

When this method is called, you will need to set a new vertices before calling calculate.

Poly2 cugl::PathExtruder::getPolygon ( )

Returns a polygon representing the path extrusion.

The polygon contains the a completely new set of vertices together with the indices defining the extrusion path. The extruder does not maintain references to this polygon and it is safe to modify it.

If the calculation is not yet performed, this method will return the empty polygon.

Returns
a polygon representing the path extrusion.
Poly2* cugl::PathExtruder::getPolygon ( Poly2 buffer)

Stores the path extrusion in the given buffer.

This method will add both the new vertices, and the corresponding indices to the new buffer. If the buffer is not empty, the indices will be adjusted accordingly. You should clear the buffer first if you do not want to preserve the original data.

If the calculation is not yet performed, this method will do nothing.

Parameters
bufferThe buffer to store the extruded polygon
Returns
a reference to the buffer for chaining.
void cugl::PathExtruder::reset ( )
inline

Clears all internal data, but still maintains the initial vertex data.

void cugl::PathExtruder::set ( const Poly2 poly)

Sets the vertex data for this extruder.

The extrusion only uses the vertex data from the polygon. It ignores any existing indices.

The vertex data is copied. The extruder does not retain any references to the original data. The method assumes the polygon is closed if the number of indices is twice the number of vertices.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
polyThe vertices to extrude
void cugl::PathExtruder::set ( const std::vector< Vec2 > &  points,
bool  closed 
)
inline

Sets the vertex data for this extruder.

The vertex data is copied. The extruder does not retain any references to the original data.

This method resets all interal data. You will need to reperform the calculation before accessing data.

Parameters
pointsThe vertices to extruder
closedWhether the path is closed

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