// Copyright (c) 2022 Dominic Masters // // This software is released under the MIT License. // https://opensource.org/licenses/MIT #include "SimpleVisualNovelBackground.hpp" using namespace Dawn; SimpleVisualNovelBackground * SimpleVisualNovelBackground::create(Scene *s) { auto item = s->createSceneItem(); // item->addComponent(); item->addComponent(); item->addComponent(); auto background = item->addComponent(); return background; } SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) : SceneItemComponent(item) { } std::vector SimpleVisualNovelBackground::getDependencies(){ return std::vector{ this->material = this->item->getComponent(), this->meshHost = this->item->getComponent() }; } void SimpleVisualNovelBackground::setTexture(Texture *texture) { assertNotNull(texture); this->material->texture = texture; // Since we go both negative and positive, actual height is doubled float_t aspect = (float_t)texture->getWidth() / (float_t)texture->getHeight(); float_t height = 0.5f; QuadMesh::bufferQuadMeshWithZ(&this->meshHost->mesh, glm::vec2(-aspect * height, -height), glm::vec2(0, 1), glm::vec2( aspect * height, height), glm::vec2(1, 0), 0.0f, 0, 0 ); } void SimpleVisualNovelBackground::onStart() { assertNotNull(this->material); assertNotNull(this->meshHost); QuadMesh::initQuadMesh(&this->meshHost->mesh, glm::vec2(-1, -1), glm::vec2(0, 1), glm::vec2(1, 1), glm::vec2(1, 0), 0.0f ); }