Dawn/src/dawnhelloworld/scene/HelloWorldScene.cpp
2023-11-25 15:51:20 -06:00

40 lines
1.4 KiB
C++

// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "scene/SceneList.hpp"
#include "component/display/Camera.hpp"
#include "component/display/MeshRenderer.hpp"
#include "component/display/material/SimpleTexturedMaterial.hpp"
#include "display/mesh/CubeMesh.hpp"
#include "component/SimpleComponent.hpp"
using namespace Dawn;
void Dawn::helloWorldScene(Scene &s) {
std::cout << "Hello World Scene" << std::endl;
auto cameraItem = s.createSceneItem();
auto camera = cameraItem->addComponent<Camera>();
cameraItem->lookAt({ 3, 3, 3}, { 0, 0, 0 }, { 0, 1, 0 });
auto cubeMesh = std::make_shared<Mesh>();
cubeMesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT);
CubeMesh::buffer(cubeMesh, glm::vec3(-1, -1, -1), glm::vec3(1, 1, 1), 0, 0);
auto texture = s.getGame()->assetManager.get<Texture>("test_texture");
auto cubeItem = s.createSceneItem();
auto cubeMeshRenderer = cubeItem->addComponent<MeshRenderer>();
cubeMeshRenderer->mesh = cubeMesh;
auto cubeMaterial = cubeItem->addComponent<SimpleTexturedMaterial>();
cubeMaterial->setTexture(texture);
addSimpleComponent(cubeItem, [](auto &cmp, auto &events) {
events.push_back(cmp.getScene()->onUnpausedUpdate.listen([&](float_t delta) {
auto item = cmp.getItem();
item->setLocalRotation(item->getLocalRotation() * glm::quat(glm::vec3(1, 1, 0) * delta));
}));
});
}