![]() |
CUGL 3.0
Cornell University Game Library
|
#include <CUScene3.h>
Public Member Functions | |
Scene3 () | |
~Scene3 () | |
virtual void | dispose () |
bool | init (const Size size) |
bool | init (float width, float height) |
bool | init (const Rect rect) |
bool | init (const Vec2 origin, const Size size) |
virtual bool | init (float x, float y, float width, float height) |
const std::string | getName () const |
void | setName (const std::string name) |
std::shared_ptr< Camera > | getCamera () |
const std::shared_ptr< Camera > | getCamera () const |
virtual std::string | toString (bool verbose=false) const |
operator std::string () const | |
const Size | getSize () const |
void | setSize (const Size size) |
void | setSize (float width, float height) |
void | setWidth (float width) |
void | setHeight (float height) |
const Rect | getBounds () const |
void | setBounds (const Rect rect) |
void | setBounds (const Vec2 origin, const Size size) |
void | setBounds (float x, float y, float width, float height) |
void | setOffset (const Vec2 origin) |
Vec3 | screenToWorldCoords (const Vec2 screenCoords) const |
Vec2 | worldToScreenCoords (const Vec3 worldCoords) const |
size_t | getChildCount () const |
std::shared_ptr< SceneNode > | getChild (unsigned int pos) |
const std::shared_ptr< SceneNode > & | getChild (unsigned int pos) const |
template<typename T > | |
std::shared_ptr< T > | getChild (unsigned int pos) const |
std::shared_ptr< SceneNode > | getChildByTag (unsigned int tag) const |
template<typename T > | |
std::shared_ptr< T > | getChildByTag (unsigned int tag) const |
std::shared_ptr< SceneNode > | getChildByName (const std::string name) const |
template<typename T > | |
std::shared_ptr< T > | getChildByName (const std::string name) const |
std::vector< std::shared_ptr< SceneNode > > | getChildren () |
const std::vector< std::shared_ptr< SceneNode > > & | getChildren () const |
virtual 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) |
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 () |
bool | isActive () const |
virtual void | setActive (bool value) |
virtual void | update (float timestep) |
virtual void | reset () |
virtual void | render () |
Static Public Member Functions | |
static std::shared_ptr< Scene3 > | alloc (const Size size) |
static std::shared_ptr< Scene3 > | alloc (float width, float height) |
static std::shared_ptr< Scene3 > | alloc (const Rect rect) |
static std::shared_ptr< Scene3 > | alloc (const Vec2 origin, const Size size) |
static std::shared_ptr< Scene3 > | alloc (float x, float y, float width, float height) |
Protected Attributes | |
std::string | _name |
std::shared_ptr< PerspectiveCamera > | _camera |
std::shared_ptr< Scene3Pipeline > | _pipeline |
cugl::Vec3 | _light |
std::vector< std::shared_ptr< SceneNode > > | _children |
bool | _active |
Friends | |
class | SceneNode |
This class provides the root node of a three-dimensional scene graph.
The Scene2 class is very similar to scene3::SceneNode
and shares some methods in common. The major difference is that it has no parent and it has no position (so it cannot be transformed). Instead, the Scene2 is defined by an attached PerspectiveCamera
.
Rendering a scene graph happens via a Scene3Pipeline
. That pipeline uses depth testing to properly render the scene, but may perform sorting in order to preserve transparency and similar such affects.
cugl::scene3::Scene3::Scene3 | ( | ) |
Creates a new degenerate scene on the stack.
The scene has no camera and must be initialized.
NEVER USE A CONSTRUCTOR WITH NEW. If you want to allocate an object on the heap, use one of the static constructors instead.
|
inline |
Deletes this scene, disposing all resources
|
virtual |
Adds a child to this scene.
Children are not necessarily enumerated in the order that they are added. Hence you should generally attempt to retrieve a child by tag or by name instead.
child | A child node. |
|
inline |
Adds a child to this scene with the given name.
Children are not necessarily enumerated in the order that they are added. Hence you should generally attempt to retrieve a child by tag or by name instead.
child | A child node. |
name | A string to identify the node. |
|
inline |
Adds a child to this scene with the given tag.
Children are not necessarily enumerated in the order that they are added. Hence you should generally attempt to retrieve a child by tag or by name instead.
child | A child node. |
tag | An integer to identify the node easily. |
Returns a newly allocated scene for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
rect | The viewport bounding box |
Returns a newly allocated scene for the given viewport.
The viewport origin is assumed to be (0,0).
size | The viewport size |
|
inlinestatic |
Returns a newly allocated scene for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
origin | The viewport offset |
size | The viewport size |
|
inlinestatic |
Returns a newly allocated scene for the given viewport.
The viewport origin is assumed to be (0,0).
width | The viewport width |
height | The viewport height |
|
inlinestatic |
Returns a newly allocated scene for the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
x | The viewport x offset |
y | The viewport y offset |
width | The viewport width |
height | The viewport height |
|
virtual |
Disposes all of the resources used by this scene.
A disposed scene can be safely reinitialized. Any children owned by this scene will be released. They will be deleted if no other object owns them.
|
inline |
Returns the viewport of this Scene2.
std::shared_ptr< Camera > cugl::scene3::Scene3::getCamera | ( | ) |
Returns the camera for this scene.
const std::shared_ptr< Camera > cugl::scene3::Scene3::getCamera | ( | ) | const |
Returns the camera for this scene.
std::shared_ptr< SceneNode > cugl::scene3::Scene3::getChild | ( | unsigned int | pos | ) |
Returns the child at the given position.
Children are not necessarily enumerated in the order that they are added. 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.
pos | The child position. |
const std::shared_ptr< SceneNode > & cugl::scene3::Scene3::getChild | ( | unsigned int | pos | ) | const |
Returns the child at the given position.
Children are not necessarily enumerated in the order that they are added. Hence you should generally attempt to retrieve a child by tag or by name instead.
pos | The child position. |
|
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.
Children are not necessarily enumerated in the order that they are added. Hence you should generally attempt to retrieve a child by tag or by name instead.
pos | The child position. |
std::shared_ptr< SceneNode > cugl::scene3::Scene3::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. Children are not necessarily enumerated in the order that they are added. Hence it is very important that names be unique.
name | An identifier to find the child node. |
|
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. Children are not necessarily enumerated in the order that they are added. Hence it is very important that names be unique.
name | An identifier to find the child node. |
std::shared_ptr< SceneNode > cugl::scene3::Scene3::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. Children are not necessarily enumerated in the order that they are added. Hence it is very important that tags be unique.
tag | An identifier to find the child node. |
|
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. Children are not necessarily enumerated in the order that they are added. Hence it is very important that tags be unique.
tag | An identifier to find the child node. |
|
inline |
Returns the number of immediate children of this scene.
|
inline |
Returns the list of the scene's immediate children.
|
inline |
Returns the list of the scene's immediate children.
|
inline |
Returns a string that is used to identify the scene.
|
inline |
Returns the viewport size of this Scene2.
|
inline |
Initializes a scene with the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
rect | The viewport bounding box |
|
inline |
Initializes a scene with the given viewport.
The viewport origin is assumed to be (0,0).
size | The viewport size |
Initializes a scene with the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
origin | The viewport offset |
size | The viewport size |
|
inline |
Initializes a scene with the given viewport.
The viewport origin is assumed to be (0,0).
width | The viewport width |
height | The viewport height |
|
virtual |
Initializes a scene with the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset of the viewport in a larger canvas.
x | The viewport x offset |
y | The viewport y offset |
width | The viewport width |
height | The viewport height |
|
inline |
Returns true if the scene is currently active
|
inline |
Cast from a Scene to a string.
|
virtual |
Removes all children from this Node.
void cugl::scene3::Scene3::removeChild | ( | const std::shared_ptr< SceneNode > & | child | ) |
Removes a child from this Scene.
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.
child | The child node which will be removed. |
|
virtual |
Removes the child at the given position from this Scene.
Removing a child alters the position of every child after it. Hence it is unsafe to cache child positions.
pos | The position of the child node which will be removed. |
void cugl::scene3::Scene3::removeChildByName | ( | const std::string | name | ) |
Removes a child from the Scene by name.
If there is more than one child of the given name, it removes the first one that is found. Children are not necessarily enumerated in the order that they are added. Hence it is very important that names be unique.
name | A string to identify the node. |
void cugl::scene3::Scene3::removeChildByTag | ( | unsigned int | tag | ) |
Removes a child from the Scene by tag value.
If there is more than one child of the given tag, it removes the first one that is found. Children are not necessarily enumerated in the order that they are added. Hence it is very important that tags be unique.
tag | An integer to identify the node easily. |
|
virtual |
Draws all of the children in this scene with the given pipeline.
Rendering happens by traversing the the scene graph using an "Pre-Order" tree traversal algorithm ( https://en.wikipedia.org/wiki/Tree_traversal#Pre-order ). That means that parents are always draw before children.
|
inlinevirtual |
Resets the status of the scene to its original configuration.
Returns the world space equivalent of a point in screen coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
In computing the world space coordinates, this method assumes that the z-value of the original vector is the same as near, which is the closest it can be the screen.
This method is important for converting event coordinates (such as a mouse click) to world coordinates.
screenCoords | The point in screen coordinates |
|
inlinevirtual |
Sets whether the scene is currently active
value | whether the scene is currently active |
|
inline |
Sets this Scene2 to have the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
rect | The viewport bounding box |
Sets this Scene2 to have the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
origin | The viewport offset |
size | The viewport size |
|
inline |
Sets this Scene2 to have the given viewport.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
x | The viewport x offset |
y | The viewport y offset |
width | The viewport width |
height | The viewport height |
|
inline |
Sets this scene to have the given viewport height.
The viewport origin is assumed to be (0,0).
height | The viewport height |
|
inline |
Sets the string that is used to identify the scene.
name | A string that is used to identify the scene. |
|
inline |
Offsets the viewport origin by the given amount.
Offseting the viewport origin has little affect on the Scene in general. It only affects the coordinate conversion methods Camera#project()
and Camera#unproject()
. It is supposed to represent the offset
origin | The offset of the viewport origin |
|
inline |
Sets this scene to have the given viewport.
The viewport origin is assumed to be (0,0).
size | The viewport size |
|
inline |
Sets this scene to have the given viewport.
The viewport origin is assumed to be (0,0).
width | The viewport width |
height | The viewport height |
|
inline |
Sets this scene to have the given viewport width.
The viewport origin is assumed to be (0,0).
width | The viewport width |
void cugl::scene3::Scene3::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 transitions in the scene graph.
This method is undefined if child1 is not a child of this scene.
child1 | The current child of this node |
child2 | The child to swap it with. |
inherit | Whether the new child should inherit the children of child1. |
|
virtual |
Returns a string representation of this scene for debugging purposes.
If verbose is true, the string will include class information. This allows us to unambiguously identify the class.
verbose | Whether to include class information |
|
inlinevirtual |
The method called to update the scene.
This method should be overridden with the specific scene logic.
timestep | The amount of time (in seconds) since the last frame |
Returns the screen space equivalent of a point in world coordinates.
Ideally, window space and screen space would be the same space. They are both defined by the viewport and have the same offset and dimension. However, screen coordinates have the origin in the top left while window coordinates have the origin in the bottom left.
This method is important for converting world coordinates to event coordinates (such as a mouse click).
worldCoords | The point in wprld coordinates |
|
protected |
Whether or note this scene is still active
|
protected |
The camera for this scene
|
protected |
The array of internal nodes
|
protected |
The light source position
|
protected |
The name of this scene
|
protected |
The camera for this scene