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

#include <CUScene.h>

Inheritance diagram for cugl::Scene:
cugl::scene2::Scene2 cugl::scene2::LoadingScene cugl::scene2::Scene2Texture

Public Member Functions

 Scene ()
 
 ~Scene ()
 
virtual void dispose ()
 
virtual bool init ()
 
virtual bool initWithHint (Size hint)
 
virtual bool initWithHint (float width, float height)
 
const std::string getName () const
 
void setName (const std::string name)
 
std::shared_ptr< CameragetCamera ()
 
const std::shared_ptr< CameragetCamera () const
 
virtual std::string toString (bool verbose=false) const
 
 operator std::string () const
 
const Size getSize () const
 
const Rect getBounds () const
 
Vec3 screenToWorldCoords (const Vec2 screenCoords) const
 
Vec2 worldToScreenCoords (const Vec3 worldCoords) const
 
bool isActive () const
 
virtual void setActive (bool value)
 
virtual void update (float timestep)
 
virtual void reset ()
 
virtual void render ()
 

Protected Attributes

std::shared_ptr< Camera_camera
 
std::string _name
 
Size _size
 
bool _active
 

Detailed Description

This class provides the root class of an application scene.

Most applications are composed of one or more scenes, with the application root responsible for switching between them. Typically these scenes have associated scene graphs. However scene graphs are specific to a rendering pipeline. Therefore it is useful to have a base class that is pipeline agnostic.

Scenes are designed to fill the entire screen. However, to better support aspect ratio independent design, many screens are height or width locked. In each case that means that this particular dimension is fixed to a particular size. This makes it possible to layout UI elements with Figma or other tools.

While Scenes are designed to fill the entire screen, it is possible to render multiple scenes on top of each other. This can be useful for transition effects or for UI layers where you want the camera to be separate from the main game layer.

This class has no static allocators as it is an abstract class intended to be subclassed

Constructor & Destructor Documentation

◆ Scene()

cugl::Scene::Scene ( )
inline

Creates a new degenerate Scene on the stack.

The scene has no view size 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.

◆ ~Scene()

cugl::Scene::~Scene ( )
inline

Deletes this scene, disposing all resources

Member Function Documentation

◆ dispose()

virtual void cugl::Scene::dispose ( )
inlinevirtual

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.

Reimplemented in cugl::scene2::LoadingScene, cugl::scene2::Scene2, and cugl::scene2::Scene2Texture.

◆ getBounds()

const Rect cugl::Scene::getBounds ( ) const
inline

Returns the viewport of this Scene.

Returns
the viewport of this Scene.

◆ getCamera() [1/2]

std::shared_ptr< Camera > cugl::Scene::getCamera ( )
inline

Returns the camera for this scene.

Returns
the camera for this scene.

◆ getCamera() [2/2]

const std::shared_ptr< Camera > cugl::Scene::getCamera ( ) const
inline

Returns the camera for this scene.

Returns
the camera for this scene.

◆ getName()

const std::string cugl::Scene::getName ( ) const
inline

Returns a string that is used to identify the scene.

Returns
a string that is used to identify the scene.

◆ getSize()

const Size cugl::Scene::getSize ( ) const
inline

Returns the viewport size of this Scene.

Returns
the viewport size of this Scene.

◆ init()

virtual bool cugl::Scene::init ( )
virtual

Initializes a Scene to fill the entire screen.

Returns
true if initialization was successful.

Reimplemented in cugl::scene2::Scene2, and cugl::scene2::Scene2Texture.

◆ initWithHint() [1/2]

virtual bool cugl::Scene::initWithHint ( float  width,
float  height 
)
inlinevirtual

Initializes a Scene with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

Parameters
widthThe width size hint
heightThe height size hint
Returns
true if initialization was successful.

Reimplemented in cugl::scene2::Scene2, and cugl::scene2::Scene2Texture.

◆ initWithHint() [2/2]

virtual bool cugl::Scene::initWithHint ( Size  hint)
virtual

Initializes a Scene with the given size hint.

Scenes are designed to fill the entire screen. If you want a scene that is only part of the screen, that should be implemented with a specific scene graph. However, the size of that screen can vary from device to device. To make scene design easier, designs are typically locked to a dimension: width or height.

This is the purpose of the size hint. If either of the values of hint are non-zero, then the scene will lock that dimension to that particular size. If both are non-zero, it will choose its dimension according to the device orientation. Landscape will be height, while portrait will pick width. Devices with no orientation will always priortize height over width.

Parameters
hintThe size hint
Returns
true if initialization was successful.

Reimplemented in cugl::scene2::Scene2Texture, and cugl::scene2::Scene2.

◆ isActive()

bool cugl::Scene::isActive ( ) const
inline

Returns true if the scene is currently active

Returns
true if the scene is currently active

◆ operator std::string()

cugl::Scene::operator std::string ( ) const
inline

Cast from a Scene to a string.

◆ render()

virtual void cugl::Scene::render ( )
inlinevirtual

Renders this screen to the scene.

This method make no assumption about the graphics pipeline. Each scene is capable of having its own pipeline.

Reimplemented in cugl::scene2::Scene2, and cugl::scene2::Scene2Texture.

◆ reset()

virtual void cugl::Scene::reset ( )
inlinevirtual

Resets the status of the scene to its original configuration.

◆ screenToWorldCoords()

Vec3 cugl::Scene::screenToWorldCoords ( const Vec2  screenCoords) const
inline

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.

This method is important for converting event coordinates (such as a mouse click) to world coordinates. Note that not all scenes support the third dimension.

Parameters
screenCoordsThe point in screen coordinates
Returns
the world space equivalent of a point in screen coordinates.

◆ setActive()

virtual void cugl::Scene::setActive ( bool  value)
inlinevirtual

Sets whether the scene is currently active

Parameters
valuewhether the scene is currently active

◆ setName()

void cugl::Scene::setName ( const std::string  name)
inline

Returns the string that is used to identify the scene.

Parameters
nameA string that is used to identify the scene.

◆ toString()

virtual std::string cugl::Scene::toString ( bool  verbose = false) const
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.

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

Reimplemented in cugl::scene2::Scene2.

◆ update()

virtual void cugl::Scene::update ( float  timestep)
inlinevirtual

The method called to update the scene.

This method should be overridden with the specific scene logic.

Parameters
timestepThe amount of time (in seconds) since the last frame

Reimplemented in cugl::scene2::LoadingScene.

◆ worldToScreenCoords()

Vec2 cugl::Scene::worldToScreenCoords ( const Vec3  worldCoords) const
inline

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). Note that not all scenes support the third dimension.

Parameters
worldCoordsThe point in wprld coordinates
Returns
the screen space equivalent of a point in world coordinates.

Member Data Documentation

◆ _active

bool cugl::Scene::_active
protected

Whether or note this scene is still active

◆ _camera

std::shared_ptr<Camera> cugl::Scene::_camera
protected

The camera for this scene

◆ _name

std::string cugl::Scene::_name
protected

The name of this scene

◆ _size

Size cugl::Scene::_size
protected

The scene size (for initializing the camera).


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