Background test
This commit is contained in:
@ -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
|
||||
);
|
||||
|
@ -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;
|
||||
|
@ -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.
|
||||
|
@ -7,6 +7,15 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SimpleVisualNovelBackground * SimpleVisualNovelBackground::create(Scene *s) {
|
||||
auto item = s->createSceneItem();
|
||||
item->addComponent<MeshRenderer>();
|
||||
item->addComponent<MeshHost>();
|
||||
item->addComponent<Material>();
|
||||
auto background = item->addComponent<SimpleVisualNovelBackground>();
|
||||
return background;
|
||||
}
|
||||
|
||||
SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
@ -15,11 +24,32 @@ SimpleVisualNovelBackground::SimpleVisualNovelBackground(SceneItem *item) :
|
||||
|
||||
std::vector<SceneItemComponent*> SimpleVisualNovelBackground::getDependencies(){
|
||||
return std::vector<SceneItemComponent*>{
|
||||
this->meshHost = this->item->getComponent<MeshHost>(),
|
||||
this->material = this->item->getComponent<Material>()
|
||||
this->material = this->item->getComponent<Material>(),
|
||||
this->meshHost = this->item->getComponent<MeshHost>()
|
||||
};
|
||||
}
|
||||
|
||||
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
|
||||
);
|
||||
}
|
@ -12,8 +12,11 @@ namespace Dawn {
|
||||
Material *material;
|
||||
MeshHost *meshHost;
|
||||
|
||||
static SimpleVisualNovelBackground * create(Scene *scene);
|
||||
|
||||
SimpleVisualNovelBackground(SceneItem *item);
|
||||
std::vector<SceneItemComponent*> getDependencies() override;
|
||||
void onStart() override;
|
||||
void setTexture(Texture *texture);
|
||||
};
|
||||
}
|
@ -10,4 +10,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
VisualNovelFadeEvent.cpp
|
||||
VisualNovelPauseEvent.cpp
|
||||
VisualNovelTextboxEvent.cpp
|
||||
VisualNovelChangeSimpleBackgroundEvent.cpp
|
||||
)
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelAnimationEvent.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
|
@ -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<SimpleVisualNovelBackground>()
|
||||
;
|
||||
|
||||
assertNotNull(back);
|
||||
back->setTexture(this->texture);
|
||||
}
|
||||
|
||||
bool_t VisualNovelChangeSimpleBackgroundEvent::onUpdate() {
|
||||
return false;
|
||||
}
|
||||
|
||||
void VisualNovelChangeSimpleBackgroundEvent::onEnd() {
|
||||
|
||||
}
|
@ -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(
|
||||
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "VisualNovelPauseEvent.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
|
@ -25,25 +25,27 @@ namespace Dawn {
|
||||
auto textureAsset = scene->game->assetManager.get<TextureAsset>("texture_penny");
|
||||
auto tilesetAsset = scene->game->assetManager.get<TilesetAsset>("tileset_penny");
|
||||
|
||||
auto meshRenderer = item->addComponent<MeshRenderer>();
|
||||
auto material = item->addComponent<Material>();
|
||||
auto meshHost = item->addComponent<MeshHost>();
|
||||
auto tiledSprite = item->addComponent<TiledSprite>();
|
||||
// auto meshRenderer = item->addComponent<MeshRenderer>();
|
||||
// auto material = item->addComponent<Material>();
|
||||
// auto meshHost = item->addComponent<MeshHost>();
|
||||
// auto tiledSprite = item->addComponent<TiledSprite>();
|
||||
// auto animation = item->addComponent<AnimationController>();
|
||||
auto pokerPlayer = item->addComponent<PokerPlayer>();
|
||||
auto animation = item->addComponent<AnimationController>();
|
||||
|
||||
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;
|
||||
}
|
||||
};
|
||||
}
|
@ -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<TextureAsset>("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<TextureAsset>("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(
|
||||
|
Reference in New Issue
Block a user