Moved Scene implementation around
This commit is contained in:
@ -1,45 +1,44 @@
|
||||
// Copyright (c) 2022 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "ExampleSpin.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "scene/components/display/MeshRenderer.hpp"
|
||||
#include "display/mesh/CubeMesh.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
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(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||
}
|
||||
|
||||
|
||||
void ExampleSpin::onUnpausedUpdate() {
|
||||
auto quat = this->transform->getLocalRotation();
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
|
||||
|
||||
this->transform->setLocalRotation(quat);
|
||||
}
|
||||
|
||||
void ExampleSpin::onDispose() {
|
||||
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||
// 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/MeshRenderer.hpp"
|
||||
#include "display/mesh/CubeMesh.hpp"
|
||||
#include "scene/components/display/material/SimpleTexturedMaterial.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
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(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
getScene()->eventSceneUnpausedUpdate.addListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||
}
|
||||
|
||||
|
||||
void ExampleSpin::onUnpausedUpdate() {
|
||||
auto quat = this->transform->getLocalRotation();
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta, glm::vec3(0, 1, 0));
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta / 2.0f, glm::vec3(1, 0, 0));
|
||||
quat = glm::rotate(quat, getGame()->timeManager.delta / 4.0f, glm::vec3(0, 0, 1));
|
||||
|
||||
this->transform->setLocalRotation(quat);
|
||||
}
|
||||
|
||||
void ExampleSpin::onDispose() {
|
||||
getScene()->eventSceneUnpausedUpdate.removeListener(this, &ExampleSpin::onUnpausedUpdate);
|
||||
}
|
Reference in New Issue
Block a user