39 lines
1.3 KiB
C++
39 lines
1.3 KiB
C++
// 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<SceneItem> ExampleSpin::create(Scene *scene) {
|
|
auto item = scene->createSceneItem();
|
|
auto mr = item->addComponent<MeshRenderer>();
|
|
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<SimpleTexturedMaterial>();
|
|
item->addComponent<ExampleSpin>();
|
|
return item;
|
|
}
|
|
|
|
ExampleSpin::ExampleSpin(std::weak_ptr<SceneItem> 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);
|
|
} |