other fixes
This commit is contained in:
@@ -13,6 +13,7 @@
|
||||
#include <renderer/3d/mesh/dynamic/dynamic_mesh.hpp>
|
||||
#include <renderer/3d/pipeline/dynamic/dynpip_options.hpp>
|
||||
#include "states/game/renderer/renderer_dynamic_pair.hpp"
|
||||
#include "states/game/terrain/heightmap.hpp"
|
||||
#include <renderer/renderer.hpp>
|
||||
|
||||
using Tyra::DynamicMesh;
|
||||
@@ -28,14 +29,14 @@ class Enemy {
|
||||
Enemy(TextureRepository* repo);
|
||||
~Enemy();
|
||||
|
||||
DynamicMesh* bodyMesh;
|
||||
DynamicMesh* gunMesh;
|
||||
DynamicMesh* mesh;
|
||||
DynPipOptions* options;
|
||||
std::vector<RendererDynamicPair*> pairs;
|
||||
RendererDynamicPair* pair;
|
||||
|
||||
void update(const Vec4& playerPosition);
|
||||
void update(const Heightmap& heightmap, const Vec4& playerPosition);
|
||||
|
||||
private:
|
||||
Vec4 direction;
|
||||
void allocateOptions();
|
||||
};
|
||||
|
||||
|
||||
@@ -23,7 +23,9 @@ class Heightmap {
|
||||
const Vec4& rightDown);
|
||||
~Heightmap();
|
||||
|
||||
const float& getHeightOffset(const Vec4& playerPosition);
|
||||
const float& getHeightOffset(const Vec4& playerPosition) const;
|
||||
|
||||
bool isOutside(const Vec4& position) const;
|
||||
|
||||
float** map;
|
||||
s16 mapWidth, mapHeight;
|
||||
@@ -31,12 +33,12 @@ class Heightmap {
|
||||
Vec4 leftUp, rightDown;
|
||||
|
||||
private:
|
||||
float getWidthPercentage(const Vec4& playerPosition);
|
||||
float getHeightPercentage(const Vec4& playerPosition);
|
||||
float getWidthPercentage(const Vec4& playerPosition) const;
|
||||
float getHeightPercentage(const Vec4& playerPosition) const;
|
||||
void allocateMap(const unsigned char* data, const int& width,
|
||||
const int& height);
|
||||
float getGameHeight(const u8& inputColor, const u8& minColor,
|
||||
const u8& maxColor);
|
||||
const u8& maxColor) const;
|
||||
};
|
||||
|
||||
} // namespace Demo
|
||||
|
||||
@@ -19,45 +19,55 @@ using Tyra::ObjLoaderOptions;
|
||||
namespace Demo {
|
||||
|
||||
Enemy::Enemy(TextureRepository* repo) {
|
||||
// ObjLoader loader;
|
||||
ObjLoader loader;
|
||||
|
||||
// ObjLoaderOptions objOptions;
|
||||
// objOptions.animation.count = 4;
|
||||
// objOptions.flipUVs = true;
|
||||
// objOptions.scale = 35.0F;
|
||||
ObjLoaderOptions objOptions;
|
||||
objOptions.animation.count = 4;
|
||||
objOptions.flipUVs = true;
|
||||
objOptions.scale = 60.0F;
|
||||
|
||||
// auto* bodyData = loader.load(
|
||||
// FileUtils::fromCwd("game/models/soldier/soldier.obj"), objOptions);
|
||||
// bodyData->normalsEnabled = false;
|
||||
// bodyMesh = new DynamicMesh(*bodyData);
|
||||
auto* data = loader.load(
|
||||
FileUtils::fromCwd("game/models/soldier/soldier.obj"), objOptions);
|
||||
data->normalsEnabled = false;
|
||||
mesh = new DynamicMesh(*data);
|
||||
|
||||
// delete bodyData;
|
||||
delete data;
|
||||
|
||||
// bodyMesh->playAnimation(0, bodyMesh->frames.size() - 1);
|
||||
// bodyMesh->setAnimSpeed(0.1F);
|
||||
mesh->playAnimation(0, mesh->frames.size() - 1);
|
||||
mesh->setAnimSpeed(0.1F);
|
||||
|
||||
// repo->addByMesh(bodyMesh, FileUtils::fromCwd("game/models/soldier/"),
|
||||
// "png");
|
||||
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/soldier/"), "png");
|
||||
|
||||
// bodyMesh->translation.translateY(-5.0F);
|
||||
mesh->translation.translateY(-5.0F);
|
||||
|
||||
// allocateOptions();
|
||||
allocateOptions();
|
||||
|
||||
// pairs.push_back(new RendererDynamicPair{bodyMesh, options});
|
||||
// // pairs.push_back(new RendererDynamicPair{gunMesh, options});
|
||||
pair = new RendererDynamicPair{mesh, options};
|
||||
|
||||
direction = Vec4(1.0F, 0.0F, 1.0F, 0.0F);
|
||||
}
|
||||
|
||||
Enemy::~Enemy() {
|
||||
delete bodyMesh;
|
||||
// delete gunMesh;
|
||||
delete mesh;
|
||||
delete options;
|
||||
for (auto* pair : pairs) {
|
||||
delete pair;
|
||||
}
|
||||
delete pair;
|
||||
}
|
||||
|
||||
void Enemy::update(const Vec4& playerPosition) {
|
||||
// bodyMesh->animate();
|
||||
void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition) {
|
||||
auto* pos = mesh->getPosition();
|
||||
auto nextPos = *pos + direction;
|
||||
|
||||
if (heightmap.isOutside(nextPos)) {
|
||||
direction.x = -direction.x;
|
||||
direction.z = -direction.z;
|
||||
}
|
||||
|
||||
nextPos = *pos + direction;
|
||||
nextPos.y = heightmap.getHeightOffset(nextPos) - 150.0F;
|
||||
mesh->translation.identity();
|
||||
mesh->translation.translate(nextPos);
|
||||
|
||||
mesh->animate();
|
||||
}
|
||||
|
||||
void Enemy::allocateOptions() { options = new DynPipOptions(); }
|
||||
|
||||
@@ -69,17 +69,16 @@ void GameState::update() {
|
||||
engine->renderer.beginFrame(cameraInfo);
|
||||
|
||||
dbgObj->setPosition(*cameraInfo.looksAt);
|
||||
float terrainHeight = 0.0F;
|
||||
// float terrainHeight = terrain->getHeightOffset(player->getPosition());
|
||||
float terrainHeight = terrain->getHeightOffset(player->getPosition());
|
||||
player->update(terrainHeight);
|
||||
enemy->update(player->getPosition());
|
||||
enemy->update(terrain->heightmap, player->getPosition());
|
||||
|
||||
renderer.clear();
|
||||
{
|
||||
renderer.add(skybox->pair);
|
||||
renderer.add(player->pair);
|
||||
// renderer.add(enemy->pairs);
|
||||
// renderer.add(terrain->pair);
|
||||
renderer.add(enemy->pair);
|
||||
renderer.add(terrain->pair);
|
||||
renderer.add(dbgObj->pair);
|
||||
}
|
||||
renderer.render();
|
||||
|
||||
@@ -37,7 +37,7 @@ void Player::handlePlayerPosition(const float& terrainHeight) {
|
||||
normalizedCamera *= speed;
|
||||
|
||||
Vec4 nextPosition(position);
|
||||
nextPosition.y = terrainHeight - 100.0F;
|
||||
nextPosition.y = terrainHeight - 60.0F;
|
||||
|
||||
if (leftJoy.v <= 100) {
|
||||
nextPosition.x += normalizedCamera.x;
|
||||
|
||||
@@ -34,6 +34,11 @@ Heightmap::Heightmap(const float& t_minHeight, const float& t_maxHeight,
|
||||
delete data;
|
||||
}
|
||||
|
||||
bool Heightmap::isOutside(const Vec4& position) const {
|
||||
return position.x <= leftUp.x || position.x >= rightDown.x ||
|
||||
position.z <= leftUp.z || position.z >= rightDown.z;
|
||||
}
|
||||
|
||||
Heightmap::~Heightmap() {
|
||||
if (map) {
|
||||
for (int i = 0; i < mapHeight; i++) {
|
||||
@@ -43,7 +48,7 @@ Heightmap::~Heightmap() {
|
||||
}
|
||||
}
|
||||
|
||||
const float& Heightmap::getHeightOffset(const Vec4& playerPosition) {
|
||||
const float& Heightmap::getHeightOffset(const Vec4& playerPosition) const {
|
||||
float widthPercentage = getWidthPercentage(playerPosition);
|
||||
float heightPercentage = getHeightPercentage(playerPosition);
|
||||
|
||||
@@ -56,11 +61,11 @@ const float& Heightmap::getHeightOffset(const Vec4& playerPosition) {
|
||||
return map[x][y];
|
||||
}
|
||||
|
||||
float Heightmap::getWidthPercentage(const Vec4& playerPosition) {
|
||||
float Heightmap::getWidthPercentage(const Vec4& playerPosition) const {
|
||||
return (playerPosition.x - leftUp.x) / (rightDown.x - leftUp.x);
|
||||
}
|
||||
|
||||
float Heightmap::getHeightPercentage(const Vec4& playerPosition) {
|
||||
float Heightmap::getHeightPercentage(const Vec4& playerPosition) const {
|
||||
return (playerPosition.z - leftUp.z) / (rightDown.z - leftUp.z);
|
||||
}
|
||||
|
||||
@@ -100,7 +105,7 @@ void Heightmap::allocateMap(const unsigned char* data, const int& width,
|
||||
}
|
||||
|
||||
float Heightmap::getGameHeight(const u8& inputColor, const u8& minColor,
|
||||
const u8& maxColor) {
|
||||
const u8& maxColor) const {
|
||||
const float mapRange = maxColor - minColor;
|
||||
const float gameRange = maxHeight - minHeight;
|
||||
|
||||
|
||||
@@ -18,29 +18,29 @@ using Tyra::ObjLoaderOptions;
|
||||
|
||||
namespace Demo {
|
||||
Terrain::Terrain(TextureRepository* repo)
|
||||
: heightmap(-5.0F, // Min height
|
||||
450.0F, // Max height
|
||||
Vec4(-784.6F, 0.0F, -1648.0F, 1.0F), // Left up
|
||||
Vec4(1144.0F, 0.0F, 1772.3F, 1.0F) // Right down
|
||||
: heightmap(20.0F, // Min height
|
||||
320.0F, // Max height
|
||||
Vec4(-750.0F, 0.0F, -1400.0F, 1.0F), // Left up
|
||||
Vec4(920.0F, 0.0F, 1520.0F, 1.0F) // Right down
|
||||
) {
|
||||
// ObjLoader loader;
|
||||
ObjLoader loader;
|
||||
|
||||
// ObjLoaderOptions objOptions;
|
||||
// objOptions.flipUVs = true;
|
||||
// objOptions.scale = 100.0F;
|
||||
ObjLoaderOptions objOptions;
|
||||
objOptions.flipUVs = true;
|
||||
objOptions.scale = 100.0F;
|
||||
|
||||
// auto* data = loader.load(
|
||||
// FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
||||
// data->normalsEnabled = false;
|
||||
// mesh = new StaticMesh(*data);
|
||||
auto* data = loader.load(
|
||||
FileUtils::fromCwd("game/models/terrain/terrain.obj"), objOptions);
|
||||
data->normalsEnabled = false;
|
||||
mesh = new StaticMesh(*data);
|
||||
|
||||
// delete data;
|
||||
delete data;
|
||||
|
||||
// repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
||||
repo->addByMesh(mesh, FileUtils::fromCwd("game/models/terrain/"), "png");
|
||||
|
||||
// allocateOptions();
|
||||
allocateOptions();
|
||||
|
||||
// pair = new RendererStaticPair{mesh, options};
|
||||
pair = new RendererStaticPair{mesh, options};
|
||||
}
|
||||
|
||||
float Terrain::getHeightOffset(const Vec4& playerPosition) {
|
||||
|
||||
Reference in New Issue
Block a user