demo buggy heightmap

This commit is contained in:
h4570
2022-08-01 10:04:21 +02:00
parent 47c323ec9e
commit 34b2956c08
12 changed files with 194 additions and 33 deletions
+1 -1
View File
@@ -31,7 +31,7 @@ class Camera {
CameraInfo3D getCameraInfo() { return CameraInfo3D(&position, &lookAt); }
void update(const Vec4& playerPosition);
void update(const Vec4& playerPosition, const float& terrainHeight);
private:
float circleRotation, lengthFromOrigin, height;
+4 -3
View File
@@ -27,17 +27,18 @@ class Player {
Player(Engine* engine);
~Player();
const Vec4& getPosition() const { return position; }
CameraInfo3D getCameraInfo() { return camera.getCameraInfo(); }
std::vector<RendererStaticPair*> staticPairs;
std::vector<RendererDynamicPair*> dynamicPairs;
void update();
void update(const float& terrainHeight);
private:
void handlePlayerPosition();
void handlePlayerPosition(const float& terrainHeight);
float speed;
float speed;
Pad* pad;
Vec4 position;
Weapon weapon;
@@ -0,0 +1,42 @@
/*
# ______ ____ ___
# | \/ ____| |___|
# | | | \ | |
#-----------------------------------------------------------------------
# Copyright 2022, tyra - https://github.com/h4570/tyra
# Licenced under Apache License 2.0
# Sandro Sobczyński <sandro.sobczynski@gmail.com>
*/
#pragma once
#include "math/vec4.hpp"
#include "loaders/texture/png_loader.hpp"
using Tyra::Vec4;
namespace Demo {
class Heightmap {
public:
Heightmap(const float& minHeight, const float& maxHeight, const Vec4& leftUp,
const Vec4& rightDown);
~Heightmap();
const float& getHeightOffset(const Vec4& playerPosition);
float** map;
s16 mapWidth, mapHeight;
float minHeight, maxHeight;
Vec4 leftUp, rightDown;
private:
float getWidthPercentage(const Vec4& playerPosition);
float getHeightPercentage(const Vec4& playerPosition);
void allocateMap(const unsigned char* data, const int& width,
const int& height);
float getGameHeight(const u8& inputColor, const u8& minColor,
const u8& maxColor);
};
} // namespace Demo
+4 -1
View File
@@ -14,10 +14,12 @@
#include <renderer/3d/pipeline/static/stapip_options.hpp>
#include "states/game/renderer/renderer_static_pair.hpp"
#include <renderer/renderer.hpp>
#include "./heightmap.hpp"
using Tyra::StaPipOptions;
using Tyra::StaticMesh;
using Tyra::TextureRepository;
using Tyra::Vec4;
namespace Demo {
@@ -26,11 +28,12 @@ class Terrain {
Terrain(TextureRepository* repo);
~Terrain();
Heightmap heightmap;
StaticMesh* mesh;
StaPipOptions* options;
RendererStaticPair* pair;
void update();
float getHeightOffset(const Vec4& playerPosition);
private:
void allocateOptions();