#include #include #include #include #include #include // A spinning cube seen through a perspective camera. class Cube : public sophia::Application { public: Cube() : Application{{.width = 800, .height = 600, .name = "Cube"}} { debugUI().showFrameStats(true); } void onCreate() override { sophia::SceneHandle sceneHandle = scenes().create(); sophia::Scene& scene = scenes().get(sceneHandle); sophia::Entity camera = scene.createCamera(); camera.getComponent().projection = sophia::CameraComponent::Projection::Perspective; camera.getComponent().position = {0.f, 0.f, 3.f}; // Unlit, so color each face by its normal to tell them apart. sophia::MeshData data = sophia::primitives::cube(); for (sophia::MeshVertex& vertex : data.vertices) { vertex.color = glm::vec4{vertex.normal * 0.5f + 0.5f, 1.f}; } cube = scene.createEntity("Cube"); cube.addComponent(sophia::MeshComponent{ .handle = resources().create(data)}); sceneViews().create({ .scene = sceneHandle, }); } void onUpdate(const sophia::FrameInfo& frameInfo) override { auto angle = static_cast(frameInfo.elapsedTime); cube.getComponent().rotation = glm::angleAxis(angle, glm::normalize(glm::vec3{1.f, 1.f, 0.f})); } private: sophia::Entity cube; }; SOPHIA_MAIN(Cube)