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

#include <CUPolygonNode.h>

Inheritance diagram for cugl::scene2::PolygonNode:
cugl::scene2::TexturedNode cugl::scene2::SceneNode cugl::scene2::SpriteNode

Public Member Functions

 PolygonNode ()
 
 ~PolygonNode ()
 
bool initWithPoly (const std::vector< Vec2 > &vertices)
 
bool initWithPoly (const Poly2 &poly)
 
bool initWithPoly (const Rect rect)
 
virtual bool initWithFile (const std::string &filename) override
 
bool initWithFilePoly (const std::string &filename, const std::vector< Vec2 > &vertices)
 
bool initWithFilePoly (const std::string &filename, const Poly2 &poly)
 
bool initWithFilePoly (const std::string &filename, const Rect rect)
 
virtual bool initWithTexture (const std::shared_ptr< Texture > &texture) override
 
bool initWithTexturePoly (const std::shared_ptr< Texture > &texture, const std::vector< Vec2 > &vertices)
 
bool initWithTexturePoly (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
bool initWithTexturePoly (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
 
float getFringe () const
 
void setFringe (float fringe)
 
virtual void setPolygon (const std::vector< Vec2 > &vertices)
 
virtual void setPolygon (const Poly2 &poly)
 
virtual void setPolygon (const Rect rect)
 
const Poly2getPolygon () const
 
const Rect getBoundingRect () 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
 
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< PolygonNodealloc ()
 
static std::shared_ptr< PolygonNodeallocWithPoly (const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodeallocWithPoly (const Poly2 &poly)
 
static std::shared_ptr< PolygonNodeallocWithPoly (const Rect rect)
 
static std::shared_ptr< PolygonNodeallocWithFile (const std::string &filename)
 
static std::shared_ptr< PolygonNodeallocWithFilePoly (const std::string &filename, const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodeallocWithFilePoly (const std::string &filename, const Poly2 &poly)
 
static std::shared_ptr< PolygonNodeallocWithFilePoly (const std::string &filename, const Rect rect)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
static std::shared_ptr< PolygonNodeallocWithTexture (const std::shared_ptr< Texture > &texture, const Rect rect)
 
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

Poly2 _polygon
 
float _fringe
 
- 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 representing a textured solid 2D polygon.

The 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 a polygon more natural for irregular shapes.

This means that a polygon with vertices (0,0), (width,0), (width,height), and (0,height) would be identical to a sprite node. However, a polygon 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.

The content size of this node is defined by the size (but not the offset) of the bounding box. The anchor point is relative to this content size. The default anchor point in a TexturedNode is (0.5, 0.5). This means that a uniform translation of the polygon (in contrast to the node itself) will not move the shape on the the screen. Instead, it will just change the part of the texture it uses.

For example, suppose the texture has given width and height. We have one polygon with vertices (0,0), (width/2,0), (width/2,height/2), and (0,height/2). We have another polygon with vertices (width/2,height/2), (width,height/2), (width,height), and (width/2,height). Both polygons would create a rectangle of size (width/2,height/2). 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. Doing this will place the polygon 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

◆ PolygonNode()

cugl::scene2::PolygonNode::PolygonNode ( )
inline

Creates an empty polygon with the degenerate texture.

You must initialize this PolygonNode 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.

◆ ~PolygonNode()

cugl::scene2::PolygonNode::~PolygonNode ( )
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<PolygonNode> cugl::scene2::PolygonNode::alloc ( )
inlinestatic

Returns an empty polygon with the degenerate texture.

You do not need to set the texture; rendering this into a SpriteBatch will simply use the blank texture. The polygon, however, will also be empty, and must be set via setPolygon.

Returns
an empty polygon with the degenerate texture.

◆ allocWithData()

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

Returns a new polygon 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:

 "polygon":  A JSON object defining a polygon. See {@link Poly2}.
 "fringe":   A number indicating the size of the border fringe.

All attributes are optional. If the polygon 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 polygon with the given JSON specificaton.

◆ allocWithFile()

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithFile ( const std::string &  filename)
inlinestatic

Returns a new polygon node from the image filename.

After creation, the polygon will be a rectangle. The vertices of this polygon will be the corners of the image. The rectangle will be triangulated with the standard two triangles.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
Returns
a new polygon node from the image filename.

◆ allocWithFilePoly() [1/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithFilePoly ( const std::string &  filename,
const Poly2 poly 
)
inlinestatic

Returns a new polygon node from the image filename and the given polygon.

The polygon will define the portion of the of the texture shown (in image space).

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
polyThe polygon to texture
Returns
a new polygon node from the image filename and the given polygon.

◆ allocWithFilePoly() [2/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithFilePoly ( const std::string &  filename,
const Rect  rect 
)
inlinestatic

Returns a new polygon node from the image filename and the given rect.

The vertices of the rectangle will define the portion of the texture shown (in image space). The rectangle will be triangulated with the standard two triangles.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
rectThe rectangle to texture
Returns
a new polygon node from the image filename and the given rect.

◆ allocWithFilePoly() [3/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithFilePoly ( const std::string &  filename,
const std::vector< Vec2 > &  vertices 
)
inlinestatic

Returns a new polygon node from the image filename and the given vertices.

The vertices will define the portion of the of the texture shown (in image space). The vertices will be triangulated with EarclipTriangulator.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
verticesThe vertices to texture (expressed in image space)
Returns
a new polygon node from the image filename and the given vertices.

◆ allocWithPoly() [1/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithPoly ( const Poly2 poly)
inlinestatic

Returns a new polygon node with the given shape.

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

Parameters
polyThe polygon to texture
Returns
a new polygon node with the given shape.

◆ allocWithPoly() [2/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithPoly ( const Rect  rect)
inlinestatic

Returns a new polygon node with the given rect.

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

The rectangle will be triangulated with the standard two triangles.

Parameters
rectThe rectangle to texture
Returns
a new polygon node with the given rect.

◆ allocWithPoly() [3/3]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithPoly ( const std::vector< Vec2 > &  vertices)
inlinestatic

Returns a new polygon node with the given vertices.

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

The vertices will be triangulated with EarclipTriangulator.

Parameters
verticesThe vertices to texture (expressed in image space)
Returns
a new polygon node with the given vertices.

◆ allocWithTexture() [1/4]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithTexture ( const std::shared_ptr< Texture > &  texture)
inlinestatic

Returns a new polygon node from a Texture object.

After creation, the polygon will be a rectangle. The vertices of this polygon will be the corners of the image. The rectangle will be triangulated with the standard two triangles.

Parameters
textureA shared pointer to a Texture object.
Returns
a new polygon node from a Texture object.

◆ allocWithTexture() [2/4]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithTexture ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly 
)
inlinestatic

Returns a new polygon node from a Texture object and the given polygon.

The polygon will define the portion of the of the texture shown (in image space).

Parameters
textureA shared pointer to a Texture object.
polyThe polygon to texture
Returns
a new polygon node from a Texture object and the given polygon.

◆ allocWithTexture() [3/4]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithTexture ( const std::shared_ptr< Texture > &  texture,
const Rect  rect 
)
inlinestatic

Returns a new polygon node from a Texture object and the given rect.

The vertices of the rectangle will define the portion of the texture shown (in image space). The rectangle will be triangulated with the standard two triangles.

Parameters
textureA shared pointer to a Texture object.
rectThe rectangle to texture
Returns
a new polygon node from a Texture object and the given rect.

◆ allocWithTexture() [4/4]

static std::shared_ptr<PolygonNode> cugl::scene2::PolygonNode::allocWithTexture ( const std::shared_ptr< Texture > &  texture,
const std::vector< Vec2 > &  vertices 
)
inlinestatic

Returns a new polygon node from a Texture object and the given vertices.

The vertices will define the portion of the of the texture shown (in image space). The vertices will be triangulated with EarclipTriangulator.

Parameters
textureA shared pointer to a Texture object.
verticesThe vertices to texture (expressed in image space)
Returns
a new polygon node from a Texture object and the given vertices.

◆ copy()

virtual std::shared_ptr<SceneNode> cugl::scene2::PolygonNode::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.

Reimplemented in cugl::scene2::SpriteNode.

◆ draw()

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

Draws this polygon 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::PolygonNode::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.

◆ getFringe()

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

Returns the antialiasing fringe for this polygon node

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

Creating a fringe does introduce significant overhead (tenths of a millisecond). The algorithm must detriangulate the polygon to find the borders and then extrude those borders. 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

◆ getPolygon()

const Poly2& cugl::scene2::PolygonNode::getPolygon ( ) const
inline

Returns the texture polygon for this scene graph node

Returns
the texture polygon for this scene graph node

◆ initWithData()

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

Initializes a polygon 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:

 "polygon":  A JSON object defining a polygon. See {@link Poly2}.
 "fringe":   A number indicating the size of the border fringe.

All attributes are optional. If the polygon 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.

Reimplemented in cugl::scene2::SpriteNode.

◆ initWithFile()

virtual bool cugl::scene2::PolygonNode::initWithFile ( const std::string &  filename)
overridevirtual

Intializes a polygon node from the image filename.

After creation, the polygon will be a rectangle. The vertices of this polygon will be the corners of the image. The rectangle will be triangulated with the standard two triangles.

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

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithFilePoly() [1/3]

bool cugl::scene2::PolygonNode::initWithFilePoly ( const std::string &  filename,
const Poly2 poly 
)
inline

Initializes a polygon node from the image filename and the given polygon.

The polygon will define the portion of the of the texture shown (in image space).

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

◆ initWithFilePoly() [2/3]

bool cugl::scene2::PolygonNode::initWithFilePoly ( const std::string &  filename,
const Rect  rect 
)
inline

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

The vertices of the rectangle will define the portion of the texture shown (in image space). The rectangle will be triangulated with the standard two triangles.

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

◆ initWithFilePoly() [3/3]

bool cugl::scene2::PolygonNode::initWithFilePoly ( const std::string &  filename,
const std::vector< Vec2 > &  vertices 
)
inline

Initializes a polygon node from the image filename and the given vertices.

The vertices will define the portion of the of the texture shown (in image space). The vertices will be triangulated with EarclipTriangulator.

Parameters
filenameA path to image file, e.g., "scene1/earthtile.png"
verticesThe vertices to texture (expressed in image space)
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithPoly() [1/3]

bool cugl::scene2::PolygonNode::initWithPoly ( const Poly2 poly)
inline

Intializes a polygon node given polygon shape.

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

Parameters
polyThe polygon to texture
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithPoly() [2/3]

bool cugl::scene2::PolygonNode::initWithPoly ( const Rect  rect)
inline

Intializes a polygon node with the given rect.

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

The rectangle will be triangulated with the standard two triangles.

Parameters
rectThe rectangle to texture
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithPoly() [3/3]

bool cugl::scene2::PolygonNode::initWithPoly ( const std::vector< Vec2 > &  vertices)
inline

Intializes a polygon node with the given vertices.

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

The vertices will be triangulated with EarclipTriangulator.

Parameters
verticesThe vertices to texture (expressed in image space)
Returns
true if the sprite is initialized properly, false otherwise.

◆ initWithTexture()

virtual bool cugl::scene2::PolygonNode::initWithTexture ( const std::shared_ptr< Texture > &  texture)
overridevirtual

Initializes a polygon node from a Texture object.

After creation, the polygon will be a rectangle. The vertices of this polygon will be the corners of the image. The rectangle will be triangulated with the standard two triangles.

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

Reimplemented from cugl::scene2::TexturedNode.

◆ initWithTexturePoly() [1/3]

bool cugl::scene2::PolygonNode::initWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Poly2 poly 
)
inline

Initializes a polygon node from a Texture object and the given polygon.

The polygon will define the portion of the of the texture shown (in image space).

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

◆ initWithTexturePoly() [2/3]

bool cugl::scene2::PolygonNode::initWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const Rect  rect 
)
inline

Initializes a polygon node from a Texture object and the given rect.

The vertices of the rectangle will define the portion of the texture shown (in image space). The rectangle will be triangulated with the standard two triangles.

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

◆ initWithTexturePoly() [3/3]

bool cugl::scene2::PolygonNode::initWithTexturePoly ( const std::shared_ptr< Texture > &  texture,
const std::vector< Vec2 > &  vertices 
)
inline

Initializes a polygon node from a Texture object and the given vertices.

The vertices will define the portion of the of the texture shown (in image space). The vertices will be triangulated with EarclipTriangulator.

Parameters
textureA shared pointer to a Texture object.
verticesThe vertices to texture (expressed in image space)
Returns
true if the sprite is initialized properly, false otherwise.

◆ setFringe()

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

Sets the antialiasing fringe for this polygon node

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

Creating a fringe does introduce significant overhead (tenths of a millisecond). The algorithm must detriangulate the polygon to find the borders and then extrude those borders. 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

◆ setPolygon() [1/3]

virtual void cugl::scene2::PolygonNode::setPolygon ( const Poly2 poly)
virtual

Sets the polygon to the given one in texture space.

Parameters
polyThe polygon to texture

◆ setPolygon() [2/3]

virtual void cugl::scene2::PolygonNode::setPolygon ( const Rect  rect)
virtual

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

The rectangle will be triangulated with the standard two triangles.

Parameters
rectThe rectangle to texture

◆ setPolygon() [3/3]

virtual void cugl::scene2::PolygonNode::setPolygon ( const std::vector< Vec2 > &  vertices)
virtual

Sets the polgon to the vertices expressed in texture space.

The vertices will be triangulated with EarclipTriangulator.

Parameters
verticesThe vertices to texture

Member Data Documentation

◆ _fringe

float cugl::scene2::PolygonNode::_fringe
protected

The border fringe for the mesh

◆ _polygon

Poly2 cugl::scene2::PolygonNode::_polygon
protected

The underlying polygon


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