// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "ExampleSpin.hpp" #include "game/DawnGame.hpp" #include "scene/components/display/mesh/MeshRenderer.hpp" #include "display/mesh/CubeMesh.hpp" #include "scene/components/display/material/SimpleTexturedMaterial.hpp" using namespace Dawn; std::shared_ptr ExampleSpin::create(Scene *scene) { auto item = scene->createSceneItem(); auto mr = item->addComponent(); mr->mesh = new Mesh(); mr->mesh->createBuffers(CUBE_VERTICE_COUNT, CUBE_INDICE_COUNT); CubeMesh::buffer(mr->mesh, glm::vec3(-0.5f, -0.5f, -0.5f), glm::vec3(1, 1, 1), 0, 0); auto mat = item->addComponent(); item->addComponent(); return item; } ExampleSpin::ExampleSpin(std::weak_ptr item) : SceneItemComponent(item) { } void ExampleSpin::onStart() { useEvent([&](float_t delta){ auto i = item.lock(); auto quat = i->getLocalRotation(); quat = glm::rotate(quat, delta, glm::vec3(0, 1, 0)); quat = glm::rotate(quat, delta / 2.0f, glm::vec3(1, 0, 0)); quat = glm::rotate(quat, delta / 4.0f, glm::vec3(0, 0, 1)); i->setLocalRotation(quat); }, getScene()->eventSceneUnpausedUpdate); }