resolved conflicts

This commit is contained in:
maka70vv 2025-03-02 18:25:55 +06:00
commit 512e912471
5 changed files with 44 additions and 68 deletions

2
.gitignore vendored
View File

@ -3,6 +3,8 @@
## ##
## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore ## Get latest from https://github.com/github/gitignore/blob/master/VisualStudio.gitignore
.vscode/
# User-specific files # User-specific files
*.rsuser *.rsuser
*.suo *.suo

View File

@ -28,7 +28,7 @@ void GameObjectManager::initialize() {
testObjMeshMutable.data = testObjMesh; testObjMeshMutable.data = testObjMesh;
testObjMeshMutable.RefreshVBO(); testObjMeshMutable.RefreshVBO();
textMesh = ZL::LoadFromTextFile("./textures/mesh_first_room.txt"); // Add ZL:: namespace textMesh = ZL::LoadFromTextFile("./textures/mesh_first_room.txt");
textMesh.Scale(10); textMesh.Scale(10);
textMesh.SwapZandY(); textMesh.SwapZandY();
textMesh.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundX(M_PI * 0.5))); textMesh.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundX(M_PI * 0.5)));
@ -269,13 +269,13 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
{ {
UnselectAllItems(); UnselectAllItems();
if (InventoryItem* item = GetItemByHotkey(event.key.keysym.sym - SDLK_1 + 1)) { if (InventoryItem* item = GetItemByHotkey(hot_key)) {
item->isSelected = true; item->isSelected = true;
std:: cout << item->name << std::endl;
} }
} }
break; break;
// ...handle other keys... // ...handle other keys...
} }
} }
@ -468,12 +468,14 @@ void GameObjectManager::updateScene(size_t ms) {
} }
bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const { bool GameObjectManager::isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const {
// Простая проверка попадания точки в квадрат 64x64 вокруг центра объекта const int baseObjectSize = 32; // Base half-size
const int objectSize = 32; // Половина размера области выделения const float scale = 1.0f; // Get scale from item if needed
return (screenX >= objectScreenX - objectSize && const int scaledObjectSize = static_cast<int>(baseObjectSize * scale);
screenX <= objectScreenX + objectSize &&
screenY >= objectScreenY - objectSize && return (screenX >= objectScreenX - scaledObjectSize &&
screenY <= objectScreenY + objectSize); screenX <= objectScreenX + scaledObjectSize &&
screenY >= objectScreenY - scaledObjectSize &&
screenY <= objectScreenY + scaledObjectSize);
} }
void GameObjectManager::checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView) { void GameObjectManager::checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView) {

View File

@ -2,47 +2,41 @@
namespace ZL namespace ZL
{ {
// Определяем глобальную переменную std::unordered_map<int, InventoryItem> gInventoryMap;
std::unordered_map<std::string, InventoryItem> gInventoryMap;
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int hot_key) void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int slot_index)
{ {
if (slot_index > MAX_INVENTORY_SLOTS || slot_index < 1) {
return;
}
InventoryItem item; InventoryItem item;
item.name = name; item.name = name;
item.texture = tex; item.texture = tex;
item.hot_key = hot_key; item.hot_key = slot_index;
item.scale = 1.0f;
// Вставляем или перезаписываем (operator[] так сделает). gInventoryMap[slot_index] = item;
gInventoryMap[name] = item; std::cout << "Added item to slot " << slot_index << std::endl;
} }
void RemoveItemFromInventory(const std::string& name) void RemoveItemFromInventory(int slot_index)
{ {
// erase вернёт количество удалённых элементов, если нужно проверить gInventoryMap.erase(slot_index);
gInventoryMap.erase(name);
} }
InventoryItem* GetItemByName(const std::string& name) InventoryItem* GetItemByIndex(int slot_index)
{ {
// Пытаемся найти элемент по ключу auto it = gInventoryMap.find(slot_index);
auto it = gInventoryMap.find(name); if (it != gInventoryMap.end()) {
if (it != gInventoryMap.end())
{
// Возвращаем адрес найденного InventoryItem
return &it->second; return &it->second;
} }
// Если не нашли nullptr
return nullptr; return nullptr;
} }
InventoryItem* GetItemByHotkey(int hotkey) InventoryItem* GetItemByHotkey(int hotkey)
{ {
for (auto& [_, item] : gInventoryMap) { return GetItemByIndex(hotkey); // Now we can just use the index directly
if (item.hot_key == hotkey) {
return &item;
}
}
return nullptr;
} }
InventoryItem* GetItemSelected(bool selected) InventoryItem* GetItemSelected(bool selected)
@ -68,10 +62,11 @@ namespace ZL
{ {
for (auto& [_, item] : gInventoryMap) { for (auto& [_, item] : gInventoryMap) {
item.isSelected = false; item.isSelected = false;
item.scale = 1.0f; // Reset scale when unselected
} }
} }
const std::unordered_map<std::string, InventoryItem>& ReturnInventory() const std::unordered_map<int, InventoryItem>& ReturnInventory()
{ {
return gInventoryMap; return gInventoryMap;
} }

View File

@ -8,30 +8,34 @@
namespace ZL namespace ZL
{ {
static const int MAX_INVENTORY_SLOTS = 9;
static const float SELECTED_ITEM_SCALE = 1.2f; // Scale factor for selected items
struct InventoryItem struct InventoryItem
{ {
std::string name; std::string name;
std::shared_ptr<Texture> texture; std::shared_ptr<Texture> texture;
bool isSelected = false; bool isSelected = false;
int hot_key; int hot_key;
float scale = 1.0f; // Add scale property
}; };
// Глобальное хранилище предметов // Глобальное хранилище предметов
extern std::unordered_map<std::string, InventoryItem> gInventoryMap; // Changed from gInventory extern std::unordered_map<int, InventoryItem> gInventoryMap; // Changed key type from string to int
// Добавить предмет в инвентарь // Добавить предмет в инвентарь
void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int hot_key); void AddItemToInventory(const std::string& name, std::shared_ptr<Texture> tex, int slot_index);
// Удалить предмет из инвентаря // Удалить предмет из инвентаря
void RemoveItemFromInventory(const std::string& name); void RemoveItemFromInventory(int slot_index);
// Поиск предмета по имени (возвращает указатель или nullptr) // Поиск предмета по индексу (возвращает указатель или nullptr)
InventoryItem* GetItemByName(const std::string& name); InventoryItem* GetItemByIndex(int slot_index);
// Вывести весь инвентарь в консоль // Вывести весь инвентарь в консоль
void PrintInventory(); void PrintInventory();
const std::unordered_map<std::string, InventoryItem>& ReturnInventory(); const std::unordered_map<int, InventoryItem>& ReturnInventory();
// Add these new functions // Add these new functions
void UnselectAllItems(); void UnselectAllItems();

View File

@ -7,33 +7,7 @@ uniform vec3 targetPos; // Цель камеры
void main() void main()
{ {
/*
float maxDistance = 2000;
float alpha = 0.0;
vec4 color = texture2D(Texture, texCoord);
vec3 dir = targetPos - eyePos;
float dirLengthSq = dot(dir, dir);
if (dirLengthSq > 0.0)
{
vec3 objToEye = vWorldPos - eyePos;
float t = dot(objToEye, dir) / dirLengthSq;
if (t >= 0.0 && t <= 1.0)
{
vec3 projection = eyePos + t * dir;
vec3 delta = vWorldPos - projection;
float distSq = dot(delta, delta);
if (distSq < maxDistance * maxDistance)
{
//color.a *= alpha; // Применяем прозрачность
color.rgb = vec3(1,0,0);
}
}
}
*/
vec4 color; vec4 color;
vec3 dirToCamera = normalize(eyePos - targetPos); vec3 dirToCamera = normalize(eyePos - targetPos);
@ -46,7 +20,7 @@ void main()
//float distanceToCamera = length(vWorldPos - targetPos); //float distanceToCamera = length(vWorldPos - targetPos);
if (/*(distanceX > 250 || distanceZ > 250) && */(dotProduct > 0.1) && vWorldPos.y > 30) if ((dotProduct > 0.1) && vWorldPos.y > 30.0)
{ {
//color.rgba = vec4(1,0,0,1); //color.rgba = vec4(1,0,0,1);
discard; discard;
@ -54,8 +28,7 @@ void main()
else else
{ {
color.rgb = texture2D(Texture, texCoord).rgb; color.rgb = texture2D(Texture, texCoord).rgb;
//color.rgb = vec3(clamp(vWorldPos.z/500, 0, 1), 0, 0); color.a = 1.0;
color.a = 1;
} }
gl_FragColor = color; gl_FragColor = color;
} }