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

#include <CUWireNode.h>

Inheritance diagram for cugl::WireNode:
cugl::TexturedNode cugl::Node

Public Member Functions

 WireNode ()
 
 ~WireNode ()
 
bool initWithVertices (const std::vector< Vec2 > &vertices, PathTraversal traversal)
 
bool initWithLine (const Vec2 &origin, const Vec2 &dest)
 
bool initWithEllipse (const Vec2 &center, const Size &size, unsigned int segments=WIRE_SEGMENTS)
 
bool initWithData (const SceneLoader *loader, const std::shared_ptr< JsonValue > &data) override
 
void setTraversal (PathTraversal traversal)
 
PathTraversal getTraversal () const
 
virtual void setPolygon (const std::vector< Vec2 > &vertices) override
 
void setPolygon (const std::vector< Vec2 > &vertices, PathTraversal traversal)
 
virtual void setPolygon (const Poly2 &poly) override
 
virtual void setPolygon (const Rect &rect) override
 
void setLine (const Vec2 &origin, const Vec2 &dest)
 
void setEllipse (const Vec2 &center, const Size &size, unsigned int segments=WIRE_SEGMENTS)
 
virtual void draw (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &transform, Color4 tint) override
 
- Public Member Functions inherited from cugl::TexturedNode
 TexturedNode ()
 
 ~TexturedNode ()
 
virtual void dispose () override
 
virtual bool init () override
 
bool init (const std::vector< Vec2 > &vertices)
 
bool init (const Poly2 &poly)
 
bool init (const Rect &rect)
 
bool initWithFile (const std::string &filename)
 
bool initWithFile (const std::string &filename, const std::vector< Vec2 > &vertices)
 
bool initWithFile (const std::string &filename, const Poly2 &poly)
 
bool initWithFile (const std::string &filename, const Rect &rect)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const std::vector< Vec2 > &vertices)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const Poly2 &poly)
 
bool initWithTexture (const std::shared_ptr< Texture > &texture, const Rect &rect)
 
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 Poly2getPolygon () const
 
virtual void shiftPolygon (float dx, float dy)
 
const RectgetBoundingRect () const
 
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 setContentSize (const Size &size) override
 
virtual void setContentSize (float width, float height) override
 
void refresh ()
 
- Public Member Functions inherited from cugl::Node
 Node ()
 
 ~Node ()
 
virtual bool initWithPosition (const Vec2 &pos)
 
bool initWithPosition (float x, float y)
 
virtual bool initWithBounds (const Size &size)
 
bool initWithBounds (float width, float height)
 
virtual bool initWithBounds (const Rect &rect)
 
bool initWithBounds (float x, float y, float width, float height)
 
virtual Nodecopy (Node *dst)
 
unsigned int getTag () const
 
void setTag (unsigned int tag)
 
const std::string & getName () const
 
void setName (const std::string &name)
 
 operator std::string () const
 
const Vec2getPosition () 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 SizegetContentSize () const
 
float getContentWidth () const
 
void setContentWidth (float width)
 
float getContentHeight () const
 
void setContentHeight (float height)
 
Size getSize () const
 
float getWidth () const
 
float getHeight () const
 
Rect getBoundingBox () const
 
void setAnchor (float x, float y)
 
const Vec2getAnchor () const
 
Vec2 getAnchorInPixels ()
 
Color4 getColor () const
 
virtual void setColor (Color4 color)
 
Color4 getAbsoluteColor ()
 
bool isVisible () const
 
void setVisible (bool visible)
 
bool hasRelativeColor ()
 
void setRelativeColor (bool flag)
 
const Vec2getScale () 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 Mat4getAlternateTransform ()
 
void setAlternateTransform (const Mat4 &transform)
 
bool withAlternateTransform ()
 
void chooseAlternateTransform (bool active)
 
const Mat4getNodeToParentTransform () const
 
Mat4 getParentToNodeTransform () const
 
Mat4 getNodeToWorldTransform () const
 
Mat4 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
 
void setZOrder (int z)
 
int getZOrder () const
 
bool isZDirty () const
 
void sortZOrder ()
 
size_t getChildCount () const
 
std::shared_ptr< NodegetChild (unsigned int pos)
 
const std::shared_ptr< Node > & getChild (unsigned int pos) const
 
template<typename T >
std::shared_ptr< T > getChild (unsigned int pos) const
 
std::shared_ptr< NodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< T > getChildByTag (unsigned int tag) const
 
std::shared_ptr< NodegetChildByName (const std::string &name) const
 
template<typename T >
std::shared_ptr< T > getChildByName (const std::string &name) const
 
std::vector< std::shared_ptr< Node > > getChildren ()
 
const std::vector< std::shared_ptr< Node > > & getChildren () const
 
void addChild (std::shared_ptr< Node > child)
 
virtual void addChild (const std::shared_ptr< Node > &child, int zval)
 
void addChildWithTag (const std::shared_ptr< Node > &child, unsigned int tag)
 
void addChildWithTag (const std::shared_ptr< Node > &child, unsigned int tag, int zval)
 
void addChildWithName (const std::shared_ptr< Node > &child, const std::string &name)
 
void addChildWithName (const std::shared_ptr< Node > &child, const std::string &name, int zval)
 
void swapChild (const std::shared_ptr< Node > &child1, const std::shared_ptr< Node > &child2, bool inherit=false)
 
NodegetParent ()
 
const NodegetParent () const
 
ScenegetScene ()
 
const ScenegetScene () const
 
void removeFromParent ()
 
virtual void removeChild (unsigned int pos)
 
void removeChild (const std::shared_ptr< Node > &child)
 
void removeChildByTag (unsigned int tag)
 
void removeChildByName (const std::string &name)
 
virtual void removeAllChildren ()
 
virtual void render (const std::shared_ptr< SpriteBatch > &batch, const Mat4 &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< WireNodealloc ()
 
static std::shared_ptr< WireNodeallocWithVertices (const std::vector< Vec2 > &vertices)
 
static std::shared_ptr< WireNodeallocWithVertices (const std::vector< Vec2 > &vertices, PathTraversal traversal)
 
static std::shared_ptr< WireNodeallocWithPoly (const Poly2 &poly)
 
static std::shared_ptr< WireNodeallocWithRect (const Rect &rect)
 
static std::shared_ptr< WireNodeallocWithLine (const Vec2 &origin, const Vec2 &dest)
 
static std::shared_ptr< WireNodeallocWithEllipse (const Vec2 &center, const Size &size, unsigned int segments=WIRE_SEGMENTS)
 
static std::shared_ptr< NodeallocWithData (const SceneLoader *loader, const std::shared_ptr< JsonValue > &data)
 
- Static Public Member Functions inherited from cugl::Node
static std::shared_ptr< Nodealloc ()
 
static std::shared_ptr< NodeallocWithPosition (const Vec2 &pos)
 
static std::shared_ptr< NodeallocWithPosition (float x, float y)
 
static std::shared_ptr< NodeallocWithBounds (const Size &size)
 
static std::shared_ptr< NodeallocWithBounds (float width, float height)
 
static std::shared_ptr< NodeallocWithBounds (const Rect &rect)
 
static std::shared_ptr< NodeallocWithBounds (float x, float y, float width, float height)
 
static std::shared_ptr< NodeallocWithData (const SceneLoader *loader, const std::shared_ptr< JsonValue > &data)
 

Protected Attributes

PathTraversal _traversal
 
- Protected Attributes inherited from cugl::TexturedNode
std::string _classname
 
std::shared_ptr< Texture_texture
 
Poly2 _polygon
 
bool _absolute
 
bool _stretch
 
bool _rendered
 
std::vector< Vertex2_vertices
 
GLenum _blendEquation
 
GLenum _srcFactor
 
GLenum _dstFactor
 
bool _flipHorizontal
 
bool _flipVertical
 
- Protected Attributes inherited from cugl::Node
Vec2 _position
 
Vec2 _anchor
 
Size _contentSize
 
Color4 _tintColor
 
bool _hasParentColor
 
bool _isVisible
 
Vec2 _scale
 
float _angle
 
Mat4 _transform
 
bool _useTransform
 
Mat4 _combined
 
std::vector< std::shared_ptr< Node > > _children
 
Node_parent
 
Scene_graph
 
std::shared_ptr< Layout_layout
 
int _childOffset
 
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
int _zOrder
 
bool _zDirty
 

Static Protected Attributes

static PathOutliner _outliner
 

Additional Inherited Members

- Protected Member Functions inherited from cugl::TexturedNode
virtual void generateRenderData ()
 
void clearRenderData ()
 
void updateTextureCoords ()
 
 CU_DISALLOW_COPY_AND_ASSIGN (TexturedNode)
 

Detailed Description

This is a scene graph node to represent a wireframe

The wireframes are lines, but they can still be textured. However, generally you will only want to create a wireframe with the degenerate texture (to draw a solid, colored line). Hence, none of the static constructors take a texture. You are free to update the texture after creation, if you wish.

The node shape is stored as polygon. The wireframe shape is determined by the polygon traversal. There are three options, defined in PathOutliner.

OPEN:     The traversal is in order, but does not close the ends.

CLOSED:   The traversal is in order, and closes the ends.

INTERIOR: The traverse will outline the default triangulation.

The default is traversal is CLOSED.

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 to 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 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. Do 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

◆ WireNode()

cugl::WireNode::WireNode ( )
inline

Creates an empty wireframe with the degenerate texture.

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

◆ ~WireNode()

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

Returns an empty wireframe node.

The underlying polygon is empty, and must be set via setPolygon.

Returns
an empty wireframe node.

◆ allocWithData()

static std::shared_ptr<Node> cugl::WireNode::allocWithData ( const SceneLoader loader,
const std::shared_ptr< JsonValue > &  data 
)
inlinestatic

Returns a newly allocated node with the given JSON specificaton.

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

 "texture":  The name of a previously loaded texture asset
 "polygon":  An even array of polygon vertices (numbers)
 "traveral": One of 'open', 'closed', or 'interior'
 "indices":  An array of unsigned ints defining triangles from the
             the vertices. The array size should be a multiple of 3.

All attributes are optional. However, it is generally a good idea to specify EITHER the texture or the polygon. If you specify the indices, then the traversal will be ignored.

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

◆ allocWithEllipse()

static std::shared_ptr<WireNode> cugl::WireNode::allocWithEllipse ( const Vec2 center,
const Size size,
unsigned int  segments = WIRE_SEGMENTS 
)
inlinestatic

Creates a wireframe that is an ellipse with given the center and dimensions.

The wireframe will show the boundary, not the circle tesselation.

Parameters
centerThe ellipse center point.
sizeThe size of the ellipse.
segmentsThe number of segments to use.
Returns
An autoreleased wireframe node

◆ allocWithLine()

static std::shared_ptr<WireNode> cugl::WireNode::allocWithLine ( const Vec2 origin,
const Vec2 dest 
)
inlinestatic

Creates a wireframe that is a line from origin to destination.

Parameters
originThe line origin.
destThe line destination.
Returns
An autoreleased wireframe node

◆ allocWithPoly()

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

Returns a wireframe with the given polygon.

The wireframe is a sequence of lines that is determined by the polygon indices. To create a specific traversal, use the PathOutliner factory.

Parameters
polyThe polygon for the wireframe path
Returns
a wireframe with the given polygon.

◆ allocWithRect()

static std::shared_ptr<WireNode> cugl::WireNode::allocWithRect ( const Rect rect)
inlinestatic

Creates a wireframe with the given rect.

The rectangle will be converted into a Poly2, and the traversal is closed.

Parameters
rectThe rectangle for the wireframe path
Returns
An autoreleased wireframe node

◆ allocWithVertices() [1/2]

static std::shared_ptr<WireNode> cugl::WireNode::allocWithVertices ( const std::vector< Vec2 > &  vertices)
inlinestatic

Returns a (closed) wireframe with the given vertices.

The polygon will be outlined using a CLOSED traversal in PathOutliner. To create a different traversal, use the alternate allocWithVertices() constructor. All WireNode objects share a single path outliner, so this method is not thread safe.

Parameters
verticesThe vertices forming the wireframe path
Returns
a (closed) wireframe with the given vertices.

◆ allocWithVertices() [2/2]

static std::shared_ptr<WireNode> cugl::WireNode::allocWithVertices ( const std::vector< Vec2 > &  vertices,
PathTraversal  traversal 
)
inlinestatic

Returns a (closed) wireframe with the given vertices.

The polygon will be outlined using the given traversal in PathOutliner. WireNode objects share a single path outliner, so this constructor is not thread safe.

Parameters
verticesThe vertices forming the wireframe path
traversalThe path traversal for index generation
Returns
a (closed) wireframe with the given vertices.

◆ draw()

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

Draws this Node via the given SpriteBatch.

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

This is the method that you should override to implement your custom drawing code. You are welcome to use any OpenGL commands that you wish. You can even skip use of the SpriteBatch. However, if you do so, you must flush the SpriteBatch by calling end() at the start of the method. in addition, you should remember to call begin() at the start of the method.

This method provides the correct transformation matrix and tint color. You do not need to worry about whether the node uses relative color. This method is called by render() and these values are guaranteed to be correct. In addition, this method does not need to check for visibility, as it is guaranteed to only be called when the node is visible.

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

Implements cugl::TexturedNode.

◆ getTraversal()

PathTraversal cugl::WireNode::getTraversal ( ) const
inline

Returns the current traversal of this path.

If the traversal is unknown (e.g. it is user-defined), this method returns NONE.

Returns
the current traversal of this path.

◆ initWithData()

bool cugl::WireNode::initWithData ( const SceneLoader loader,
const std::shared_ptr< JsonValue > &  data 
)
overridevirtual

Initializes a node with the given JSON specificaton.

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

 "texture":  The name of a previously loaded texture asset
 "polygon":  An even array of polygon vertices (numbers)
 "traveral": One of 'open', 'closed', or 'interior'
 "indices":  An array of unsigned ints defining triangles from the
             the vertices. The array size should be a multiple of 3.

All attributes are optional. However, it is generally a good idea to specify EITHER the texture or the polygon. If you specify the indices, then the traversal will be ignored.

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

Reimplemented from cugl::TexturedNode.

◆ initWithEllipse()

bool cugl::WireNode::initWithEllipse ( const Vec2 center,
const Size size,
unsigned int  segments = WIRE_SEGMENTS 
)

Initializes a wireframe that is an ellipse with given the center and dimensions.

The wireframe will show the boundary, not the circle tesselation.

Parameters
centerThe ellipse center point.
sizeThe size of the ellipse.
segmentsThe number of segments to use.
Returns
true if the wireframe is initialized properly, false otherwise.

◆ initWithLine()

bool cugl::WireNode::initWithLine ( const Vec2 origin,
const Vec2 dest 
)

Initializes a wireframe that is a line from origin to destination.

Parameters
originThe line origin.
destThe line destination.
Returns
true if the wireframe is initialized properly, false otherwise.

◆ initWithVertices()

bool cugl::WireNode::initWithVertices ( const std::vector< Vec2 > &  vertices,
PathTraversal  traversal 
)

Intializes a solid polygon with the given vertices and traversal

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

The polygon will be outlined using the given traversal in PathOutliner. WireNode objects share a single path outliner, so this initializer is not thread safe.

Parameters
verticesThe vertices to texture (expressed in image space)
traversalThe path traversal for index generation
Returns
true if the wireframe is initialized properly, false otherwise.

◆ setEllipse()

void cugl::WireNode::setEllipse ( const Vec2 center,
const Size size,
unsigned int  segments = WIRE_SEGMENTS 
)

Sets the wireframe polygon to be an ellipse with given the center and dimensions.

The wireframe will show the boundary, not the circle tesselation. The traversal will be closed.

Parameters
centerThe ellipse center point.
sizeThe size of the ellipse.
segmentsThe number of segments to use.

◆ setLine()

void cugl::WireNode::setLine ( const Vec2 origin,
const Vec2 dest 
)

Sets the wireframe polygon to be the line from origin to destination.

The traversal will be OPEN.

Parameters
originThe line origin.
destThe line destination.

◆ setPolygon() [1/4]

virtual void cugl::WireNode::setPolygon ( const Poly2 poly)
overridevirtual

Sets the wireframe polygon to the given one in texture space.

This method confirms that the polygon is a PATH. However, it cannot learn the traversal, so the traveral will be NONE.

Parameters
polyThe polygon to draw

Reimplemented from cugl::TexturedNode.

◆ setPolygon() [2/4]

virtual void cugl::WireNode::setPolygon ( const Rect rect)
overridevirtual

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

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.

Parameters
rectThe rectangle to draw

Implements cugl::TexturedNode.

◆ setPolygon() [3/4]

virtual void cugl::WireNode::setPolygon ( const std::vector< Vec2 > &  vertices)
overridevirtual

Sets the wireframe polgon to the vertices expressed in texture space.

The polygon will be outlined using a CLOSED traversal in PathOutliner. To create a different traversal, use the alternate setPolygon() method. All WireNode objects share a single path outliner, so this method is not thread safe.

Parameters
verticesThe vertices to draw

Implements cugl::TexturedNode.

◆ setPolygon() [4/4]

void cugl::WireNode::setPolygon ( const std::vector< Vec2 > &  vertices,
PathTraversal  traversal 
)

Sets the wireframe polgon to the vertices expressed in texture space.

The polygon will be outlined using the given traversal in PathOutliner. All WireNode objects share a single path outliner, so this method is not thread safe.

Parameters
verticesThe vertices to draw
traversalThe vertex traversal to use

◆ setTraversal()

void cugl::WireNode::setTraversal ( PathTraversal  traversal)

Sets the traversal of this path.

If the traversal is different from the current known traversal, it will recompute the traveral using the PathOutliner. All WireNode objects share a single path outliner, so this method is not thread safe.

Parameters
traversalThe new wireframe traversal

Member Data Documentation

◆ _outliner

PathOutliner cugl::WireNode::_outliner
staticprotected

An outliner for those incomplete polygons

◆ _traversal

PathTraversal cugl::WireNode::_traversal
protected

The current (known) traversal of this wireframe


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