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

#include <CUSceneNode3.h>

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

Public Member Functions

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

Protected Attributes

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
 

Friends

class Scene3
 

Detailed Description

This class provides a 3d scene graph node.

A base node is a cubic that can contain other (transformed) nodes. Each node forms a its own coordinate space. All rendering takes place inside of this coordinate space. By default, a mode does not render anything. Instead, all drawing is handled via Scene3Pipeline, which traverses the scene graph tree before drawing.

Unlike the 2d scene graph nodes, we do not associate a bounding box (or volume with the node). While that is important for UI layout code, it is less important for 3d scene graphs. However, we do still have the concept of the anchor. All transforms (scaling and rotation) are applied relative to the anchor, not the node origin. But because there is no bounding box, this anchor is specified as a point in node space, and not a percentage.

Constructor & Destructor Documentation

◆ SceneNode()

cugl::scene3::SceneNode::SceneNode ( )

Creates an uninitialized node.

You must initialize this node before use.

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

◆ ~SceneNode()

cugl::scene3::SceneNode::~SceneNode ( )
inline

Deletes this node, disposing all resources

Member Function Documentation

◆ addChild()

void cugl::scene3::SceneNode::addChild ( const std::shared_ptr< SceneNode > &  child)

Adds a child to this node.

Children are enumerated in the order that they are added. However, it is still best to For example, they may be resorted by their z-order. Hence you should generally attempt to retrieve a child by tag or by name instead.

Parameters
childA child node.

◆ addChildWithName()

void cugl::scene3::SceneNode::addChildWithName ( const std::shared_ptr< SceneNode > &  child,
const std::string  name 
)
inline

Adds a child to this node with the given name.

For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is generally best to retrieve a child using either a tag or a name instead.

Parameters
childA child node.
nameA string to identify the node.

◆ addChildWithTag()

void cugl::scene3::SceneNode::addChildWithTag ( const std::shared_ptr< SceneNode > &  child,
unsigned int  tag 
)
inline

Adds a child to this node with the given tag.

For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is generally best to retrieve a child using either a tag or a name instead.

Parameters
childA child node.
tagAn integer to identify the node easily.

◆ alloc()

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::alloc ( )
inlinestatic

Returns a newly allocated node at the world origin.

The node has both position and size (0,0,0).

Returns
a newly allocated node at the world origin.

◆ allocWithAnchor() [1/3]

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithAnchor ( const Vec3  anchor)
inlinestatic

Returns a newly allocated node with the given anchor.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at (0,0,0) in parent space.

Parameters
anchorThe anchor of this node
Returns
a newly allocated node with the given anchor.

◆ allocWithAnchor() [2/3]

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithAnchor ( const Vec3  pos,
const Vec3  anchor 
)
inlinestatic

Returns a newly allocated node with the given anchor and position.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at position pos in parent space.

Parameters
posThe node position
anchorThe node anchor
Returns
a newly allocated node with the given anchor and position.

◆ allocWithAnchor() [3/3]

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithAnchor ( float  x,
float  y,
float  z 
)
inlinestatic

Returns a newly allocated node with the given anchor.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at (0,0,0) in parent space.

Parameters
xThe x-coordinate of the anchor in node space
yThe y-coordinate of the anchor in node space
zThe z-coordinate of the anchor in node space
Returns
a newly allocated node with the given anchor.

◆ allocWithData()

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithData ( const AssetManager manager,
const std::shared_ptr< JsonValue > &  json 
)
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 Scene3Loader. This JSON format supports the following attribute values:

 "position": A three-element number array
 "anchor":   A three-element number array representing the anchor point
 "scale":    Either a three-element number array or a single number
 "rotation": A JSON value representing rotation about an axis
 "visible":  A boolean value, representing if the node is visible

All attributes are optional. There are no required attributes. Everything that is missing is assigned its default value.

The value "rotation" can either be a four-element array or a JSON object. If it is an array, it is interpreted as a quaternion. If it is an object, it supports the following attributes:

 "angle":    A number, representing the rotation in DEGREES, not radians
 "axis":     A three-element number array

Once again, both are optional, though no rotation is applied if the angle is missing. If the axis is missing, rotation is about the z-axis

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

◆ allocWithPosition() [1/2]

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithPosition ( const Vec3  pos)
inlinestatic

Returns a newly allocated node at the given position.

The node has size (0,0,0). As a result, the position is identified with the origin of the node space.

Parameters
posThe origin of the node in parent space
Returns
a newly allocated node at the given position.

◆ allocWithPosition() [2/2]

static std::shared_ptr< SceneNode > cugl::scene3::SceneNode::allocWithPosition ( float  x,
float  y,
float  z 
)
inlinestatic

Returns a newly allocated node at the given position.

The node has size (0,0,0). As a result, the position is identified with the origin of the node space.

Parameters
xThe x-coordinate of the node in parent space
yThe y-coordinate of the node in parent space
zThe z-coordinate of the node in parent space
Returns
a newly allocated node at the given position.

◆ copy()

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

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 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 in cugl::scene3::BillboardNode, cugl::scene3::ObjNode, and cugl::scene3::ParticleNode.

◆ dispose()

virtual void cugl::scene3::SceneNode::dispose ( )
virtual

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 in cugl::scene3::BillboardNode, cugl::scene3::ObjNode, and cugl::scene3::ParticleNode.

◆ getAnchor()

const Vec3 cugl::scene3::SceneNode::getAnchor ( ) const
inline

Returns the anchor point.

The anchor point defines the relative origin of Node with respect to its parent. It is a "pin" where the Node is attached to its parent. In effect, the translation of a Node is defined by its position plus anchor point.

The anchor point is defined as a position in node space. It is the origin by default. Note that changing the anchor will not move the contents of the node in the parent space, but it will change the value of the node position.

Returns
The anchor point.

◆ getBatchKey()

CUEnum cugl::scene3::SceneNode::getBatchKey ( ) const
inline

Returns the batch key for this node type.

Batch keys are uses to identify the correct Scene3Batch to use in Scene3Pipeline. Each batch type has its own key. See Scene3Batch#getBatchKey.

Returns
the batch key for this node type.

◆ getChild() [1/3]

std::shared_ptr< SceneNode > cugl::scene3::SceneNode::getChild ( unsigned int  pos)

Returns the child at the given position.

For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is generally best to retrieve a child using either a tag or a name instead.

Parameters
posThe child position.
Returns
the child at the given position.

◆ getChild() [2/3]

const std::shared_ptr< SceneNode > & cugl::scene3::SceneNode::getChild ( unsigned int  pos) const

Returns the child at the given position.

For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is generally best to retrieve a child using either a tag or a name instead.

Parameters
posThe child position.
Returns
the child at the given position.

◆ getChild() [3/3]

template<typename T >
std::shared_ptr< T > cugl::scene3::SceneNode::getChild ( unsigned int  pos) const
inline

Returns the child at the given position, typecast to a shared T pointer.

This method is provided to simplify the polymorphism of a scene graph. While all children are a subclass of type Node, you may want to access them by their specific subclass. If the child is not an instance of type T (or a subclass), this method returns nullptr.

For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is generally best to retrieve a child using either a tag or a name instead.

Parameters
posThe child position.
Returns
the child at the given position, typecast to a shared T pointer.

◆ getChildByName() [1/2]

std::shared_ptr< SceneNode > cugl::scene3::SceneNode::getChildByName ( const std::string  name) const

Returns the (first) child with the given name.

If there is more than one child of the given name, it returns the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is very important that names be unique.

Parameters
nameAn identifier to find the child node.
Returns
the (first) child with the given name.

◆ getChildByName() [2/2]

template<typename T >
std::shared_ptr< T > cugl::scene3::SceneNode::getChildByName ( const std::string  name) const
inline

Returns the (first) child with the given name, typecast to a shared T pointer.

This method is provided to simplify the polymorphism of a scene graph. While all children are a subclass of type Node, you may want to access them by their specific subclass. If the child is not an instance of type T (or a subclass), this method returns nullptr.

If there is more than one child of the given name, it returns the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is very important that names be unique.

Parameters
nameAn identifier to find the child node.
Returns
the (first) child with the given name, typecast to a shared T pointer.

◆ getChildByTag() [1/2]

std::shared_ptr< SceneNode > cugl::scene3::SceneNode::getChildByTag ( unsigned int  tag) const

Returns the (first) child with the given tag.

If there is more than one child of the given tag, it returns the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is very important that tags be unique.

Parameters
tagAn identifier to find the child node.
Returns
the (first) child with the given tag.

◆ getChildByTag() [2/2]

template<typename T >
std::shared_ptr< T > cugl::scene3::SceneNode::getChildByTag ( unsigned int  tag) const
inline

Returns the (first) child with the given tag, typecast to a shared T pointer.

This method is provided to simplify the polymorphism of a scene graph. While all children are a subclass of type Node, you may want to access them by their specific subclass. If the child is not an instance of type T (or a subclass), this method returns nullptr.

If there is more than one child of the given tag, it returns the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for all subclasses of SceneNode. Hence it is very important that tags be unique.

Parameters
tagAn identifier to find the child node.
Returns
the (first) child with the given tag, typecast to a shared T pointer.

◆ getChildCount()

size_t cugl::scene3::SceneNode::getChildCount ( ) const
inline

Returns the number of children of this node.

Returns
The number of children of this node.

◆ getChildren() [1/2]

std::vector< std::shared_ptr< SceneNode > > cugl::scene3::SceneNode::getChildren ( )
inline

Returns the list of the node's children.

Returns
the list of the node's children.

◆ getChildren() [2/2]

const std::vector< std::shared_ptr< SceneNode > > & cugl::scene3::SceneNode::getChildren ( ) const
inline

Returns the list of the node's children.

Returns
the list of the node's children.

◆ getClassName()

const std::string cugl::scene3::SceneNode::getClassName ( ) const
inline

Returns the class name of this node.

This method is to help us speed up subclass-based polymorphism on the scene graphs.

Returns
the class name of this node.

◆ getModelMatrix()

const Mat4 & cugl::scene3::SceneNode::getModelMatrix ( ) const
inline

Returns the model matrix of this node.

The model matrix defines the transform of this node in parent space.

Returns
the model matrix of this node.

◆ getName()

const std::string cugl::scene3::SceneNode::getName ( ) const
inline

Returns a string that is used to identify the node.

This name is used to access a child node, since child position may change. In addition, the name is useful for debugging. To work properly, a name should be unique within a scene graph. It is empty if undefined.

Returns
a string that is used to identify the node.

◆ getNodeToParentTransform()

const Mat4 & cugl::scene3::SceneNode::getNodeToParentTransform ( ) const
inline

Returns the matrix transforming node space to parent space.

This value is the node's transform. It is computed from the anchor, scale, rotation, and position.

Returns
the matrix transforming node space to parent space.

◆ getNodeToWorldTransform()

virtual Mat4 cugl::scene3::SceneNode::getNodeToWorldTransform ( ) const
virtual

Returns the matrix transforming node space to world space.

This matrix is used to convert node coordinates into OpenGL coordinates. It is the recursive (left-multiplied) node-to-parent transforms of all of its ancestors.

Returns
the matrix transforming node space to world space.

◆ getParent() [1/2]

SceneNode * cugl::scene3::SceneNode::getParent ( )
inline

Returns a (weak) pointer to the parent node.

The purpose of this pointer is to climb back up the scene graph tree. No child asserts ownership of its parent.

Returns
a (weak) pointer to the parent node.

◆ getParent() [2/2]

const SceneNode * cugl::scene3::SceneNode::getParent ( ) const
inline

Returns a (weak) pointer to the parent node.

The purpose of this pointer is to climb back up the scene graph tree. No child asserts ownership of its parent.

Returns
a (weak) pointer to the parent node.

◆ getParentToNodeTransform()

Mat4 cugl::scene3::SceneNode::getParentToNodeTransform ( ) const
inline

Returns the matrix transforming parent space to node space.

This value is the node's transform. It is computed from the anchor, scale, rotation, and position.

Returns
the matrix transforming parent space to node space.

◆ getPosition()

const Vec3 cugl::scene3::SceneNode::getPosition ( ) const
inline

Returns the position of the node in its parent's coordinate system.

The node position is not necessarily the origin of the Node coordinate system. The relationship between the position and Node space is determined by the anchor point. See getAnchor() for more details.

Returns
the position of the node in its parent's coordinate system.

◆ getRotation()

cugl::Quaternion cugl::scene3::SceneNode::getRotation ( ) const
inline

Returns the rotation quaterion of this node about the anchor.

This value rotates the node about the anchor, with the anchor unmoved. Rotations are represented by quaternions, which store both an axis and and angle of rotation (in radians).

Returns
the rotation quaterion of this node about the anchor.

◆ getScale()

cugl::Vec3 cugl::scene3::SceneNode::getScale ( ) const
inline

Returns the non-uniform scaling factor for this node about the anchor.

This factor scales the node about the anchor (with the anchor unmoved). Hence this is not the same as a scale applied to Node space, as the origin may be different. Scaling is first, before any other transforms.

Returns
the non-uniform scaling factor for this node about the anchor

◆ getScene() [1/2]

Scene3 * cugl::scene3::SceneNode::getScene ( )
inline

Returns a (weak) pointer to the scene graph.

The purpose of this pointer is to climb back up to the root of the scene graph tree. No node asserts ownership of its scene.

Returns
a (weak) pointer to the scene graph.

◆ getScene() [2/2]

const Scene3 * cugl::scene3::SceneNode::getScene ( ) const
inline

Returns a (weak) pointer to the scene graph.

The purpose of this pointer is to climb back up to the root of the scene graph tree. No node asserts ownership of its scene.

Returns
a (weak) pointer to the scene graph.

◆ getTag()

unsigned int cugl::scene3::SceneNode::getTag ( ) const
inline

Returns a tag that is used to identify the node easily.

This tag is used to quickly access a child node, since child position may change. To work properly, a tag should be unique within a scene graph. It is 0 if undefined.

Returns
a tag that is used to identify the node easily.

◆ getWorldPosition()

Vec3 cugl::scene3::SceneNode::getWorldPosition ( ) const
inline

Returns the position of the anchor point node in world space.

Note that this is the position of the anchor point. This is not the same as the location of the node origin in world space.

Returns
the position of the anchor point node in world space.

◆ getWorldToNodeTransform()

Mat4 cugl::scene3::SceneNode::getWorldToNodeTransform ( ) const
inline

Returns the matrix transforming node space to world space.

This matrix is used to convert OpenGL coordinates into node coordinates. This method is useful for converting global positions like touches or mouse clicks. It is the recursive (right-multiplied) parent-to-node transforms of all of its ancestors.

Returns
the matrix transforming node space to world space.

◆ init()

virtual bool cugl::scene3::SceneNode::init ( )
inlinevirtual

Initializes a node at the world origin.

The node has both position and anchor (0,0,0).

Returns
true if initialization was successful.

◆ initWithAnchor() [1/3]

virtual bool cugl::scene3::SceneNode::initWithAnchor ( const Vec3  anchor)
inlinevirtual

Initializes a node with the given anchor.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at (0,0,0) in parent space.

Parameters
anchorThe node anchor
Returns
true if initialization was successful.

◆ initWithAnchor() [2/3]

virtual bool cugl::scene3::SceneNode::initWithAnchor ( const Vec3  pos,
const Vec3  anchor 
)
virtual

Initializes a node with the given anchor and position.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at position pos in parent space.

Parameters
posThe node position
anchorThe node anchor
Returns
true if initialization was successful.

◆ initWithAnchor() [3/3]

bool cugl::scene3::SceneNode::initWithAnchor ( float  x,
float  y,
float  z 
)
inline

Initializes a node with the given anchor.

The anchor defines the transformation origin of the scene node. All scaling and rotation happens about the anchor, not the origin. This anchor is placed at (0,0,0) in parent space.

Parameters
xThe x-coordinate of the anchor in node space
yThe y-coordinate of the anchor in node space
zThe z-coordinate of the anchor in node space
Returns
true if initialization was successful.

◆ initWithData()

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

Initializes a node with the given JSON specificaton.

This initializer is designed to receive the "data" object from the JSON passed to Scene3Loader. This JSON format supports the following attribute values:

 "position": A three-element number array
 "anchor":   A three-element number array representing the anchor point
 "scale":    Either a three-element number array or a single number
 "rotation": A JSON value representing rotation about an axis
 "visible":  A boolean value, representing if the node is visible

All attributes are optional. There are no required attributes. Everything that is missing is assigned its default value.

The value "rotation" can either be a four-element array or a JSON object. If it is an array, it is interpreted as a quaternion. If it is an object, it supports the following attributes:

 "angle":    A number, representing the rotation in DEGREES, not radians
 "axis":     A three-element number array

Once again, both are optional, though no rotation is applied if the angle is missing. If the axis is missing, rotation is about the z-axis

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

Reimplemented in cugl::scene3::BillboardNode, cugl::scene3::ObjNode, and cugl::scene3::ParticleNode.

◆ initWithPosition() [1/2]

virtual bool cugl::scene3::SceneNode::initWithPosition ( const Vec3  pos)
virtual

Initializes a node at the given position.

The node has anchor (0,0,0). As a result, the position is identified with the origin of the node space.

Parameters
posThe origin of the node in parent space
Returns
true if initialization was successful.

◆ initWithPosition() [2/2]

bool cugl::scene3::SceneNode::initWithPosition ( float  x,
float  y,
float  z 
)
inline

Initializes a node at the given position.

The node has anchor (0,0,0). As a result, the position is identified with the origin of the node space.

Parameters
xThe x-coordinate of the node in parent space
yThe y-coordinate of the node in parent space
zThe z-coordinate of the node in parent space
Returns
true if initialization was successful.

◆ isVisible()

bool cugl::scene3::SceneNode::isVisible ( ) const
inline

Returns true if the node is visible.

If a node is not visible, then it is not drawn. This means that its children are not visible as well, regardless of their visibility settings. The default value is true, making the node visible.

Returns
true if the node is visible.

◆ nodeToParentCoords()

Vec3 cugl::scene3::SceneNode::nodeToParentCoords ( const Vec3  nodePoint) const
inline

Converts an node (local) space position to parent coordinates.

See getNodeToParentTransform() for how this conversion takes place. That method should be used instead if there are many points to convert, as this method will recompute the transform matrix each time.

Parameters
nodePointA local position.
Returns
A point in parent space coordinates.

◆ nodeToScreenCoords()

Vec2 cugl::scene3::SceneNode::nodeToScreenCoords ( const Vec3  nodePoint) const

Converts an node (local) position to screen coordinates.

This method is useful for converting back to global positions like touches or mouse clicks, which are represented in screen coordinates. Screen coordinates typically have the origin in the top left.

The screen coordinate system is defined by the scene's camera. The method converts the node point into world space, and then uses the camera to convert into screen space.

This method returns the original point if there is no active scene.

Parameters
nodePointA local position.
Returns
A point in screen coordinates.

◆ nodeToWorldCoords()

Vec3 cugl::scene3::SceneNode::nodeToWorldCoords ( const Vec3  nodePoint) const
inline

Converts an node (local) position to OpenGL coordinates.

See getNodeToWorldTransform() for how this conversion takes place. That method should be used instead if there are many points to convert, as this method will recompute the transform matrix each time.

Parameters
nodePointA local position.
Returns
A point in OpenGL coordinates.

◆ operator std::string()

cugl::scene3::SceneNode::operator std::string ( ) const
inline

Cast from a Node to a string.

◆ parentToNodeCoords()

Vec3 cugl::scene3::SceneNode::parentToNodeCoords ( const Vec3  parentPoint) const
inline

Converts an parent space position to node (local) space coordinates.

See getParentToNodeTransform() for how this conversion takes place. That method should be used instead if there are many points to convert, as this method will recompute the transform matrix each time.

Parameters
parentPointA parent position.
Returns
A point in node (local) space coordinates.

◆ removeAllChildren()

virtual void cugl::scene3::SceneNode::removeAllChildren ( )
virtual

Removes all children from this Node.

◆ removeChild() [1/2]

void cugl::scene3::SceneNode::removeChild ( const std::shared_ptr< SceneNode > &  child)

Removes a child from this Node.

Removing a child alters the position of every child after it. Hence it is unsafe to cache child positions.

If the child is not in this node, nothing happens.

Parameters
childThe child node which will be removed.

◆ removeChild() [2/2]

virtual void cugl::scene3::SceneNode::removeChild ( unsigned int  pos)
virtual

Removes the child at the given position from this Node.

Removing a child alters the position of every child after it. Hence it is unsafe to cache child positions.

Parameters
posThe position of the child node which will be removed.

◆ removeChildByName()

void cugl::scene3::SceneNode::removeChildByName ( const std::string  name)

Removes a child from the Node by name.

If there is more than one child of the given name, it removes the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for subclasses of SceneNode. Hence it is very important that names be unique.

Parameters
nameA string to identify the node.

◆ removeChildByTag()

void cugl::scene3::SceneNode::removeChildByTag ( unsigned int  tag)

Removes a child from the Node by tag value.

If there is more than one child of the given tag, it removes the first one that is found. For the base SceneNode class, children are always enumerated in the order that they are added. However, this is not guaranteed for subclasses of SceneNode. Hence it is very important that tags be unique.

Parameters
tagAn integer to identify the node easily.

◆ removeFromParent()

void cugl::scene3::SceneNode::removeFromParent ( )
inline

Removes this node from its parent node.

If the node has no parent, nothing happens.

◆ screenToNodeCoords()

Vec3 cugl::scene3::SceneNode::screenToNodeCoords ( const Vec2  screenPoint) const

Converts a screen position to node (local) space coordinates.

This method is useful for converting global positions like touches or mouse clicks, which are represented in screen coordinates. Screen coordinates typically have the origin in the top left.

The screen coordinate system is defined by the scene's camera. The method uses the camera to convert into world space, and then converts from world space into not (local) space.

This method returns the original point if there is no active scene.

Parameters
screenPointAn position on the screen
Returns
A point in node (local) space coordinates.

◆ setAnchor() [1/2]

void cugl::scene3::SceneNode::setAnchor ( const Vec3  anchor)

Sets the anchor point.

The anchor point defines the relative origin of Node with respect to its parent. It is a "pin" where the Node is attached to its parent. In effect, the translation of a Node is defined by its position plus anchor point.

The anchor point is defined as a position in node space. It is the origin by default. Note that changing the anchor will not move the contents of the node in the parent space, but it will change the value of the node position.

Parameters
anchorThe anchor point of node.

◆ setAnchor() [2/2]

void cugl::scene3::SceneNode::setAnchor ( float  x,
float  y,
float  z 
)

Sets the anchor point.

The anchor point defines the relative origin of Node with respect to its parent. It is a "pin" where the Node is attached to its parent. In effect, the translation of a Node is defined by its position plus anchor point.

The anchor point is defined as a position in node space. It it the origin by default. Note that changing the anchor will not move the contents of the node in the parent space, but it will change the value of the node position.

Parameters
xThe x-coordinate of the anchor.
yThe y-coordinate of the anchor.
zThe z-coordinate of the anchor.

◆ setBatchKey()

void cugl::scene3::SceneNode::setBatchKey ( CUEnum  key)
inline

Sets the batch key for this node type.

Batch keys are uses to identify the correct Scene3Batch to use in Scene3Pipeline. Each batch type has its own key. See Scene3Batch#getBatchKey.

Parameters
keyThe batch key for this node type.

◆ setName()

void cugl::scene3::SceneNode::setName ( const std::string  name)
inline

Sets a string that is used to identify the node.

This name is used to access a child node, since child position may change. In addition, the name is useful for debugging. To work properly, a name should be unique within a scene graph. It is empty if undefined.

Parameters
nameA string that is used to identify the node.

◆ setPosition() [1/2]

void cugl::scene3::SceneNode::setPosition ( const Vec3  position)

Sets the position of the node in its parent's coordinate system.

The node position is not necessarily the origin of the Node coordinate system. The relationship between the position and Node space is determined by the anchor point. See getAnchor() for more details.

Parameters
positionThe position of the node in its parent's coordinate system.

◆ setPosition() [2/2]

void cugl::scene3::SceneNode::setPosition ( float  x,
float  y,
float  z 
)

Sets the position of the node in its parent's coordinate system.

The node position is not necessarily the origin of the Node coordinate system. The relationship between the position and Node space is determined by the anchor point. See getAnchor() for more details.

Parameters
xThe x-coordinate of the node in its parent's coordinate system.
yThe x-coordinate of the node in its parent's coordinate system.
zThe z-coordinate of the node in its parent's coordinate system.

◆ setRotation()

void cugl::scene3::SceneNode::setRotation ( cugl::Quaternion  rot)

Sets the rotation quaterion of this node about the anchor.

This value rotates the node about the anchor, with the anchor unmoved. Rotations are represented by quaternions, which store both an axis and and angle of rotation (in radians).

Parameters
rotThe rotation quaterion of this node about the anchor.

◆ setScale() [1/2]

void cugl::scene3::SceneNode::setScale ( const cugl::Vec3  scale)

Sets the non-uniform scaling factor for this node about the anchor.

This factor scales the node about the anchor (with the anchor unmoved). Hence this is not the same as a scale applied to Node space, as the origin may be different. Scaling is first, before any other transforms.

Parameters
scaleThe non-uniform scaling factor for this node about the anchor

◆ setScale() [2/2]

void cugl::scene3::SceneNode::setScale ( float  scale)
inline

Sets the uniform scaling factor for this node about the anchor.

This factor scales the node about the anchor (with the anchor unmoved). Hence this is not the same as a scale applied to Node space, as the origin may be different. Scaling is first, before any other transforms.

Parameters
scaleThe uniform scaling factor for this node about the anchor

◆ setTag()

void cugl::scene3::SceneNode::setTag ( unsigned int  tag)
inline

Sets a tag that is used to identify the node easily.

This tag is used to quickly access a child node, since child position may change. To work properly, a tag should be unique within a scene graph. It is 0 if undefined.

Parameters
tagA tag that is used to identify the node easily.

◆ setVisible()

void cugl::scene3::SceneNode::setVisible ( bool  visible)
inline

Sets whether the node is visible.

If a node is not visible, then it is not drawn. This means that its children are not visible as well, regardless of their visibility settings. The default value is true, making the node visible.

Parameters
visibletrue if the node is visible.

◆ swapChild()

void cugl::scene3::SceneNode::swapChild ( const std::shared_ptr< SceneNode > &  child1,
const std::shared_ptr< SceneNode > &  child2,
bool  inherit = false 
)

Swaps the current child child1 with the new child child2.

If inherit is true, the children of child1 are assigned to child2 after the swap; this value is false by default. The purpose of this value is to allow transition nodes in the middle of the scene graph.

This method is undefined if child1 is not a child of this node.

Parameters
child1The current child of this node
child2The child to swap it with.
inheritWhether the new child should inherit the children of child1.

◆ toString()

virtual std::string cugl::scene3::SceneNode::toString ( bool  verbose = false) const
virtual

Returns a string representation of this node for debugging purposes.

If verbose is true, the string will include class information. This allows us to unambiguously identify the class.

Parameters
verboseWhether to include class information
Returns
a string representation of this node for debuggging purposes.

◆ worldToNodeCoords()

Vec3 cugl::scene3::SceneNode::worldToNodeCoords ( const Vec3  worldPoint) const
inline

Converts an OpenGL position to node (local) space coordinates.

See getWorldtoNodeTransform() for how this conversion takes place. That method should be used instead if there are many points to convert, as this method will recompute the transform matrix each time.

Parameters
worldPointAn OpenGL position.
Returns
A point in node (local) space coordinates.

Member Data Documentation

◆ _anchor

cugl::Vec3 cugl::scene3::SceneNode::_anchor
protected

The anchor point of the node.

The anchor point is a position in node space. All transforms applied to this node occur about the anchor, not the origin.

◆ _batchkey

CUEnum cugl::scene3::SceneNode::_batchkey
protected

The batch key

◆ _childOffset

int cugl::scene3::SceneNode::_childOffset
protected

The (current) child offset of this node (-1 if root)

◆ _children

std::vector<std::shared_ptr<SceneNode> > cugl::scene3::SceneNode::_children
protected

The array of children nodes

◆ _classname

std::string cugl::scene3::SceneNode::_classname
protected

The class name for the specific subclass

◆ _graph

Scene3* cugl::scene3::SceneNode::_graph
protected

A weaker pointer to the scene (or null if not in a scene)

◆ _hashOfName

size_t cugl::scene3::SceneNode::_hashOfName
protected

A cached has value of _name.

This value is used to speed up look-ups by string.

◆ _isVisible

bool cugl::scene3::SceneNode::_isVisible
protected

Whether this node is visible

◆ _json

std::shared_ptr<JsonValue> cugl::scene3::SceneNode::_json
protected

The defining JSON data for this node (if any)

◆ _modelmat

Mat4 cugl::scene3::SceneNode::_modelmat
protected

The model matrix for this node

◆ _name

std::string cugl::scene3::SceneNode::_name
protected

A descriptive identifying tag.

Like tag, this value is used to quickly identify the child of a node. However, it is more descriptive, and so is useful in debugging.

◆ _parent

SceneNode* cugl::scene3::SceneNode::_parent
protected

A weaker pointer to the parent (or null if root)

◆ _position

cugl::Vec3 cugl::scene3::SceneNode::_position
protected

The position of this node in the parent coordinate space.

◆ _rotate

cugl::Quaternion cugl::scene3::SceneNode::_rotate
protected

The rotation to transform this node.

Rotation is applied after any scaling, but before the position translation. The node coordinate space remains unchanged.

◆ _scale

cugl::Vec3 cugl::scene3::SceneNode::_scale
protected

The scaling factor to transform this node.

This scaling happens in the parent coordinate space. Scaling happens before any rotation. The node coordinate space remains unchanged.

◆ _tag

unsigned int cugl::scene3::SceneNode::_tag
protected

An identifying tag.

This value is used to quickly identify the child of a node. To work properly, a tag should be unique within a scene graph. It is 0 if undefined.


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