Skip to content

Scene System

Steven Sell edited this page Jun 23, 2015 · 1 revision

The Scene Subsystem in the Ocular Engine is designed to be both highly-flexible and easy-to-use. We will begin by looking at how to interact with the system and then go into detail of the individual classes that make it work.

The SceneObject

A SceneObject is just that - an arbitrary object in the scene. Each SceneObject is a collection of logic to run and physical structures to render. All logic is contained inside of a Routine that has numerous callbacks (update, scene start/end, etc.) while all data that should be rendered is represented by a Renderable.

A typical SceneObject will consist of at least a single Routine/Renderable pairing. Now, an individual object can have an indefinite number of Routines and Renderables attached to it, but in normal situations additional Routines and Renderables should be attached indirectly via child objects.

Let's take a look at a basic SceneObject that creates a cube mesh and moves it in a direction. First, we create the empty object:

SceneObject* object = OcularEngine.Scene()->createObject();

Next, we add on our logic and render information:

object->addRoutine("CustomMove");
object->addRenderable("PrimitiveCube", 1.0f, Color.Green);

So we have attached a new routine called "CustomMove" and a renderable called "PrimitiveCube" with extra parameters to pass along to it's constructor. While the cube renderable is a native part of the Ocular Engine, we must create our own routine. This is as simple as creating a new class, inheriting from ARoutine and then filling out the callback methods that we want:

RoutineCustomMove.hpp

class RoutineCustomMove : public ARoutine
{
public:

    RoutineCustomMove();
    virtual ~RoutineCustomMove();

    virtual void onUpdate(float const delta) override;

protected:

private:
};

RoutineCustomMove.cpp

RoutineCustomMove::RoutineCustomMove()
    : ARoutine("CustomMove")
{

}

RoutineCustomMove::~RoutineCustomMove()
{

}

void RoutineCustomMove::onUpdate(float const delta) 
{
    if(sceneObject)
    {
        // Transform along the +x-axis at a constant rate of 10 units/second.
        sceneObject.tranform.translate(Vector3f(1.0f, 0.0f, 0.0f), (10.0f * delta));
    }
}