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
.vscode/
# User-specific files
*.rsuser
*.suo

View File

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

View File

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

View File

@ -8,30 +8,34 @@
namespace ZL
{
static const int MAX_INVENTORY_SLOTS = 9;
static const float SELECTED_ITEM_SCALE = 1.2f; // Scale factor for selected items
struct InventoryItem
{
std::string name;
std::shared_ptr<Texture> texture;
bool isSelected = false;
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)
InventoryItem* GetItemByName(const std::string& name);
// Поиск предмета по индексу (возвращает указатель или nullptr)
InventoryItem* GetItemByIndex(int slot_index);
// Вывести весь инвентарь в консоль
void PrintInventory();
const std::unordered_map<std::string, InventoryItem>& ReturnInventory();
const std::unordered_map<int, InventoryItem>& ReturnInventory();
// Add these new functions
void UnselectAllItems();

View File

@ -7,33 +7,7 @@ uniform vec3 targetPos; // Цель камеры
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;
vec3 dirToCamera = normalize(eyePos - targetPos);
@ -46,7 +20,7 @@ void main()
//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);
discard;
@ -54,8 +28,7 @@ void main()
else
{
color.rgb = texture2D(Texture, texCoord).rgb;
//color.rgb = vec3(clamp(vWorldPos.z/500, 0, 1), 0, 0);
color.a = 1;
color.a = 1.0;
}
gl_FragColor = color;
}