Merge branch 'salmon' of github.com:mephi1984/ZeptoLabTest1 into salmon
This commit is contained in:
commit
87032466ac
@ -1,6 +1,8 @@
|
||||
#pragma once
|
||||
#include "TextureManager.h"
|
||||
#include "Math.h"
|
||||
#include <unordered_map>
|
||||
|
||||
#include <memory>
|
||||
|
||||
namespace ZL {
|
||||
@ -20,15 +22,17 @@ struct ActiveObject {
|
||||
|
||||
class ActiveObjectManager {
|
||||
public:
|
||||
std::unordered_map<std::string, ActiveObject> activeObjectsEntities;
|
||||
|
||||
// Добавить или обновить объект в контейнере
|
||||
void addActiveObject(const ActiveObject& object) {
|
||||
activeObjects[object.name] = object;
|
||||
activeObjectsEntities[object.name] = object;
|
||||
}
|
||||
|
||||
// Найти объект по имени (возвращает указатель, nullptr — если не найден)
|
||||
ActiveObject* findByName(const std::string& name) {
|
||||
auto it = activeObjects.find(name);
|
||||
if (it != activeObjects.end()) {
|
||||
auto it = activeObjectsEntities.find(name);
|
||||
if (it != activeObjectsEntities.end()) {
|
||||
return &it->second;
|
||||
}
|
||||
return nullptr;
|
||||
@ -36,10 +40,11 @@ class ActiveObjectManager {
|
||||
|
||||
// Найти все объекты с нужным значением highlighted
|
||||
// (возвращает список указателей на найденные объекты)
|
||||
std::vector<ActiveObject*> findByHighlighted(bool highlighted) {
|
||||
std::vector<ActiveObject*> result;
|
||||
result.reserve(activeObjects.size());
|
||||
for (auto& [key, object] : activeObjects) {
|
||||
// ActiveObject.h
|
||||
std::vector<const ActiveObject*> findByHighlighted(bool highlighted) const {
|
||||
std::vector<const ActiveObject*> result;
|
||||
result.reserve(activeObjectsEntities.size());
|
||||
for (const auto& [key, object] : activeObjectsEntities) { // const auto&
|
||||
if (object.highlighted == highlighted) {
|
||||
result.push_back(&object);
|
||||
}
|
||||
@ -47,9 +52,10 @@ class ActiveObjectManager {
|
||||
return result;
|
||||
}
|
||||
|
||||
private:
|
||||
// Хранение объектов по ключу name
|
||||
std::unordered_map<std::string, ActiveObject> activeObjects;
|
||||
};
|
||||
|
||||
|
||||
void removeByName(const std::string& name) {
|
||||
activeObjectsEntities.erase(name);
|
||||
}
|
||||
};
|
||||
}
|
||||
|
||||
@ -279,7 +279,7 @@ namespace ZL
|
||||
{
|
||||
std::getline(f, tempLine); //Group: 'Bone', Weight: 0.9929084181785583
|
||||
if (std::regex_search(tempLine, match, pattern_bone_weight)) {
|
||||
// Èçâëåêàåì ñëîâî (áåç êàâû÷åê)
|
||||
// <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD> (<28><><EFBFBD> <20><><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>)
|
||||
std::string word = match.str(1);
|
||||
double weight = std::stod(match.str(2));
|
||||
|
||||
@ -527,12 +527,11 @@ namespace ZL
|
||||
|
||||
if (abs(finalPos.v[0] - originalPos.v[0]) > 1 || abs(finalPos.v[1] - originalPos.v[1]) > 1 || abs(finalPos.v[2] - originalPos.v[2]) > 1)
|
||||
{
|
||||
//std::cout << "Hello!" << std::endl;
|
||||
|
||||
}
|
||||
|
||||
if (!vMoved)
|
||||
{
|
||||
//std::cout << "Hello!" << std::endl;
|
||||
finalPos = originalPos;
|
||||
}
|
||||
|
||||
|
||||
@ -27,9 +27,10 @@ void GameObjectManager::initialize() {
|
||||
testObjMeshMutable.data = testObjMesh;
|
||||
testObjMeshMutable.RefreshVBO();
|
||||
|
||||
textMesh = ZL::LoadFromTextFile("./mesh001.txt"); // Add ZL:: namespace
|
||||
textMesh = ZL::LoadFromTextFile("./mesh_first_room.txt"); // Add ZL:: namespace
|
||||
coneMesh = ZL::LoadFromTextFile("./cone001.txt"); // Add ZL:: namespace
|
||||
coneMesh.Scale(200);
|
||||
textMesh.Scale(20);
|
||||
|
||||
textMeshMutable.AssignFrom(textMesh);
|
||||
textMeshMutable.RefreshVBO();
|
||||
@ -80,6 +81,7 @@ void GameObjectManager::initialize() {
|
||||
room_1.sound_name = "Symphony No.6 (1st movement).ogg";
|
||||
room_1.roomLogic = createRoom1Logic();
|
||||
rooms.push_back(room_1);
|
||||
aoMgr.addActiveObject(ao1);
|
||||
|
||||
Room room_2;
|
||||
room_2.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./background.bmp"));
|
||||
@ -136,14 +138,16 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
||||
switch_room(1);
|
||||
}
|
||||
else if (event.type == SDL_MOUSEBUTTONDOWN) {
|
||||
for (size_t i = 0; i < activeObjects.size(); ++i) {
|
||||
auto& ao = activeObjects[i];
|
||||
if (ao.highlighted) {
|
||||
AddItemToInventory(ao.name, ao.activeObjectTexturePtr);
|
||||
activeObjects.erase(activeObjects.begin() + i);
|
||||
// Можно выйти из цикла, если объект удален, чтобы избежать ошибок индексации.
|
||||
break;
|
||||
const auto highlightedObjects = aoMgr.findByHighlighted(true);
|
||||
|
||||
for (auto* ao : highlightedObjects) {
|
||||
if (!ao) {
|
||||
continue;
|
||||
}
|
||||
|
||||
AddItemToInventory(ao->name, ao->activeObjectTexturePtr);
|
||||
|
||||
aoMgr.removeByName(ao->name);
|
||||
}
|
||||
// bx.Interpolate(animationCounter);
|
||||
// animationCounter += 2;
|
||||
@ -362,16 +366,16 @@ void GameObjectManager::updateScene(size_t ms) {
|
||||
Environment::characterPos.v[1] = -Environment::cameraShift.v[1];
|
||||
Environment::characterPos.v[2] = -Environment::cameraShift.v[2];
|
||||
|
||||
for (auto& ao : activeObjects) {
|
||||
for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
|
||||
float dist = sqrtf(
|
||||
pow(Environment::characterPos.v[0] - ao.objectPos.v[0], 2) +
|
||||
pow(Environment::characterPos.v[1] - ao.objectPos.v[1], 2) +
|
||||
pow(Environment::characterPos.v[2] - ao.objectPos.v[2], 2)
|
||||
pow(Environment::characterPos.v[0] - obj.objectPos.v[0], 2) +
|
||||
pow(Environment::characterPos.v[1] - obj.objectPos.v[1], 2) +
|
||||
pow(Environment::characterPos.v[2] - obj.objectPos.v[2], 2)
|
||||
);
|
||||
ao.highlighted = (dist < 50.f);
|
||||
|
||||
obj.highlighted = (dist < 50.f);
|
||||
}
|
||||
|
||||
|
||||
if (rooms[current_room_index].roomLogic) {
|
||||
rooms[current_room_index].roomLogic(*this, ms);
|
||||
}
|
||||
|
||||
@ -54,6 +54,7 @@ public:
|
||||
|
||||
static const float INVENTORY_ICON_SIZE;
|
||||
static const float INVENTORY_MARGIN;
|
||||
ActiveObjectManager aoMgr;
|
||||
|
||||
private:
|
||||
//int animationCounter = 0;
|
||||
|
||||
@ -32,7 +32,7 @@ void RenderSystem::drawScene(GameObjectManager& gameObjects) {
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
*/
|
||||
drawWorld(gameObjects);
|
||||
//drawUI(gameObjects);
|
||||
drawUI(gameObjects);
|
||||
|
||||
/*renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
@ -177,59 +177,70 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
||||
}
|
||||
|
||||
void RenderSystem::drawUI(const GameObjectManager& gameObjects) {
|
||||
renderer.PushProjectionMatrix(static_cast<float>(Environment::width),
|
||||
// Устанавливаем нужный шейдер для UI (например, "default")
|
||||
renderer.shaderManager.PushShader("default");
|
||||
|
||||
// Если шейдер ожидает атрибуты вершин, их нужно включить
|
||||
static const std::string vPositionName = "vPosition";
|
||||
static const std::string vTexCoordName = "vTexCoord";
|
||||
renderer.EnableVertexAttribArray(vPositionName);
|
||||
renderer.EnableVertexAttribArray(vTexCoordName);
|
||||
|
||||
renderer.PushProjectionMatrix(static_cast<float>(Environment::width),
|
||||
static_cast<float>(Environment::height));
|
||||
renderer.PushMatrix();
|
||||
renderer.LoadIdentity();
|
||||
|
||||
// Draw highlighted objects UI
|
||||
for (const auto& ao : gameObjects.activeObjects) {
|
||||
if (ao.highlighted) {
|
||||
if (ao.activeObjectScreenTexturePtr){
|
||||
int screenX, screenY;
|
||||
worldToScreenCoordinates(ao.objectPos, currentProjectionModelView,
|
||||
Environment::width, Environment::height, screenX, screenY);
|
||||
renderer.PushMatrix();
|
||||
renderer.TranslateMatrix(Vector3f{screenX + 0.f, screenY + 0.f, 0.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, ao.activeObjectScreenTexturePtr->getTexID());
|
||||
renderer.DrawVertexRenderStruct(ao.activeObjectScreenMeshMutable);
|
||||
renderer.PopMatrix();
|
||||
} else {}
|
||||
}
|
||||
for (const auto* ao : gameObjects.aoMgr.findByHighlighted(true)) {
|
||||
std::cout << ao->name << std::endl;
|
||||
std::cout << "Draw" << std::endl;
|
||||
if (ao->activeObjectScreenTexturePtr) {
|
||||
std::cout << "Found activeObjectScreenTexturePtr" << std::endl;
|
||||
int screenX, screenY;
|
||||
worldToScreenCoordinates(ao->objectPos, currentProjectionModelView,
|
||||
Environment::width, Environment::height, screenX, screenY);
|
||||
renderer.PushMatrix();
|
||||
// Здесь можно использовать вычисленные screenX, screenY,
|
||||
// но для теста оставляем фиксированное значение
|
||||
renderer.TranslateMatrix(Vector3f{screenX + 0.f, screenY + 0.f, 0.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, ao->activeObjectScreenTexturePtr->getTexID());
|
||||
renderer.DrawVertexRenderStruct(ao->activeObjectScreenMeshMutable);
|
||||
renderer.PopMatrix();
|
||||
}
|
||||
}
|
||||
|
||||
const auto& inventoryMap = ZL::ReturnInventory();
|
||||
const auto& inventoryMap = ZL::ReturnInventory();
|
||||
int i = 0;
|
||||
for (const auto& [name, item] : inventoryMap) {
|
||||
renderer.PushMatrix();
|
||||
|
||||
// Заводим счётчик i, чтобы вычислять позицию иконки
|
||||
int i = 0;
|
||||
float xPos = Environment::width
|
||||
- gameObjects.INVENTORY_MARGIN
|
||||
- gameObjects.INVENTORY_ICON_SIZE;
|
||||
float yPos = gameObjects.INVENTORY_MARGIN
|
||||
+ i * (gameObjects.INVENTORY_ICON_SIZE
|
||||
+ gameObjects.INVENTORY_MARGIN);
|
||||
|
||||
// Итерируемся по всем предметам,
|
||||
for (const auto& [name, item] : inventoryMap) {
|
||||
renderer.PushMatrix();
|
||||
|
||||
float xPos = Environment::width
|
||||
- gameObjects.INVENTORY_MARGIN
|
||||
- gameObjects.INVENTORY_ICON_SIZE;
|
||||
float yPos = gameObjects.INVENTORY_MARGIN
|
||||
+ i * (gameObjects.INVENTORY_ICON_SIZE
|
||||
+ gameObjects.INVENTORY_MARGIN);
|
||||
|
||||
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
|
||||
|
||||
// item.texture->getTexID() – сам текстурный ID
|
||||
glBindTexture(GL_TEXTURE_2D, item.texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(gameObjects.inventoryIconMeshMutable);
|
||||
|
||||
renderer.PopMatrix();
|
||||
|
||||
i++;
|
||||
}
|
||||
renderer.TranslateMatrix(Vector3f{xPos, yPos, 0.0f});
|
||||
glBindTexture(GL_TEXTURE_2D, item.texture->getTexID());
|
||||
renderer.DrawVertexRenderStruct(gameObjects.inventoryIconMeshMutable);
|
||||
|
||||
renderer.PopMatrix();
|
||||
i++;
|
||||
}
|
||||
|
||||
renderer.PopMatrix();
|
||||
renderer.PopProjectionMatrix();
|
||||
|
||||
// Выключаем атрибуты, чтобы сохранить баланс
|
||||
renderer.DisableVertexAttribArray(vPositionName);
|
||||
renderer.DisableVertexAttribArray(vTexCoordName);
|
||||
|
||||
// Снимаем шейдер, тем самым балансируя стек
|
||||
renderer.shaderManager.PopShader();
|
||||
}
|
||||
|
||||
|
||||
void RenderSystem::worldToScreenCoordinates(Vector3f objectPos,
|
||||
Matrix4f projectionModelView,
|
||||
int screenWidth, int screenHeight,
|
||||
|
||||
@ -1,5 +1,6 @@
|
||||
#pragma once
|
||||
#include "Renderer.h"
|
||||
#include "ActiveObject.h"
|
||||
#include "GameObjectManager.h"
|
||||
#include <string>
|
||||
|
||||
|
||||
4833
mesh_first_room.txt
Normal file
4833
mesh_first_room.txt
Normal file
File diff suppressed because it is too large
Load Diff
Loading…
Reference in New Issue
Block a user