demo skybox

This commit is contained in:
h4570
2022-08-02 13:20:12 +02:00
parent cdadb932b7
commit 5aae7cff7e
11 changed files with 131 additions and 15 deletions
+66
View File
@@ -0,0 +1,66 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#include "states/game/skybox/skybox.hpp"
#include <loaders/3d/tyrobj/tyrobj_loader.hpp>
#include <file/file_utils.hpp>
using Tyra::FileUtils;
using Tyra::TyrobjLoader;
namespace Demo {
Skybox::Skybox(TextureRepository* repo) {
TyrobjLoader loader;
auto* data = loader.load(FileUtils::fromCwd("game/models/skybox/skybox.obj"),
1, 400.0F, true);
data->normalsEnabled = false;
mesh = new StaticMesh(*data);
delete data;
mesh->scale.scaleX(2.0F);
mesh->scale.scaleZ(2.0F);
for (u32 i = 0; i < mesh->getMaterialsCount(); i++) {
auto* material = mesh->getMaterial(i);
material->print();
material->color.r = 16.0F;
material->color.g = 16.0F;
material->color.b = 16.0F;
}
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/skybox/"), "png");
allocateOptions();
pair = new RendererStaticPair{mesh, options};
}
Skybox::~Skybox() {
delete mesh;
delete options;
delete pair;
}
void Skybox::update(const Vec4& playerPosition) {
mesh->translation.identity();
mesh->translation.translate(playerPosition);
}
void Skybox::allocateOptions() {
options = new StaPipOptions();
options->frustumCulling = Tyra::PipelineFrustumCulling_None;
options->shadingType = Tyra::TyraShadingGouraud;
options->textureMappingType = Tyra::TyraNearest;
options->blendingEnabled = true;
options->antiAliasingEnabled = false;
}
} // namespace Demo