diff --git a/ROADMAP.txt b/ROADMAP.txt index 99a4446..d62dc53 100644 --- a/ROADMAP.txt +++ b/ROADMAP.txt @@ -37,6 +37,8 @@ because Mesh rendering uses only core.render() - [renderer] bbox parts optimization - [General] smart pointers and std::array instead of raw pointers - [md2] refactor +- [2D] Add zbuffer support (z-index) +- [3DUtility] Add zbuffer support (z-index) - [2D] Fixed font support - [File] Async file loading - [obj] Add multicolor support to obj diff --git a/demo/inc/states/game/enemy/enemy.hpp b/demo/inc/states/game/enemy/enemy.hpp index 387f267..e34013f 100644 --- a/demo/inc/states/game/enemy/enemy.hpp +++ b/demo/inc/states/game/enemy/enemy.hpp @@ -54,7 +54,6 @@ class Enemy { bool isFighting = false; Vec4 spawnPoint; - Renderer3DUtility* utility; Audio* audio; EnemyInfo info; }; diff --git a/demo/inc/states/game/player/player.hpp b/demo/inc/states/game/player/player.hpp index a2e92e7..1eb4b66 100644 --- a/demo/inc/states/game/player/player.hpp +++ b/demo/inc/states/game/player/player.hpp @@ -42,7 +42,6 @@ class Player { private: void handlePlayerPosition(const Heightmap& heightmap, const float& terrainHeight); - Renderer3DUtility* utility; float speed; Pad* pad; diff --git a/demo/src/states/game/enemy/enemy.cpp b/demo/src/states/game/enemy/enemy.cpp index de2cfe4..2acf169 100644 --- a/demo/src/states/game/enemy/enemy.cpp +++ b/demo/src/states/game/enemy/enemy.cpp @@ -11,13 +11,13 @@ #include "states/game/enemy/enemy.hpp" #include +using Tyra::Color; using Tyra::Math; namespace Demo { Enemy::Enemy(Engine* engine, const EnemyInfo& t_info) { info = t_info; - utility = &engine->renderer.renderer3D.utility; mesh = new DynamicMesh(*info.motherMesh); @@ -87,20 +87,23 @@ void Enemy::update(const Heightmap& heightmap, const Vec4& playerPosition, } void Enemy::handlePlayerShoot(const PlayerShootAction& shootAction) { - if (!shootAction.isShooting) { - return; - } + // if (!shootAction.isShooting) { + // return; + // } const auto& ray = shootAction.ray.value(); auto bbox = mesh->getCurrentBoundingBox().getTransformed(mesh->getModelMatrix()); - auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max()); + float length = -1.0F; + auto isOnEnemy = ray.intersectBox(bbox.min(), bbox.max(), &length); if (isOnEnemy) { mesh->setPosition(spawnPoint); TYRA_LOG("Enemy hit!"); + } else { + if (length != -1.0F) TYRA_LOG("Distance: ", length); } } diff --git a/demo/src/states/game/enemy/enemy_manager.cpp b/demo/src/states/game/enemy/enemy_manager.cpp index 251d635..94b882b 100644 --- a/demo/src/states/game/enemy/enemy_manager.cpp +++ b/demo/src/states/game/enemy/enemy_manager.cpp @@ -43,7 +43,7 @@ EnemyManager::EnemyManager(Engine* engine, const Heightmap& heightmap) { auto* sample = engine->audio.adpcm.load( FileUtils::fromCwd("game/models/zombie/punch.adpcm")); - const int enemyCount = 10; + const int enemyCount = 1; for (int i = 0; i < enemyCount; i++) { EnemyInfo info; info.adpcmChannel = 9 + i; diff --git a/demo/src/states/game/game_state.cpp b/demo/src/states/game/game_state.cpp index b3164f9..7d29555 100644 --- a/demo/src/states/game/game_state.cpp +++ b/demo/src/states/game/game_state.cpp @@ -85,6 +85,14 @@ void GameState::update() { renderer.add(terrain->pair); renderer.render(); + // Debug + auto& utility = engine->renderer.renderer3D.utility; + utility.drawBox(*player->getCameraInfo().looksAt, 0.3F); + + auto* firstEnemy = enemyManager->getPairs().front()->mesh; + utility.drawBBox(firstEnemy->getCurrentBoundingBox().getTransformed( + firstEnemy->getModelMatrix())); + // End frame engine->renderer.endFrame(); } diff --git a/demo/src/states/game/player/player.cpp b/demo/src/states/game/player/player.cpp index ade770c..49afe98 100644 --- a/demo/src/states/game/player/player.cpp +++ b/demo/src/states/game/player/player.cpp @@ -19,8 +19,6 @@ Player::Player(Engine* engine) position = Vec4(3.0F, 50.0F, 0.0F); camera.lookAt = Vec4(0.0F, 0.0F, -30.0F); speed = 5.0F; - - utility = &engine->renderer.renderer3D.utility; } Player::~Player() { delete pair; } @@ -37,14 +35,9 @@ PlayerShootAction Player::getShootAction() const { PlayerShootAction action; action.isShooting = weapon.isShooting; - if (action.isShooting) { - action.ray = Ray(camera.position, camera.lookAt.getNormalized()); - } - - utility->drawBox(camera.lookAt, 1.0F); - - // utility->drawLine(ray.origin, ray.direction); - utility->drawLine(camera.position + Vec4(0.0F, 1.0F, 0.0F), camera.lookAt); + // if (action.isShooting) { + action.ray = Ray(camera.position, camera.lookAt.getNormalized()); + // } return action; } diff --git a/engine/inc/renderer/3d/renderer_3d_utility.hpp b/engine/inc/renderer/3d/renderer_3d_utility.hpp index cb05fe4..d9f1782 100644 --- a/engine/inc/renderer/3d/renderer_3d_utility.hpp +++ b/engine/inc/renderer/3d/renderer_3d_utility.hpp @@ -19,10 +19,10 @@ namespace Tyra { /** - * Debug functions, with bad performance. + * Debug functions, without z buffer, with bad performance. * - * Remember that you need to use them AFTER ALLPASS rendering. - * (for example after skybox), otherwise colors will not work. + * Remember to use these functions AFTER all 3D rendering, + * otherwise lines will be overwritten! */ class Renderer3DUtility { public: diff --git a/engine/src/renderer/3d/renderer_3d_utility.cpp b/engine/src/renderer/3d/renderer_3d_utility.cpp index 275781d..6139b0b 100644 --- a/engine/src/renderer/3d/renderer_3d_utility.cpp +++ b/engine/src/renderer/3d/renderer_3d_utility.cpp @@ -65,7 +65,6 @@ void Renderer3DUtility::drawLine(const Vec4& from, const Vec4& to, const u8 vertCount = 2; const s8 thickness = 2; s16 packetSize = 8 * thickness; - prim.type = PRIM_LINE; auto gsColor = getGSColor(color); auto* packet = @@ -114,7 +113,6 @@ void Renderer3DUtility::drawBBox(const CoreBBox& v, const Color& color) { const u8 vertCount = 4; const s8 thickness = 2; s16 packetSize = 150 * thickness; - prim.type = PRIM_LINE; auto gsColor = getGSColor(color); auto* packet = @@ -284,13 +282,19 @@ bool Renderer3DUtility::calcLineVertices(xyz_t* outputArray, const Vec4& a, s32 centerY = ftoi4(2048 + displayOffset); const u32 maxZ = ftoi4(((float)0xFFFFFF) / 32.0F); - outputArray[0].x = (clippedVerts[0].position.x + 1.0F) * centerX; - outputArray[0].y = (clippedVerts[0].position.y + 1.0F) * centerY; - outputArray[0].z = (clippedVerts[0].position.z + 1.0F) * maxZ; + outputArray[0].x = + static_cast((clippedVerts[0].position.x + 1.0F) * centerX); + outputArray[0].y = + static_cast((clippedVerts[0].position.y + 1.0F) * centerY); + outputArray[0].z = + static_cast((clippedVerts[0].position.z + 1.0F) * maxZ); - outputArray[1].x = (clippedVerts[1].position.x + 1.0F) * centerX; - outputArray[1].y = (clippedVerts[1].position.y + 1.0F) * centerY; - outputArray[1].z = (clippedVerts[1].position.z + 1.0F) * maxZ; + outputArray[1].x = + static_cast((clippedVerts[1].position.x + 1.0F) * centerX); + outputArray[1].y = + static_cast((clippedVerts[1].position.y + 1.0F) * centerY); + outputArray[1].z = + static_cast((clippedVerts[1].position.z + 1.0F) * maxZ); return true; }