CUGL 2.1
Cornell University Game Library
Public Member Functions | Static Public Member Functions | Protected Attributes | List of all members
cugl::scene2::PathNode Class Reference

#include <CUPathNode.h>

Inheritance diagram for cugl::scene2::PathNode:
cugl::scene2::TexturedNode cugl::scene2::SceneNode

Public Member Functions

 PathNode ()
 
 ~PathNode ()
 
bool initWithPath (const std::vector< Vec2 > &vertices, float stroke, poly2::Joint joint=poly2::Joint::SQUARE, poly2::EndCap cap=poly2::EndCap::BUTT, bool closed=true)
 
bool initWithPath (const Path2 &path, float stroke, poly2::Joint joint=poly2::Joint::SQUARE, poly2::EndCap cap=poly2::EndCap::BUTT)
 
bool initWithFilePath (const std::string &filename, const Path2 &path)
 
bool initWithFilePath (const std::string &filename, const Rect rect)
 
bool initWithTexturePath (const std::shared_ptr< Texture > &texture, const Path2 &path)
 
bool initWithTexturePath (const std::shared_ptr< Texture > &texture, const Rect rect)
 
virtual bool initWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data) override
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const override
 
void setStroke (float stroke)
 
float getStroke () const
 
void setClosed (bool closed)
 
bool getClosed () const
 
void setJoint (poly2::Joint joint)
 
poly2::Joint getJoint () const
 
void setCap (poly2::EndCap cap)
 
poly2::EndCap getCap () const
 
float getFringe () const
 
void setFringe (float fringe)
 
bool hasStencil () const
 
void setStencil (bool stencil)
 
void setPath (const std::vector< Vec2 > &vertices, bool closed=true)
 
void setPath (const Path2 &path)
 
void setPath (const Rect rect)
 
const Path2getPath () const
 
const Poly2getExtrusion () const
 
const Rect getBoundingRect () const
 
float getExtrudedContentWidth () const
 
float getExtrudedContentHeight () const
 
const Size getExtrudedContentSize () const
 
const Rect getExtrudedContentBounds () const
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint) override
 
- Public Member Functions inherited from cugl::scene2::TexturedNode
 TexturedNode ()
 
 ~TexturedNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
virtual bool initWithFile (const std::string &filename)
 
virtual bool initWithTexture (const std::shared_ptr< Texture > &texture)
 
void setTexture (const std::string &filename)
 
void setTexture (const std::shared_ptr< Texture > &texture)
 
std::shared_ptr< Texture > & getTexture ()
 
const std::shared_ptr< Texture > & getTexture () const
 
const std::shared_ptr< Gradient > & getGradient () const
 
void setGradient (const std::shared_ptr< Gradient > &gradient)
 
void shiftTexture (float dx, float dy)
 
void setBlendFunc (GLenum srcFactor, GLenum dstFactor)
 
GLenum getSourceBlendFactor () const
 
GLenum getDestinationBlendFactor () const
 
void setBlendEquation (GLenum equation)
 
GLenum getBlendEquation () const
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual std::string toString (bool verbose=false) const override
 
bool isAbsolute () const
 
void setAbsolute (bool flag)
 
virtual void setAnchor (const Vec2 anchor) override
 
virtual void setAnchor (float x, float y) override
 
virtual void setContentSize (const Size size) override
 
virtual void setContentSize (float width, float height) override
 
void refresh ()
 
- Public Member Functions inherited from cugl::scene2::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual bool initWithPosition (const Vec2 pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size size)
 
virtual bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect rect)
 
virtual bool initWithBounds (float x, float y, float width, float height)
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string getName () const
 
void setName (const std::string name)
 
const std::string getClassName () const
 
 operator std::string () const
 
const Vec2 getPosition () const
 
void setPosition (const Vec2 &position)
 
void setPosition (float x, float y)
 
float getPositionX (void) const
 
void setPositionX (float x)
 
float getPositionY (void) const
 
void setPositionY (float y)
 
Vec2 getWorldPosition () const
 
const Size getContentSize () const
 
float getContentWidth () const
 
void setContentWidth (float width)
 
float getContentHeight () const
 
void setContentHeight (float height)
 
virtual Rect getLayoutBounds () const
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
const Vec2 getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
virtual void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor () const
 
void setRelativeColor (bool flag)
 
std::shared_ptr< ScissorgetScissor () const
 
void setScissor (const std::shared_ptr< Scissor > &scissor)
 
void setScissor ()
 
const Vec2 getScale () const
 
float getScaleX () const
 
float getScaleY () const
 
void setScale (float scale)
 
void setScale (const Vec2 vec)
 
void setScale (float sx, float sy)
 
float getAngle ()
 
void setAngle (float angle)
 
const Affine2getTransform () const
 
const Affine2getAlternateTransform () const
 
void setAlternateTransform (const Affine2 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Affine2getNodeToParentTransform () const
 
Affine2 getParentToNodeTransform () const
 
Affine2 getNodeToWorldTransform () const
 
Affine2 getWorldToNodeTransform () const
 
Vec2 screenToNodeCoords (const Vec2 screenPoint) const
 
Vec2 worldToNodeCoords (const Vec2 worldPoint) const
 
Vec2 nodeToScreenCoords (const Vec2 nodePoint) const
 
Vec2 nodeToWorldCoords (const Vec2 nodePoint) const
 
Vec2 parentToNodeCoords (const Vec2 parentPoint) const
 
Vec2 nodeToParentCoords (const Vec2 nodePoint) const
 
size_t getChildCount () const
 
std::shared_ptr< SceneNodegetChild (unsigned int pos)
 
const std::shared_ptr< SceneNode > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< T > getChild (unsigned int pos) const
 
std::shared_ptr< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< T > getChildByName (const std::string name) const
 
std::vector< std::shared_ptr< SceneNode > > getChildren ()
 
const std::vector< std::shared_ptr< SceneNode > > & getChildren () const
 
void addChild (const std::shared_ptr< SceneNode > &child)
 
void addChildWithTag (const std::shared_ptr< SceneNode > &child, unsigned int tag)
 
void addChildWithName (const std::shared_ptr< SceneNode > &child, const std::string name)
 
void swapChild (const std::shared_ptr< SceneNode > &child1, const std::shared_ptr< SceneNode > &child2, bool inherit=false)
 
SceneNodegetParent ()
 
const SceneNodegetParent () const
 
Scene2getScene ()
 
const Scene2getScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< SceneNode > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string name)
 
virtual void removeAllChildren ()
 
void setPriority (float priority)
 
float getPriority ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Affine2 &transform, Color4 tint)
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch)
 
const std::shared_ptr< Layout > & getLayout () const
 
void setLayout (const std::shared_ptr< Layout > &layout)
 
virtual void doLayout ()
 

Static Public Member Functions

static std::shared_ptr< PathNodealloc ()
 
static std::shared_ptr< PathNodeallocWithVertices (const std::vector< Vec2 > &vertices, float stroke, poly2::Joint joint=poly2::Joint::SQUARE, poly2::EndCap cap=poly2::EndCap::BUTT, bool closed=true)
 
static std::shared_ptr< PathNodeallocWithPath (const Path2 &path, float stroke, poly2::Joint joint=poly2::Joint::SQUARE, poly2::EndCap cap=poly2::EndCap::BUTT)
 
static std::shared_ptr< PathNodeallocWithRect (const Rect rect, float stroke, poly2::Joint joint=poly2::Joint::SQUARE, poly2::EndCap cap=poly2::EndCap::BUTT)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::scene2::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec2 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Size size)
 
static std::shared_ptr< SceneNodeallocWithBounds (float width, float height)
 
static std::shared_ptr< SceneNodeallocWithBounds (const Rect rect)
 
static std::shared_ptr< SceneNodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< SceneNodeallocWithData (const Scene2Loader *loader, const std::shared_ptr< JsonValue > &data)
 

Protected Attributes

Path2 _path
 
Poly2 _polygon
 
float _stroke
 
poly2::Joint _joint
 
poly2::EndCap _endcap
 
Rect _extrabounds
 
float _fringe
 
bool _stencil
 
SimpleExtruder _extruder
 
Mesh< SpriteVertex2_border
 
- Protected Attributes inherited from cugl::scene2::TexturedNode
std::shared_ptr< Texture_texture
 
std::shared_ptr< Gradient_gradient
 
bool _absolute
 
Vec2 _offset
 
bool _rendered
 
Mesh< SpriteVertex2_mesh
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _flipHorizontal
 
bool _flipVertical
 
- Protected Attributes inherited from cugl::scene2::SceneNode
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
std::shared_ptr< Scissor_scissor
 
Vec2 _scale
 
float _angle
 
Affine2 _transform
 
bool _useTransform
 
Affine2 _combined
 
std::vector< std::shared_ptr< SceneNode > > _children
 
SceneNode_parent
 
Scene2_graph
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
std::string _classname
 
float _priority
 
std::shared_ptr< JsonValue_json
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::scene2::TexturedNode
void clearRenderData ()
 
 CU_DISALLOW_COPY_AND_ASSIGN (TexturedNode)
 

Detailed Description

This is a scene graph node to represent a path with width.

At first glance, it would appear that this class is unnecessary. A path with width, produced by SimpleExtruder, is a solid polygon. This polygon can, in turn, be used in conjunction with PolygonNode.

However, there are some subtle issues. In particular, mitres and joints may mean that a PathNode and WireNode at the same position will not line up with one another. This is undesirable. Hence this is a special polygon node that takes into account that it is an extruded path.

One of the side effects of this is that the content size of the node is defined by the path, NOT the extruded polygon. If you want the bounds of the extruded path (relative to Node space), you should use the method getExtrudedContentBounds(). Additionally, the anchor point is relative to the content size not the extruded size. This means that the extruded path may be to the left of the origin even when the anchor is at (0,0).

Because paths have width, it is natural to texture them. However, generally you will only want to create a path with the degenerate texture (to draw a solid, colored path). Hence, none of the static constructors take a texture. You are free to update the texture after creation, if you wish.

The extruded polygon is specified in image coordinates. Image coordinates are different from texture coordinates. Their origin is at the bottom-left corner of the file, and each pixel is one unit. This makes specifying to polygon more natural for irregular shapes.

This means that an extrusion with vertices (0,0), (width,0), (width,height), and (0,height) would be identical to a sprite node. However, an extrusion with vertices (0,0), (2*width,0), (2*width,2*height), and (0,2*height) would tile the sprite (given the wrap settings) twice both horizontally and vertically. A uniform translation of the extrusion (in contrast to the node itself) will not move the shape on the the screen. Instead, it will just change the part or the texture it uses.

For example, suppose the texture has given width and height. We have one extrusion with vertices (0,0), (width/2,0), (width/2,height/2), and (0,height/2). We have another extrusion with vertices (width/2,height/2), (width,height/2), (width,height), and (width/2,height). Both extrusion would have size (width/2,height/2) and be centered at the node position. However, the first would use the bottom left part of the texture, while the second would use the top right.

You can disable these features at any time by setting the attribute absolute to true. Do this will place the path vertices in their absolute positions in Node space. This will also disable anchor functions (setting the anchor as the bottom left corner), since anchors do not make sense when we are drawing vertices directly into the coordinate space.

Constructor & Destructor Documentation

◆ PathNode()

cugl::scene2::PathNode::PathNode ( )

Creates an empty path node.

You must initialize this PathNode before use.

NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.

◆ ~PathNode()

cugl::scene2::PathNode::~PathNode ( )
inline

Releases all resources allocated with this node.

This will release, but not necessarily delete the associated texture. However, the polygon and drawing commands will be deleted and no longer safe to use.

Member Function Documentation

◆ alloc()

static std::shared_ptr<PathNode> cugl::scene2::PathNode::alloc ( )
inlinestatic

Returns an empty path node.

The underlying path is empty, and must be set via setPath().

Returns
an empty path node.

◆ allocWithData()

static std::shared_ptr<SceneNode> cugl::scene2::PathNode::allocWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
inlinestatic

Returns a new path node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

 "path":     A JSON object defining a path. See {@link Path2}.
 "stroke":   A number specifying the stroke width.
 "joint":    One of "mitre', "bevel", "square", or "round".
 "endcap":   One of "square", "round", or "butt".
 "fringe":   A number indicating the size of the border fringe.
 "stencil"   A boolean indicating whether to stencil the path.

All attributes are optional. If the path is not specified, the node will use a rectangle with the dimensions of the texture. For more information, see TexturedNode#initWithData.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
a new path node with the given JSON specificaton.

◆ allocWithPath()

static std::shared_ptr<PathNode> cugl::scene2::PathNode::allocWithPath ( const Path2 path,
float  stroke,
poly2::Joint  joint = poly2::Joint::SQUARE,
poly2::EndCap  cap = poly2::EndCap::BUTT 
)
inlinestatic

Returns a new path node with the given path and stroke width.

This method will extrude the path with the specified joint and cap. This method uses SimpleExtruder, as it is safe for framerate calculation.

Parameters
pathThe path to texture (expressed in image space)
strokeThe stroke width of the extruded path.
jointThe joint between extrusion line segments.
capThe end caps of the extruded paths.
Returns
a new path node with the given polygon and stroke width.

◆ allocWithRect()

static std::shared_ptr<PathNode> cugl::scene2::PathNode::allocWithRect ( const Rect  rect,
float  stroke,
poly2::Joint  joint = poly2::Joint::SQUARE,
poly2::EndCap  cap = poly2::EndCap::BUTT 
)
inlinestatic

Returns a new path node with the given rect and stroke width.

The rectangle will be converted into a Poly2, using the standard outline. This is the same as passing Poly2(rect,false). The traversal will be CLOSED. It will then be extruded with the current joint and cap. PathNode objects share a single extruder, so this constructor is not thread safe.

Parameters
rectThe rectangle for to texture.
strokeThe stroke width of the extruded path.
jointThe joint between extrusion line segments.
capThe end caps of the extruded paths.
Returns
a new path with the given rect and stroke width.

◆ allocWithVertices()

static std::shared_ptr<PathNode> cugl::scene2::PathNode::allocWithVertices ( const std::vector< Vec2 > &  vertices,
float  stroke,
poly2::Joint  joint = poly2::Joint::SQUARE,
poly2::EndCap  cap = poly2::EndCap::BUTT,
bool  closed = true 
)
inlinestatic

Returns a new path node with the given vertices and stroke width.

This method will extrude the vertices with the specified joint and cap. This method uses SimpleExtruder, as it is safe for framerate calculation.

Parameters
verticesThe vertices to texture (expressed in image space)
strokeThe stroke width of the extruded path.
jointThe joint between extrusion line segments.
capThe end caps of the extruded paths.
closedThe whether the vertex path is open or closed.
Returns
a new path node with the given vertices and stroke width.

◆ copy()

virtual std::shared_ptr<SceneNode> cugl::scene2::PathNode::copy ( const std::shared_ptr< SceneNode > &  dst) const
overridevirtual

Performs a shallow copy of this Node into dst.

No children from this node are copied, and no children of dst are modified. In addition, the parents of both Nodes are unchanged. However, all other attributes of this node are copied.

Parameters
dstThe Node to copy into
Returns
A reference to dst for chaining.

Reimplemented from cugl::scene2::TexturedNode.

◆ draw()

virtual void cugl::scene2::PathNode::draw ( const std::shared_ptr< SpriteBatch > &  batch,
const Affine2 transform,
Color4  tint 
)
overridevirtual

Draws this path node via the given SpriteBatch.

This method only worries about drawing the current node. It does not attempt to render the children.

Parameters
batchThe SpriteBatch to draw with.
transformThe global transformation matrix.
tintThe tint to blend with the Node color.

Implements cugl::scene2::TexturedNode.

◆ getBoundingRect()

const Rect cugl::scene2::PathNode::getBoundingRect ( ) const
inline

Returns the rect of the Polygon in points

The bounding rect is the smallest rectangle containing all of the points in the polygon.

This value also defines the content size of the node. The polygon will be shifted so that its bounding rect is centered at the node center.

◆ getCap()

poly2::EndCap cugl::scene2::PathNode::getCap ( ) const
inline

Returns the cap shape at the ends of the path.

Returns
the cap shape at the ends of the path.

◆ getClosed()

bool cugl::scene2::PathNode::getClosed ( ) const
inline

Returns whether the path is closed.

If set to true, this will smooth the polygon to remove all gaps, regardless of the original inidices in the polygon. Furthermore, previous information about existing gaps is lost, so that setting the value back to false will only open the curve at the end.

Returns
whether the path is closed.

◆ getExtrudedContentBounds()

const Rect cugl::scene2::PathNode::getExtrudedContentBounds ( ) const
inline

Returns the bounding box of the extruded content.

This method is similar to getExtrudedContentSize() in that it returns the extra content size created by the stroke width, mitres, and caps. In addition, it returns the actual bounds of the path within Node space.

Unlike getBoundingBox(), this method is unaffected by any transforms on this node.

Returns
the bounding box of the extruded content.

◆ getExtrudedContentHeight()

float cugl::scene2::PathNode::getExtrudedContentHeight ( ) const
inline

Returns the height of the extruded content.

This method is an alternative to getContentHeight(). That method only returns the content height of the path polygon; it does not include the stroke width, mitres, and caps. This method includes the extra height of the extruded path.

Returns
the height of the extruded content.

◆ getExtrudedContentSize()

const Size cugl::scene2::PathNode::getExtrudedContentSize ( ) const
inline

Returns the size of the extruded content.

This method is an alternative to getContentSize(). That method only returns the content size of the path polygon; it does not include the stroke width, mitres, and caps. This method includes the extra size of the extruded path.

Returns
the size of the extruded content.

◆ getExtrudedContentWidth()

float cugl::scene2::PathNode::getExtrudedContentWidth ( ) const
inline

Returns the width of the extruded content.

This method is an alternative to getContentWidth(). That method only returns the content width of the path polygon; it does not include the stroke width, mitres, and caps. This method includes the extra width of the extruded path.

Returns
the width of the extruded content.

◆ getExtrusion()

const Poly2& cugl::scene2::PathNode::getExtrusion ( ) const
inline

Returns the extruded path for this scene graph node

Returns
the extruded path for this scene graph node

◆ getFringe()

float cugl::scene2::PathNode::getFringe ( ) const
inline

Returns the antialiasing fringe for this polygon node

If this value is non-zero, the node will surround the stroke with an additional stroke the width of the fringe. The second stroke will fade to transparent on the outside edge. This is a way of providing anti- aliasing that is significantly better than multisampling. Furthermore, this works on OpenGLES, which does not support multisampling.

Creating a fringe does introduce some overhead. The extruder must do a second pass on the boundary of the first stroke (which was computed during the first extrusion). In addition, this effect is often unnecessary on retina/high-dpi displays. As a result, the default fringe value is 0.

A fringe value should be >= 0.5 to have noticeable effects. In practice, values between 1 and 2 work best.

Returns
the antialiasing fringe for this polygon node

◆ getJoint()

poly2::Joint cugl::scene2::PathNode::getJoint ( ) const
inline

Returns the joint type between path segments.

Returns
the joint type between path segments.

◆ getPath()

const Path2& cugl::scene2::PathNode::getPath ( ) const
inline

Returns the base path for this scene graph node

Returns
the base path for this scene graph node

◆ getStroke()

float cugl::scene2::PathNode::getStroke ( ) const
inline

Returns the stroke width of the path.

Returns
the stroke width of the path.

◆ hasStencil()

bool cugl::scene2::PathNode::hasStencil ( ) const
inline

Returns true if this node uses stencil effects

Stencil effects are only necessary if the stroke both overlaps itself and has transparency. These overlaps can cause weird artifacts in the transparent regions, as they blend together. The stencil effect makes sure that the stroke appears as one uniform polygon with no overlaps.

By default this value is false. However, adding a fringe to a stroke guarantees a transparent region. Therefore, we recommend turning it on when using a fringe.

Returns
true if this node uses stencil effects

◆ initWithData()

virtual bool cugl::scene2::PathNode::initWithData ( const Scene2Loader loader,
const std::shared_ptr< JsonValue > &  data 
)
overridevirtual

Initializes a path node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene2Loader. This JSON format supports all of the attribute values of its parent class. In addition, it supports the following additional attributes:

 "path":     A JSON object defining a path. See {@link Path2}.
 "stroke":   A number specifying the stroke width.
 "joint":    One of "mitre', "bevel", "square", or "round".
 "endcap":   One of "square", "round", or "butt".
 "fringe":   A number indicating the size of the border fringe.
 "stencil"   A boolean indicating whether to stencil the path.

All attributes are optional. If the path is not specified, the node will use a rectangle with the dimensions of the texture. For more information, see TexturedNode#initWithData.

Parameters
loaderThe scene loader passing this JSON file
dataThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithFilePath() [1/2]

bool cugl::scene2::PathNode::initWithFilePath ( const std::string &  filename,
const Path2 path 
)

Initializes a path node from the image filename and the path.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
pathThe path to texture
Returns
true if the node is initialized properly, false otherwise.

◆ initWithFilePath() [2/2]

bool cugl::scene2::PathNode::initWithFilePath ( const std::string &  filename,
const Rect  rect 
)

Initializes a path node from the image filename and the given rect.

The rectangle will be extruded using a mitre joint.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
rectThe rectangle to texture
Returns
true if the node is initialized properly, false otherwise.

◆ initWithPath() [1/2]

bool cugl::scene2::PathNode::initWithPath ( const Path2 path,
float  stroke,
poly2::Joint  joint = poly2::Joint::SQUARE,
poly2::EndCap  cap = poly2::EndCap::BUTT 
)

Intializes a path node with the given polygon and stroke width.

This method will extrude the path with the specified joint and cap. This method uses SimpleExtruder, as it is safe for framerate calculation.

You do not need to set the texture; rendering this into a SpriteBatch will simply use the blank texture. Hence the path will have a solid color.

Parameters
pathThe path to texture (expressed in image space)
strokeThe stroke width of the extruded path.
jointThe joint between extrusion line segments.
capThe end caps of the extruded paths.
Returns
true if the path node is initialized properly, false otherwise.

◆ initWithPath() [2/2]

bool cugl::scene2::PathNode::initWithPath ( const std::vector< Vec2 > &  vertices,
float  stroke,
poly2::Joint  joint = poly2::Joint::SQUARE,
poly2::EndCap  cap = poly2::EndCap::BUTT,
bool  closed = true 
)

Intializes a path with the given vertices and stroke width.

This method will extrude the vertices with the specified joint and cap. This method uses SimpleExtruder, as it is safe for framerate calculation.

You do not need to set the texture; rendering this into a SpriteBatch will simply use the blank texture. Hence the path will have a solid color.

Parameters
verticesThe vertices to texture (expressed in image space)
strokeThe stroke width of the extruded path.
jointThe joint between extrusion line segments.
capThe end caps of the extruded paths.
closedThe whether the vertex path is open or closed.
Returns
true if the path node is initialized properly, false otherwise.

◆ initWithTexturePath() [1/2]

bool cugl::scene2::PathNode::initWithTexturePath ( const std::shared_ptr< Texture > &  texture,
const Path2 path 
)

Initializes a path node from a texture and the given path.

Parameters
textureA shared pointer to a Texture object.
pathThe path to texture
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithTexturePath() [2/2]

bool cugl::scene2::PathNode::initWithTexturePath ( const std::shared_ptr< Texture > &  texture,
const Rect  rect 
)

Initializes a path node from a texture and the given rect.

The conversion of rectangle to polygon is subclass specific.

Parameters
textureA shared pointer to a Texture object.
rectThe rectangle to texture
Returns
true if the sprite is initialized properly, false otherwise.

◆ setCap()

void cugl::scene2::PathNode::setCap ( poly2::EndCap  cap)

Sets the cap shape at the ends of the path.

This method affects the extruded polygon, but not the original path polygon.

Parameters
capThe cap shape at the ends of the path.

◆ setClosed()

void cugl::scene2::PathNode::setClosed ( bool  closed)

Sets whether the path is closed.

If set to true, this will smooth the polygon to remove all gaps, regardless of the original inidices in the polygon. Furthermore, previous information about existing gaps is lost, so that setting the value back to false will only open the curve at the end.

Parameters
closedWhether the path is closed.

◆ setFringe()

void cugl::scene2::PathNode::setFringe ( float  fringe)
inline

Sets the antialiasing fringe for this polygon node

If this value is non-zero, the node will surround the stroke with an additional stroke the width of the fringe. The second stroke will fade to transparent on the outside edge. This is a way of providing anti- aliasing that is significantly better than multisampling. Furthermore, this works on OpenGLES, which does not support multisampling.

Creating a fringe does introduce some overhead. The extruder must do a second pass on the boundary of the first stroke (which was computed during the first extrusion). In addition, this effect is often unnecessary on retina/high-dpi displays. As a result, the default fringe value is 0.

A fringe value should be >= 0.5 to have noticeable effects. In practice, values between 1 and 2 work best.

Parameters
fringeThe antialiasing fringe for this polygon node

◆ setJoint()

void cugl::scene2::PathNode::setJoint ( poly2::Joint  joint)

Sets the joint type between path segments.

This method affects the extruded polygon, but not the original path polygon.

Parameters
jointThe joint type between path segments

◆ setPath() [1/3]

void cugl::scene2::PathNode::setPath ( const Path2 path)

Sets the path to the given one in texture space.

Parameters
pathThe path to texture

◆ setPath() [2/3]

void cugl::scene2::PathNode::setPath ( const Rect  rect)

Sets the texture path to one equivalent to the given rect.

The rectangle will be extruded with mitre joints.

Parameters
rectThe rectangle to texture

◆ setPath() [3/3]

void cugl::scene2::PathNode::setPath ( const std::vector< Vec2 > &  vertices,
bool  closed = true 
)

Sets the path to the vertices expressed in texture space.

Parameters
verticesThe vertices to texture
closedWhether the path is closed

◆ setStencil()

void cugl::scene2::PathNode::setStencil ( bool  stencil)
inline

Sets whether to use stencil effects in this node

Stencil effects are only necessary if the stroke both overlaps itself and has transparency. These overlaps can cause weird artifacts in the transparent regions, as they blend together. The stencil effect makes sure that the stroke appears as one uniform polygon with no overlaps.

By default this value is false. However, adding a fringe to a stroke guarantees a transparent region. Therefore, we recommend turning it on when using a fringe.

Parameters
stencilWhether to use stencil effects in this node

◆ setStroke()

void cugl::scene2::PathNode::setStroke ( float  stroke)

Sets the stroke width of the path.

This method affects the extruded polygon, but not the source path polygon.

Parameters
strokeThe stroke width of the path

Member Data Documentation

◆ _border

Mesh<SpriteVertex2> cugl::scene2::PathNode::_border
protected

The fringe mesh

◆ _endcap

poly2::EndCap cugl::scene2::PathNode::_endcap
protected

The shape of the two end caps of the path.

◆ _extrabounds

Rect cugl::scene2::PathNode::_extrabounds
protected

The extruded bounds

◆ _extruder

SimpleExtruder cugl::scene2::PathNode::_extruder
protected

The extruder for this node

◆ _fringe

float cugl::scene2::PathNode::_fringe
protected

The border fringe for the mesh

◆ _joint

poly2::Joint cugl::scene2::PathNode::_joint
protected

The joint between segments of the path.

◆ _path

Path2 cugl::scene2::PathNode::_path
protected

The path defining this node

◆ _polygon

Poly2 cugl::scene2::PathNode::_polygon
protected

The extruded path as a solid polygon

◆ _stencil

bool cugl::scene2::PathNode::_stencil
protected

Whether to stencil the path (for overlaps)

◆ _stroke

float cugl::scene2::PathNode::_stroke
protected

The stroke width of this path.


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