Polycode uses a managed scene graph system for all of its internal rendering, which means that you don't manually render things, but add them to a scene and the rendering is done automatically. Scenes and entities are the base components of this scene graph.

Contents

Scenes overview.

All rendering in Polycode happens via Scenes. A Scene is, at its most basic, a container for the root entity and a camera defining how the scene is rendered. Scenes can be instantiated as 2D or 3D, which defines the initial default camera settings for the scene (you can change the camera settings at any time after that or render via different cameras). You can have any number of scenes rendering at the same time. For example, you can use a 3D Scene to render a game and a 2D Scene on top of it to render the UI. Scenes are managed internally by the SceneManager.

Entities overview.

Entities are the base of all positional and renderable objects in Polycode. They contain transform information, render and update code as well as various entity properties, such as id's and tags. They can contain other entities and form complex hierarchies. There is a single root contained in every Scene and all entities added to that scene are children of its root entity.

Creating a scene.

There are three types of scenes that you can create, each one defining the default camera options and coordinate system of the scene. Though you can change the camera options or switch to another camera at any point.

SCENE_3D - Perspective camera, Y-up coordinate system. Use this setting for all 3D scenes.

SCENE_2D - Orthographic camera, Y-up coordinate system with 0,0 coordinate in the middle of the screen. The orthographic mode of the camera is set to lock height at 1.0 and adjust the width based on the aspect ratio (see ORTHO_SIZE_LOCK_HEIGHT mode). Use this setting for resolution-independent 2D scenes.

SCENE_2D_TOPLEFT - Orthographic camera, Y-down coordinate system with 0,0 coordinate in the top left corner of the screen. The orthographic mode of the camera is set to match the orthographic size to current resolution (see ORTHO_SIZE_VIEWPORT mode). Use this setting for resolution-dependent UI scenes.

To create a new scene, simply instantiate a Scene class and pass it the type of Scene you want to create. It will be automatically added to the SceneManager and will begin rendering to the front buffer on every render call.

C++
Scene *scene = new Scene(Scene::SCENE_2D);
Lua
scene = Scene(Scene.SCENE_2D)

Adding entities to the scene.

By default a scene contains a single root entity called rootEntity. Everything rendered in the scene is rendered via this single root entity. To add your entities to the scene you can add them as children to the rootEntity or use the Scene's wrapper addChild method, which does the same thing.

Alternatively, you can add an entity to another entity that is already added to the scene (using the addChild method), in which case, the child entity's transformations will be relative to its parent entity.

C++
Scene *scene = new Scene(Scene::SCENE_2D);
ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.5, 0.5);
scene->addChild(box);
Lua
scene = Scene(Scene.SCENE_2D)
box = ScenePrimitive(ScenePrimitive.TYPE_VPLANE, 0.5, 0.5)
scene:addChild(box)

Transforming entities.

Entities can be moved, scaled and rotated in 3 dimensions. Entities added as children to other entities inherit their transformations (unless the children's ignoreParentMatrix setting is set to true). Entity color can also be set by calling setColor or directly setting the color property of an entity. The entity color is used as a vertex color unless a mesh specifies that it wants to use per-vertex colors (see Rendering Meshes).

C++
Scene *scene = new Scene(Scene::SCENE_2D);
for(int i=0; i < 10; i++) {
    ScenePrimitive *box = new ScenePrimitive(ScenePrimitive::TYPE_VPLANE, 0.12, 0.12);
    box->setPosition(-0.5 + (i * 0.1), 0.0, 0.0);
    box->setScale(1.0 - (i * 0.1), 1.0 - (i * 0.1), 1.0 - (i * 0.1));
    box->setRoll(i * 20.0);
    box->setColor(i * 0.1, 1.0, 1.0 - (i * 0.1), 1.0);
    scene->addChild(box);
}
Lua
scene = Scene(Scene.SCENE_2D)

for i=0,10 do
	box = ScenePrimitive(ScenePrimitive.TYPE_VPLANE, 0.12, 0.12)
	box:setPosition(-0.5 + (i * 0.1), 0.0, 0.0)
	box:setScale(1.0 - (i * 0.1), 1.0 - (i * 0.1), 1.0 - (i * 0.1))
	box:setRoll(i * 20.0)
	box:setColor(i * 0.1, 1.0, 1.0 - (i * 0.1), 1.0)
	scene:addChild(box)
end