Home » Pocket Engine » Simple Example

Simple Example

#include "Engine.hpp"
#include "GameState.hpp"
#include "OpenGL.hpp"
#include "GameWorld.hpp"
#include "RenderSystem.hpp"

using namespace Nano;

class Test : public GameState<Test> {

    GameWorld world;
    GameObject* cube;

    void Initialize() {
        world.CreateSystem<RenderSystem>();

        GameObject* cameraObject = world.CreateObject();
        cameraObject->AddComponent<Transform>()->Position = {0,0,5};
        cameraObject->AddComponent<Camera>()->Viewport = Manager().Viewport();

        Box viewPort = Manager().Viewport();

        cube = world.CreateObject();
        cube->AddComponent<Transform>();
        cube->AddComponent<Mesh>()->AddCube(0, 1);
        cube->GetComponent<Mesh>()->AddGeoSphere(1,1,10);
        cube->AddComponent<Material>();
    }

    void Update(float dt) {
    static float rot = 0;
        rot += dt;
        cube->GetComponent<Transform>()->Rotation = Quaternion(rot, Vector3(1,1,0).Normalized());
        world.Update(dt);
    }

    void Render() {
        glClear(GL_COLOR_BUFFER_BIT);
        world.Render();
    }
};

int main() {
    Engine e;
    e.Start<Test>();
    return 0;
}