CUGL 3.0
Cornell University Game Library
Loading...
Searching...
No Matches
Public Member Functions | Static Public Member Functions | List of all members
cugl::scene3::BillboardNode Class Reference

#include <CUBillboardNode.h>

Inheritance diagram for cugl::scene3::BillboardNode:
cugl::scene3::SceneNode

Public Member Functions

 BillboardNode ()
 
 ~BillboardNode ()
 
virtual void dispose () override
 
bool initWithSpriteMesh (const std::shared_ptr< graphics::SpriteMesh > &mesh)
 
bool initWithData (const AssetManager *manager, const std::shared_ptr< JsonValue > &json) override
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const override
 
std::shared_ptr< SceneNodeclone () const
 
std::shared_ptr< graphics::SpriteMeshgetSpriteMesh () const
 
void setSpriteMesh (const std::shared_ptr< graphics::SpriteMesh > &mesh)
 
std::shared_ptr< graphics::TexturegetTexture () const
 
void setTexture (const std::shared_ptr< graphics::Texture > &value)
 
std::shared_ptr< graphics::GradientgetGradient () const
 
void setGradient (const std::shared_ptr< graphics::Gradient > &value)
 
void setSpriteSheet (int rows, int cols, int size, int frame=0)
 
void clearSpriteSheet ()
 
int getSpan () const
 
unsigned int getFrame () const
 
void setFrame (int frame)
 
Vec2 getTextureOffset () const
 
- Public Member Functions inherited from cugl::scene3::SceneNode
 SceneNode ()
 
 ~SceneNode ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool initWithPosition (const Vec3 pos)
 
bool initWithPosition (float x, float y, float z)
 
virtual bool initWithAnchor (const Vec3 anchor)
 
bool initWithAnchor (float x, float y, float z)
 
virtual bool initWithAnchor (const Vec3 pos, const Vec3 anchor)
 
virtual bool initWithData (const AssetManager *manager, const std::shared_ptr< JsonValue > &json)
 
virtual std::shared_ptr< SceneNodecopy (const std::shared_ptr< SceneNode > &dst) const
 
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
 
CUEnum getBatchKey () const
 
void setBatchKey (CUEnum key)
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Vec3 getPosition () const
 
void setPosition (const Vec3 position)
 
void setPosition (float x, float y, float z)
 
Vec3 getWorldPosition () const
 
void setAnchor (const Vec3 anchor)
 
void setAnchor (float x, float y, float z)
 
const Vec3 getAnchor () const
 
bool isVisible () const
 
void setVisible (bool visible)
 
cugl::Vec3 getScale () const
 
void setScale (float scale)
 
void setScale (const cugl::Vec3 scale)
 
cugl::Quaternion getRotation () const
 
void setRotation (cugl::Quaternion rot)
 
const Mat4getModelMatrix () const
 
const Mat4getNodeToParentTransform () const
 
Mat4 getParentToNodeTransform () const
 
virtual Mat4 getNodeToWorldTransform () const
 
Mat4 getWorldToNodeTransform () const
 
Vec3 screenToNodeCoords (const Vec2 screenPoint) const
 
Vec3 worldToNodeCoords (const Vec3 worldPoint) const
 
Vec2 nodeToScreenCoords (const Vec3 nodePoint) const
 
Vec3 nodeToWorldCoords (const Vec3 nodePoint) const
 
Vec3 parentToNodeCoords (const Vec3 parentPoint) const
 
Vec3 nodeToParentCoords (const Vec3 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< TgetChild (unsigned int pos) const
 
std::shared_ptr< SceneNodegetChildByTag (unsigned int tag) const
 
template<typename T >
std::shared_ptr< TgetChildByTag (unsigned int tag) const
 
std::shared_ptr< SceneNodegetChildByName (const std::string name) const
 
template<typename T >
std::shared_ptr< TgetChildByName (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
 
Scene3getScene ()
 
const Scene3getScene () 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 ()
 

Static Public Member Functions

static std::shared_ptr< BillboardNodeallocWithSpriteMesh (const std::shared_ptr< graphics::SpriteMesh > &mesh)
 
static std::shared_ptr< BillboardNodeallocWithData (const AssetManager *manager, const std::shared_ptr< JsonValue > &json)
 
- Static Public Member Functions inherited from cugl::scene3::SceneNode
static std::shared_ptr< SceneNodealloc ()
 
static std::shared_ptr< SceneNodeallocWithPosition (const Vec3 pos)
 
static std::shared_ptr< SceneNodeallocWithPosition (float x, float y, float z)
 
static std::shared_ptr< SceneNodeallocWithAnchor (const Vec3 anchor)
 
static std::shared_ptr< SceneNodeallocWithAnchor (float x, float y, float z)
 
static std::shared_ptr< SceneNodeallocWithAnchor (const Vec3 pos, const Vec3 anchor)
 
static std::shared_ptr< SceneNodeallocWithData (const AssetManager *manager, const std::shared_ptr< JsonValue > &json)
 

Additional Inherited Members

- Protected Attributes inherited from cugl::scene3::SceneNode
unsigned int _tag
 
std::string _name
 
size_t _hashOfName
 
std::string _classname
 
bool _isVisible
 
cugl::Vec3 _position
 
cugl::Vec3 _anchor
 
cugl::Vec3 _scale
 
cugl::Quaternion _rotate
 
Mat4 _modelmat
 
std::vector< std::shared_ptr< SceneNode > > _children
 
SceneNode_parent
 
Scene3_graph
 
int _childOffset
 
CUEnum _batchkey
 
std::shared_ptr< JsonValue_json
 

Detailed Description

This class represents an Billboard in a 3d scene graph.

Billboards are designed to project 2d images in 3d space. The image is always shown head on, no matter the angle or perspective. The only thing that can vary is the origin of the billboard, which is a point in 3d space. This origin can be transformed by BillboardShader#setModelMatrix. So it is possible to move the image along all three axes in 3d space.

Billboards support a single static graphics::SpriteMesh. Unlike sprite batches billboards are not designed for compositing, as alpha blending is completely incompatible 3d depth filtering. If you need to billboard a composite image, you should first render it to a single texture with graphics::RenderTarget before putting it in the billboard.

The two features that do carry over from graphics::SpriteBatch are textures and gradients. These are both optional. A mesh with neither texture nor gradient is rendered as a solid color. Because billboards do not handle alpha blending (and hence transparency) very well, it is best to make sure that the mesh fits the texture as close as possible, rather than making the mesh a default quad.

Billboards can be animated in the same way that a graphics::ParticleSystem can. A call to BillboardShader#setTextureOffset will offset all of the texture coordinates in the mesh by the given amount. This node has an interface similar to that of scene2::SpriteNode to aid in the calculation of this offset. In particular, you can take a texture and break it into a sprite sheet of equal-sized frames.

Constructor & Destructor Documentation

◆ BillboardNode()

cugl::scene3::BillboardNode::BillboardNode ( )

Creates an uninitialized node.

You must initialize this model before use.

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

◆ ~BillboardNode()

cugl::scene3::BillboardNode::~BillboardNode ( )
inline

Deletes this node, disposing all resources

Member Function Documentation

◆ allocWithData()

static std::shared_ptr< BillboardNode > cugl::scene3::BillboardNode::allocWithData ( const AssetManager manager,
const std::shared_ptr< JsonValue > &  json 
)
inlinestatic

Returns a newly allocated node with the given JSON specification.

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

 "mesh":     A string with the name of a previously loaded sprite mesh asset
 "texture":  A string with the name of a previously loaded texture asset
 "gradient": A JSON object defining a gradient. See {@link Gradient}.
 "span":     The number of frames in the texture sprite sheet
 "rows":     An int specifying the number of rows in the sprite sheet
 "cols":     An int specifying the number of columns in the sprite sheet
 "frame":    The initial starting frame.

All attributes are optional. However, not specifying the mesh means that nothing is drawn.

Parameters
managerThe asset manager handling this asset
jsonThe JSON object specifying the node
Returns
a newly allocated node with the given JSON specification.

◆ allocWithSpriteMesh()

static std::shared_ptr< BillboardNode > cugl::scene3::BillboardNode::allocWithSpriteMesh ( const std::shared_ptr< graphics::SpriteMesh > &  mesh)
inlinestatic

Returns a newly allocated node with the given sprite mesh

This node will keep a reference to sprite mesh, but it will have its own position, orientation, texture, and gradient. Therefore it is possible for multiple nodes to share the same sprite mesh.

The billboard will assume that the sprite mesh is to represent a static image. Therefore, there is only one animation frame in the texture (e.g. rows and cols are 1).

Parameters
meshThe sprite mesh
Returns
a newly allocated node with the given sprite mesh

◆ clearSpriteSheet()

void cugl::scene3::BillboardNode::clearSpriteSheet ( )

Removes all animation information, setting the billboard to a static image

◆ clone()

std::shared_ptr< SceneNode > cugl::scene3::BillboardNode::clone ( ) const

Returns a shallow copy of this node.

The nodes will initially share the same sprite mesh, texture, and gradient. However, the position and orientation are copied by value.

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

Returns
a shallow copy of this node.

◆ copy()

virtual std::shared_ptr< SceneNode > cugl::scene3::BillboardNode::copy ( const std::shared_ptr< SceneNode > &  dst) const
overridevirtual

Performs a shallow copy of this node into dst.

The nodes will initially share the same sprite mesh, texture, and gradient. However, the position and orientation are copied by value.

No children from this model are copied, and no children of dst are modified. In addition, the parents of both node 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::scene3::SceneNode.

◆ dispose()

virtual void cugl::scene3::BillboardNode::dispose ( )
overridevirtual

Disposes all of the resources used by this node.

A disposed node can be safely reinitialized. Any children owned by this node will be released. They will be deleted if no other object owns them.

It is unsafe to call this on a node that is still currently inside of a scene graph.

Reimplemented from cugl::scene3::SceneNode.

◆ getFrame()

unsigned int cugl::scene3::BillboardNode::getFrame ( ) const
inline

Returns the current active frame.

Returns
the current active frame.

◆ getGradient()

std::shared_ptr< graphics::Gradient > cugl::scene3::BillboardNode::getGradient ( ) const
inline

Returns the gradient associated with this billboard.

If this value is nullptr, the no gradient will be applied.

Returns
the gradient associated with this billboard.

◆ getSpan()

int cugl::scene3::BillboardNode::getSpan ( ) const
inline

Returns the number of frames in the texture sprite sheet

Returns
the number of frames in the texture sprite sheet

◆ getSpriteMesh()

std::shared_ptr< graphics::SpriteMesh > cugl::scene3::BillboardNode::getSpriteMesh ( ) const
inline

Returns the sprite mesh associated with this node.

If this value is nullptr, nothing will be drawn for this node.

Returns
the sprite mesh associated with this node.

◆ getTexture()

std::shared_ptr< graphics::Texture > cugl::scene3::BillboardNode::getTexture ( ) const
inline

Returns the texture associated with this billboard.

If this value is nullptr, the mesh will be rendered as a single color.

Returns
the texture associated with this billboard.

◆ getTextureOffset()

Vec2 cugl::scene3::BillboardNode::getTextureOffset ( ) const
inline

Returns the texture offset for the given frame.

Returns
the texture offset for the given frame.

◆ initWithData()

bool cugl::scene3::BillboardNode::initWithData ( const AssetManager manager,
const std::shared_ptr< JsonValue > &  json 
)
overridevirtual

Initializes a node with the given JSON specification.

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

 "mesh":     A string with the name of a previously loaded sprite mesh asset
 "texture":  A string with the name of a previously loaded texture asset
 "gradient": A JSON object defining a gradient. See {@link Gradient}.
 "span":     The number of frames in the texture sprite sheet
 "rows":     An int specifying the number of rows in the sprite sheet
 "cols":     An int specifying the number of columns in the sprite sheet
 "frame":    The initial starting frame.

All attributes are optional. However, not specifying the mesh means that nothing is drawn.

Parameters
managerThe asset manager handling this asset
jsonThe JSON object specifying the node
Returns
true if initialization was successful.

Reimplemented from cugl::scene3::SceneNode.

◆ initWithSpriteMesh()

bool cugl::scene3::BillboardNode::initWithSpriteMesh ( const std::shared_ptr< graphics::SpriteMesh > &  mesh)

Initializes this node with the given sprite mesh

This node will keep a reference to sprite mesh, but it will have its own position, orientation, texture, and gradient. Therefore it is possible for multiple nodes to share the same sprite mesh.

The billboard will assume that the sprite mesh is to represent a static image. Therefore, there is only one animation frame in the texture (e.g. rows and cols are 1).

Parameters
meshThe sprite mesh
Returns
true if initialization was successful.

◆ setFrame()

void cugl::scene3::BillboardNode::setFrame ( int  frame)

Sets the active frame as the given index.

If the frame index is invalid, an error is raised.

Parameters
framethe index to make the active frame

◆ setGradient()

void cugl::scene3::BillboardNode::setGradient ( const std::shared_ptr< graphics::Gradient > &  value)
inline

Sets the gradient associated with this billboard.

If this value is nullptr, the no gradient will be applied.

Parameters
valueThe gradient associated with this billboard.

◆ setSpriteMesh()

void cugl::scene3::BillboardNode::setSpriteMesh ( const std::shared_ptr< graphics::SpriteMesh > &  mesh)
inline

Sets the sprite mesh associated with this node.

If this value is nullptr, nothing will be drawn for this node.

Parameters
meshThe sprite mesh associated with this node.

◆ setSpriteSheet()

void cugl::scene3::BillboardNode::setSpriteSheet ( int  rows,
int  cols,
int  size,
int  frame = 0 
)

Sets the sprite dimensions of the associated texture

This method is used to divide the texture up into a sprite sheet for animation. If it size is set to a value > 1, then calls to setFrame will adjust the current animation frame. This has no effect if the billboard has no texture.

Note that the sprite mesh already has its texture coordinates assigned. The only way to animate the sprite is by applying an offset to the texture coordinates. Therefore, for animation to work correctly, the texture coordinates of the sprite mesh must all fit in a single frame (the initial one). If these texture coordinate fit in a frame other than frame 0, that should be specified.

Parameters
rowsThe number of rows in the sprite sheet
colsThe number of columns in the sprite sheet
sizeThe number of frames in the sprite sheet
frameThe initial frame represented by the sprite sheet

◆ setTexture()

void cugl::scene3::BillboardNode::setTexture ( const std::shared_ptr< graphics::Texture > &  value)
inline

Sets the texture associated with this billboard.

If this value is nullptr, the mesh will be rendered as a single color.

Parameters
valueThe texture associated with this billboard.

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