Cornell Cocos
Cornell Extensions to Cocos2d
Public Member Functions | Static Public Member Functions | Public Attributes | Protected Member Functions | List of all members
WireNode Class Reference

#include <CUWireNode.h>

Inheritance diagram for WireNode:
TexturedNode

Public Member Functions

virtual std::string getDescription () const override
 
virtual void draw (Renderer *renderer, const Mat4 &transform, uint32_t flags) override
 
virtual ~WireNode (void)
 
- Public Member Functions inherited from TexturedNode
virtual void setTexture (const std::string &filename)
 
virtual void setTexture (Texture2D *texture) override
 
virtual Texture2D * getTexture () const override
 
virtual void setPolygon (float *vertices, int size, int offset=0)
 
virtual void setPolygon (const Poly2 &poly)
 
virtual void setPolygon (const Rect &rect)
 
const Poly2getPolygon () const
 
virtual void shiftPolygon (float dx, float dy)
 
const Rect & getBoundingRect () const
 
void setBlendFunc (const BlendFunc &blendFunc) override
 
const BlendFunc & getBlendFunc () const override
 
virtual void setOpacityModifyRGB (bool modify) override
 
virtual bool isOpacityModifyRGB (void) const override
 
void flipHorizontal (bool flag)
 
bool isFlipHorizontal () const
 
void flipVertical (bool flag)
 
bool isFlipVertical () const
 
virtual ~TexturedNode (void)
 
virtual bool init () override
 
virtual bool init (float *vertices, int size, int offset=0)
 
virtual bool init (const Poly2 &poly)
 
virtual bool init (const Rect &rect)
 
virtual bool initWithFile (const std::string &filename)
 
virtual bool initWithFile (const std::string &filename, float *vertices, int size, int offset=0)
 
virtual bool initWithFile (const std::string &filename, const Poly2 &poly)
 
virtual bool initWithFile (const std::string &filename, const Rect &rect)
 
virtual bool initWithTexture (Texture2D *texture)
 
virtual bool initWithTexture (Texture2D *texture, float *vertices, int size, int offset=0)
 
virtual bool initWithTexture (Texture2D *texture, const Poly2 &poly)
 
virtual bool initWithTexture (Texture2D *texture, const Rect &rect)
 

Static Public Member Functions

static WireNodecreate ()
 
static WireNodecreateWithVertices (float *vertices, int size, int offset=0)
 
static WireNodecreateWithPoly (const Poly2 &poly)
 
static WireNodecreateWithRect (const Rect &rect)
 
static WireNodecreateWithLine (const Vec2 &origin, const Vec2 &dest)
 
static WireNodecreateWithEllipse (const Vec2 &center, const Size &size, unsigned int segments)
 

Public Attributes

CC_CONSTRUCTOR_ACCESS __pad0__: WireNode()
 
- Public Attributes inherited from TexturedNode
CC_CONSTRUCTOR_ACCESS __pad0__: TexturedNode(void)
 

Protected Member Functions

void generateRenderData () override
 
- Protected Member Functions inherited from TexturedNode
TrianglesCommand::Triangles & allocTriangles (const Poly2 &poly)
 
void clearRenderData ()
 
void updateColor () override
 
void updateBlendFunc ()
 
void updateTextureCoords ()
 

Additional Inherited Members

- Protected Attributes inherited from TexturedNode
Texture2D * _texture
 
Poly2 _polygon
 
BlendFunc _blendFunc
 
bool _insideBounds
 
bool _opacityModifyRGB
 
TrianglesCommand _command
 
TrianglesCommand::Triangles _triangles
 
bool _flipHorizontal
 
bool _flipVertical
 

Detailed Description

Scene graph node to represent a wireframe

This class uses the Cocos2D rendering pipeline to batch all of the lines for a wireframe into a single mesh with one drawing call, improving performance.

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 Poly2.

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

Constructor & Destructor Documentation

virtual WireNode::~WireNode ( void  )
inlinevirtual

Releases all resources allocated with this sprite.

After this is called, the polygon and drawing commands will be deleted and no longer safe to use.

Member Function Documentation

NS_CC_BEGIN WireNode * WireNode::create ( )
static

Creates an empty wireframe node.

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

Returns
An autoreleased wireframe node
WireNode * WireNode::createWithEllipse ( const Vec2 &  center,
const Size &  size,
unsigned int  segments 
)
static

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
WireNode * WireNode::createWithLine ( const Vec2 &  origin,
const Vec2 &  dest 
)
static

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

Parameters
originThe line origin.
destThe line destination.
Returns
An autoreleased wireframe node
WireNode * WireNode::createWithPoly ( const Poly2 poly)
static

Creates 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, call the traverse() method in Poly2 before assigning it to this Wireframe.

Parameters
polyThe polygon for the wireframe path
Returns
An autoreleased wireframe node

Creates a wireframe with the given polygon.

The wireframe is determined by the polygon traversal. There are three options.

The wireframe is a sequence of lines that is determined by the polygon indices. To create a specific traversal, call the traverse() method in Poly2 before assigning it to this Wireframe.

Parameters
polyThe polygon for the wireframe path
Returns
An autoreleased wireframe node
WireNode * WireNode::createWithRect ( const Rect &  rect)
static

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
WireNode * WireNode::createWithVertices ( float *  vertices,
int  size,
int  offset = 0 
)
static

Creates a wireframe with the given vertices.

The traversal path will be open. To create a different traversal, use the createWithPoly() method.

Parameters
verticesThe vertices forming the wireframe path
sizeThe number of elements in vertices
offsetThe offset in vertices
Returns
An autoreleased wireframe node
void WireNode::draw ( Renderer *  renderer,
const Mat4 &  transform,
uint32_t  flags 
)
overridevirtual

Sends drawing commands to the renderer

This method is overridden from Node, to provide the custom commands. Wireframes are drawn to the Wireframe mesh (which is different from the Triangle mesh used for solid shapes) to cut down on the number of drawing calls.

Parameters
rendererReference to the render thread
transformThe accumulated transform from the parent
flagsSpecialized Cocos2d drawing flags
void WireNode::generateRenderData ( )
overrideprotectedvirtual

Allocate the render data necessary to render this node.

The render data for this node is a wireframe for the given traversal.

Reimplemented from TexturedNode.

std::string WireNode::getDescription ( ) const
overridevirtual

Returns a string description of this object

This method is useful for debugging.

Returns
a string description of this object

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