diff --git a/src/dawn/display/RenderPipeline.cpp b/src/dawn/display/RenderPipeline.cpp index 68560058..a56ca489 100644 --- a/src/dawn/display/RenderPipeline.cpp +++ b/src/dawn/display/RenderPipeline.cpp @@ -126,10 +126,10 @@ void RenderPipeline::renderUI( // Clear / Bind / Update the render target. renderTarget->bind(); - renderTarget->clear( - RENDER_TARGET_CLEAR_FLAG_DEPTH | - RENDER_TARGET_CLEAR_FLAG_COLOR - ); + // renderTarget->clear( + // RENDER_TARGET_CLEAR_FLAG_DEPTH | + // RENDER_TARGET_CLEAR_FLAG_COLOR + // ); this->renderManager->setRenderFlags( RENDER_MANAGER_RENDER_FLAG_BLEND ); diff --git a/src/dawn/display/Transform.cpp b/src/dawn/display/Transform.cpp index 95b91ffd..c4ad4d90 100644 --- a/src/dawn/display/Transform.cpp +++ b/src/dawn/display/Transform.cpp @@ -5,6 +5,7 @@ #include "Transform.hpp" #include "scene/SceneItem.hpp" +#include "util/mathutils.hpp" using namespace Dawn; @@ -69,6 +70,16 @@ void Transform::lookAt(glm::vec3 pos, glm::vec3 look, glm::vec3 up) { this->setWorldTransform(glm::lookAt(pos, look, up)); } +float_t Transform::lookAtPixelPerfect( + glm::vec3 position, glm::vec3 look, float_t viewportHeight, float_t fov +) { + float_t z = ( + tanf((mathDeg2Rad(180.0f) - fov) / 2.0f) * + (viewportHeight/2.0f) + ); + this->lookAt(glm::vec3(position.x, position.y, position.z + z), look); + return z; +} glm::vec3 Transform::getLocalPosition() { return this->localPosition; diff --git a/src/dawn/display/Transform.hpp b/src/dawn/display/Transform.hpp index 1fc8a5cf..9009f9dc 100644 --- a/src/dawn/display/Transform.hpp +++ b/src/dawn/display/Transform.hpp @@ -60,6 +60,20 @@ namespace Dawn { void lookAt(glm::vec3 position, glm::vec3 look); void lookAt(glm::vec3 position, glm::vec3 look, glm::vec3 up); + /** + * Shorthand combined for lookAt and perspectivePixelPerfectDistance + * to allow you to create pixel perfect lookAt camera view matricies. + * + * @param position Position of the camera. Z is for an offset. + * @param look Position in world space this transform looks at. + * @param viewportHeight Height of the viewport. + * @param fov Field of view (in radians). + * @return The Z distance that was calculated. + */ + float_t lookAtPixelPerfect( + glm::vec3 position, glm::vec3 look, float_t viewportHeight, float_t fov + ); + /** * Returns the local position (position relative to "my parent"). * @return The 3D local position in parent-relative space. diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp index 0c3ae206..9c0f9470 100644 --- a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.cpp @@ -7,6 +7,15 @@ 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) { @@ -15,11 +24,32 @@ SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) : std::vector SimpleVisualNovelBackground::getDependencies(){ return std::vector{ - this->meshHost = this->item->getComponent(), - this->material = this->item->getComponent() + this->material = this->item->getComponent(), + this->meshHost = this->item->getComponent() }; } -void SimpleVisualNovelBackground::onStart() { +void SimpleVisualNovelBackground::setTexture(Texture *texture) { + auto param = this->material->getShader()->getParameterByName("u_Text"); + this->material->textureValues[param] = texture; + 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 + ); } \ No newline at end of file diff --git a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp index c178dfbb..a4aef513 100644 --- a/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp +++ b/src/dawn/visualnovel/components/SimpleVisualNovelBackground.hpp @@ -12,8 +12,11 @@ namespace Dawn { Material *material; MeshHost *meshHost; + static SimpleVisualNovelBackground * create(Scene *scene); + SimpleVisualNovelBackground(SceneItem *item); std::vector getDependencies() override; void onStart() override; + void setTexture(Texture *texture); }; } \ No newline at end of file diff --git a/src/dawn/visualnovel/events/CMakeLists.txt b/src/dawn/visualnovel/events/CMakeLists.txt index c9f8045a..c3a8c6b5 100644 --- a/src/dawn/visualnovel/events/CMakeLists.txt +++ b/src/dawn/visualnovel/events/CMakeLists.txt @@ -10,4 +10,5 @@ target_sources(${DAWN_TARGET_NAME} VisualNovelFadeEvent.cpp VisualNovelPauseEvent.cpp VisualNovelTextboxEvent.cpp + VisualNovelChangeSimpleBackgroundEvent.cpp ) \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp index 90fe2ac7..7a30322d 100644 --- a/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp +++ b/src/dawn/visualnovel/events/VisualNovelAnimationEvent.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "VisualNovelAnimationEvent.hpp" +#include "game/DawnGame.hpp" using namespace Dawn; diff --git a/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.cpp b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.cpp new file mode 100644 index 00000000..cfc64de6 --- /dev/null +++ b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.cpp @@ -0,0 +1,32 @@ +// Copyright (c) 2022 Dominic Masters +// +// This software is released under the MIT License. +// https://opensource.org/licenses/MIT + +#include "VisualNovelChangeSimpleBackgroundEvent.hpp" +#include "game/DawnGame.hpp" + +using namespace Dawn; + +VisualNovelChangeSimpleBackgroundEvent::VisualNovelChangeSimpleBackgroundEvent( + VisualNovelManager *manager, Texture *texture +) : IVisualNovelEvent(manager) { + this->texture = texture; +} + +void VisualNovelChangeSimpleBackgroundEvent::onStart(IVisualNovelEvent *prev) { + auto back = this->manager->getScene() + ->findComponent() + ; + + assertNotNull(back); + back->setTexture(this->texture); +} + +bool_t VisualNovelChangeSimpleBackgroundEvent::onUpdate() { + return false; +} + +void VisualNovelChangeSimpleBackgroundEvent::onEnd() { + +} \ No newline at end of file diff --git a/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp index 48ed4139..f0547a0f 100644 --- a/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp +++ b/src/dawn/visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp @@ -5,11 +5,16 @@ #pragma once #include "visualnovel/VisualNovelManager.hpp" +#include "visualnovel/components/SimpleVisualNovelBackground.hpp" namespace Dawn { class VisualNovelChangeSimpleBackgroundEvent : public IVisualNovelEvent { protected: - Texture *texture; + Texture *texture = nullptr; + + void onStart(IVisualNovelEvent *previous) override; + bool_t onUpdate() override; + void onEnd() override; public: VisualNovelChangeSimpleBackgroundEvent( diff --git a/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp b/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp index f136a705..14a1d501 100644 --- a/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp +++ b/src/dawn/visualnovel/events/VisualNovelPauseEvent.cpp @@ -4,6 +4,7 @@ // https://opensource.org/licenses/MIT #include "VisualNovelPauseEvent.hpp" +#include "game/DawnGame.hpp" using namespace Dawn; diff --git a/src/dawnpokergame/prefabs/VNPenny.hpp b/src/dawnpokergame/prefabs/VNPenny.hpp index d6f757ae..630a13ef 100644 --- a/src/dawnpokergame/prefabs/VNPenny.hpp +++ b/src/dawnpokergame/prefabs/VNPenny.hpp @@ -25,25 +25,27 @@ namespace Dawn { auto textureAsset = scene->game->assetManager.get("texture_penny"); auto tilesetAsset = scene->game->assetManager.get("tileset_penny"); - auto meshRenderer = item->addComponent(); - auto material = item->addComponent(); - auto meshHost = item->addComponent(); - auto tiledSprite = item->addComponent(); + // auto meshRenderer = item->addComponent(); + // auto material = item->addComponent(); + // auto meshHost = item->addComponent(); + // auto tiledSprite = item->addComponent(); + // auto animation = item->addComponent(); auto pokerPlayer = item->addComponent(); - auto animation = item->addComponent(); - - auto param = material->getShader()->getParameterByName("u_Text"); - material->textureValues[param] = &textureAsset->texture; - - tiledSprite->setTileset(&tilesetAsset->tileset); - tiledSprite->setSize(glm::vec2(tilesetAsset->tileset.divX, tilesetAsset->tileset.divY)); - - auto anim = new TiledSpriteAnimation(tiledSprite); - anim->addSequentialKeyframes(0.1f, 0, 22); - anim->loop = true; - animation->animation = anim; return item; + + // auto param = material->getShader()->getParameterByName("u_Text"); + // material->textureValues[param] = &textureAsset->texture; + + // tiledSprite->setTileset(&tilesetAsset->tileset); + // tiledSprite->setSize(glm::vec2(tilesetAsset->tileset.divX, tilesetAsset->tileset.divY)); + + // auto anim = new TiledSpriteAnimation(tiledSprite); + // anim->addSequentialKeyframes(0.1f, 0, 22); + // anim->loop = true; + // animation->animation = anim; + + // return item; } }; } \ No newline at end of file diff --git a/src/dawnpokergame/scenes/TestScene.hpp b/src/dawnpokergame/scenes/TestScene.hpp index d13bdf8d..e93236f1 100644 --- a/src/dawnpokergame/scenes/TestScene.hpp +++ b/src/dawnpokergame/scenes/TestScene.hpp @@ -13,6 +13,7 @@ #include "visualnovel/events/VisualNovelTextboxEvent.hpp" #include "visualnovel/events/VisualNovelPauseEvent.hpp" #include "visualnovel/events/VisualNovelFadeEvent.hpp" +#include "visualnovel/events/VisualNovelChangeSimpleBackgroundEvent.hpp" #include "poker/PokerGame.hpp" #include "visualnovel/events/PokerBetLoopEvent.hpp" #include "visualnovel/events/PokerInitialEvent.hpp" @@ -34,17 +35,25 @@ namespace Dawn { vectorAppend(&assets, &PokerPlayerDisplay::getAssets(assMan)); vectorAppend(&assets, &VNPenny::getAssets(assMan)); + assets.push_back(assMan->get("texture_tavern_night")); + return assets; } void stage() override { // Camera auto camera = Camera::create(this); - camera->transform->lookAt(glm::vec3(50, 50, 50), glm::vec3(0, 0, 0)); + camera->transform->lookAtPixelPerfect( + glm::vec3(0, 0, 0), + glm::vec3(0, 0, 0), + 1.0f, + camera->fov + ); // UI auto canvas = UICanvas::createCanvas(this); auto textbox = PokerGameTextbox::create(canvas); + auto background = SimpleVisualNovelBackground::create(this); // VN Manager auto vnManagerItem = this->createSceneItem(); @@ -64,9 +73,11 @@ namespace Dawn { auto vnFader = VisualNovelFader::create(canvas); + auto texture = this->game->assetManager.get("texture_tavern_night"); + auto betting = vnManager - ->setEvent(new VisualNovelFadeEvent( - vnManager, COLOR_BLACK, true, &easeOutCubic, 0.0f + ->setEvent(new VisualNovelChangeSimpleBackgroundEvent( + vnManager, &texture->texture )) ->then(new VisualNovelPauseEvent(vnManager, 1.0f)) ->then(new VisualNovelFadeEvent(