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