demo skybox
This commit is contained in:
@@ -30,6 +30,7 @@ void GameState::onStart() {
|
||||
|
||||
player = new Player(engine);
|
||||
terrain = new Terrain(&engine->renderer.core.texture.repository);
|
||||
skybox = new Skybox(&engine->renderer.core.texture.repository);
|
||||
dbgObj = new DebugObject(&engine->renderer.core.texture.repository);
|
||||
|
||||
initialized = true;
|
||||
@@ -40,6 +41,7 @@ GlobalStateType GameState::onFinish() {
|
||||
|
||||
delete player;
|
||||
delete terrain;
|
||||
delete skybox;
|
||||
delete dbgObj;
|
||||
initialized = false;
|
||||
|
||||
@@ -54,10 +56,8 @@ void GameState::update() {
|
||||
|
||||
// TODO: Get next player position and calculate all stuf for NEXT position
|
||||
// (not current!)
|
||||
// TODO: Fix camera for heightmap
|
||||
// TODO: Change map
|
||||
// TODO: Implement collision
|
||||
|
||||
skybox->update(player->getPosition());
|
||||
auto cameraInfo = player->getCameraInfo();
|
||||
engine->renderer.beginFrame(cameraInfo);
|
||||
|
||||
@@ -68,6 +68,7 @@ void GameState::update() {
|
||||
|
||||
renderer.clear();
|
||||
{
|
||||
renderer.add(skybox->pair);
|
||||
renderer.add(player->staticPairs);
|
||||
renderer.add(player->dynamicPairs);
|
||||
renderer.add(terrain->pair);
|
||||
|
||||
@@ -40,9 +40,10 @@ void Camera::update(const Vec4& playerPosition, const float& terrainHeight) {
|
||||
}
|
||||
|
||||
unitCircle.x = (sin(circleRotation) * lengthFromOrigin);
|
||||
unitCircle.y = height + playerPosition.y + terrainHeight;
|
||||
unitCircle.y = height;
|
||||
unitCircle.z = (cos(circleRotation) * lengthFromOrigin);
|
||||
|
||||
position = playerPosition;
|
||||
lookAt = unitCircle + playerPosition;
|
||||
}
|
||||
|
||||
|
||||
@@ -101,7 +101,8 @@ Weapon::~Weapon() {
|
||||
|
||||
void Weapon::allocateOptions() {
|
||||
options = new StaPipOptions();
|
||||
options->shadingType = Tyra::TyraShadingGouraud;
|
||||
options->textureMappingType = Tyra::TyraNearest;
|
||||
options->shadingType = Tyra::TyraShadingFlat;
|
||||
options->blendingEnabled = false;
|
||||
options->fullClipChecks = false;
|
||||
options->frustumCulling = Tyra::PipelineFrustumCulling_None;
|
||||
|
||||
@@ -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
|
||||
@@ -18,7 +18,7 @@ using Tyra::TyrobjLoader;
|
||||
namespace Demo {
|
||||
Terrain::Terrain(TextureRepository* repo)
|
||||
: heightmap(-5.0F, // Min height
|
||||
70.0F, // Max height
|
||||
100.0F, // Max height
|
||||
Vec4(-196.6F, 0.0F, -412.0F, 1.0F), // Left up
|
||||
Vec4(286.0F, 0.0F, 443.3F, 1.0F) // Right down
|
||||
) {
|
||||
|
||||
Reference in New Issue
Block a user