Background test

This commit is contained in:
2022-12-13 23:30:19 -08:00
parent 41a85a0553
commit 850f4c227d
12 changed files with 138 additions and 27 deletions

View File

@ -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
);

View File

@ -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;

View File

@ -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.

View File

@ -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
);
}

View File

@ -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);
};
}

View File

@ -10,4 +10,5 @@ target_sources(${DAWN_TARGET_NAME}
VisualNovelFadeEvent.cpp
VisualNovelPauseEvent.cpp
VisualNovelTextboxEvent.cpp
VisualNovelChangeSimpleBackgroundEvent.cpp
)

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "VisualNovelAnimationEvent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;

View File

@ -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() {
}

View File

@ -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(

View File

@ -4,6 +4,7 @@
// https://opensource.org/licenses/MIT
#include "VisualNovelPauseEvent.hpp"
#include "game/DawnGame.hpp"
using namespace Dawn;