kolliziya dobavlena 2 krovat

This commit is contained in:
Альберт Гадиев 2025-03-02 21:46:38 +06:00
parent c31139fdec
commit 60b610d111
3 changed files with 214 additions and 128 deletions

View File

@ -1,7 +1,18 @@
#pragma once #pragma once
#include "Math.h" #include "Math.h"
#include <vector>
#include <memory>
namespace ZL { namespace ZL {
// Базовый класс для всех коллизий
class Collidable {
public:
virtual bool checkCollision(const Vector3f& position) const = 0;
virtual ~Collidable() = default;
};
// Прямоугольная граница комнаты
class BoundaryBox { class BoundaryBox {
public: public:
BoundaryBox(float width, float height) BoundaryBox(float width, float height)
@ -17,4 +28,74 @@ private:
float halfWidth; float halfWidth;
float halfHeight; float halfHeight;
}; };
}
// Круглая коллизия для объектов
class CircleCollider : public Collidable {
public:
CircleCollider(const Vector3f& center, float radius)
: center(center)
, radius(radius) {}
bool checkCollision(const Vector3f& position) const override {
float dx = position.v[0] - center.v[0];
float dz = position.v[2] - center.v[2];
return (dx * dx + dz * dz) <= (radius * radius);
}
void setPosition(const Vector3f& newPos) { center = newPos; }
void setRadius(float newRadius) { radius = newRadius; }
private:
Vector3f center;
float radius;
};
// Прямоугольная коллизия для объектов
class RectangleCollider : public Collidable {
public:
RectangleCollider(const Vector3f& min, const Vector3f& max)
: minPoint(min)
, maxPoint(max) {}
bool checkCollision(const Vector3f& position) const override {
return (position.v[0] >= minPoint.v[0] && position.v[0] <= maxPoint.v[0] &&
position.v[2] >= minPoint.v[2] && position.v[2] <= maxPoint.v[2]);
}
private:
Vector3f minPoint;
Vector3f maxPoint;
};
// Менеджер коллизий
class CollisionManager {
public:
void setRoomBoundary(float width, float height) {
roomBoundary = std::make_unique<BoundaryBox>(width, height);
}
void addCollider(std::shared_ptr<Collidable> collider) {
colliders.push_back(collider);
}
bool checkCollision(const Vector3f& position) const {
// Проверяем границы комнаты
if (roomBoundary && !roomBoundary->isInside(position)) {
return true;
}
// Проверяем коллизии с объектами
for (const auto& collider : colliders) {
if (collider->checkCollision(position)) {
return true;
}
}
return false;
}
private:
std::unique_ptr<BoundaryBox> roomBoundary;
std::vector<std::shared_ptr<Collidable>> colliders;
};
} // namespace ZL

View File

@ -12,8 +12,8 @@ const float GameObjectManager::INVENTORY_MARGIN = 10.0f;
void GameObjectManager::initialize() { void GameObjectManager::initialize() {
current_room_index = 0; current_room_index = 0;
objects_in_inventory = 0; objects_in_inventory = 0;
coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp")); coneTexturePtr = std::make_shared<Texture>(CreateTextureDataFromBmp24("./conus.bmp"));
@ -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"); textMesh = ZL::LoadFromTextFile("./textures/mesh_first_room.txt"); // Add ZL:: namespace
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)));
@ -37,7 +37,6 @@ void GameObjectManager::initialize() {
coneMesh = ZL::LoadFromTextFile("./cone001.txt"); // Add ZL:: namespace coneMesh = ZL::LoadFromTextFile("./cone001.txt"); // Add ZL:: namespace
coneMesh.Scale(200); coneMesh.Scale(200);
textMeshMutable.AssignFrom(textMesh); textMeshMutable.AssignFrom(textMesh);
textMeshMutable.RefreshVBO(); textMeshMutable.RefreshVBO();
coneMeshMutable.AssignFrom(coneMesh); coneMeshMutable.AssignFrom(coneMesh);
@ -47,8 +46,8 @@ void GameObjectManager::initialize() {
//bx.LoadFromFile("./violetta001.txt"); //bx.LoadFromFile("./violetta001.txt");
violaIdleModel.LoadFromFile("./idleviola001.txt"); violaIdleModel.LoadFromFile("./idleviola001.txt");
violaWalkModel.LoadFromFile("./walkviolla001.txt"); violaWalkModel.LoadFromFile("./walkviolla001.txt");
// Create active object // Create active object
ActiveObject ao1; ActiveObject ao1;
ao1.name = "book"; ao1.name = "book";
ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace ao1.activeObjectMesh = ZL::LoadFromTextFile("./book001.txt"); // Add ZL:: namespace
@ -79,8 +78,6 @@ void GameObjectManager::initialize() {
ao2.activeObjectScreenMeshMutable.RefreshVBO(); ao2.activeObjectScreenMeshMutable.RefreshVBO();
*/ */
Room room_1; Room room_1;
room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")); room_1.roomTexture = std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp"));
room_1.objects.push_back(ao1); room_1.objects.push_back(ao1);
@ -92,7 +89,7 @@ void GameObjectManager::initialize() {
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"));
room_2.sound_name = "Symphony No.6 (1st movement).ogg"; room_2.sound_name = "Symphony No.6 (1st movement).ogg";
room_2.roomLogic = createRoom2Logic(); room_2.roomLogic = createRoom1Logic();
rooms.push_back(room_2); rooms.push_back(room_2);
activeObjects = rooms[current_room_index].objects; activeObjects = rooms[current_room_index].objects;
@ -119,9 +116,63 @@ void GameObjectManager::initialize() {
AddItemToInventory("book2", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory+1); AddItemToInventory("book2", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory+1);
objects_in_inventory++; objects_in_inventory++;
//SDL_ShowCursor(SDL_DISABLE); //SDL_ShowCursor(SDL_DISABLE);
SDL_SetRelativeMouseMode(SDL_TRUE); SDL_SetRelativeMouseMode(SDL_TRUE);
// Устанавливаем границы комнаты 800x800
collisionMgr.setRoomBoundary(800.0f, 800.0f);
// Создаем стены комнаты (толстые коллизии вдоль границ)
auto wallNorth = std::make_shared<CircleCollider>(Vector3f{0, 0, -350}, 50.0f);
auto wallSouth = std::make_shared<CircleCollider>(Vector3f{0, 0, 350}, 50.0f);
auto wallEast = std::make_shared<CircleCollider>(Vector3f{350, 0, 0}, 50.0f);
auto wallWest = std::make_shared<CircleCollider>(Vector3f{-350, 0, 0}, 50.0f);
collisionMgr.addCollider(wallNorth);
collisionMgr.addCollider(wallSouth);
collisionMgr.addCollider(wallEast);
collisionMgr.addCollider(wallWest);
// Создаем точки коллизии
auto point1 = std::make_shared<CircleCollider>(Vector3f{125.0f, 0.0f, -214.0f}, 30.0f);
auto point2 = std::make_shared<CircleCollider>(Vector3f{380.0f, 0.0f, -206.0f}, 30.0f);
auto point3 = std::make_shared<CircleCollider>(Vector3f{385.0f, 0.0f, -377.0f}, 30.0f);
auto point4 = std::make_shared<CircleCollider>(Vector3f{112.0f, 0.0f, -377.0f}, 30.0f);
collisionMgr.addCollider(point1);
collisionMgr.addCollider(point2);
collisionMgr.addCollider(point3);
collisionMgr.addCollider(point4);
// Создаем коллизию для кровати как прямоугольник
// Используем точки как границы прямоугольника
// Vector3f bedMin{112.0f, 0.0f, -377.0f}; // Минимальные координаты
// Vector3f bedMax{385.0f, 0.0f, 390.0f}; // Максимальные координаты
// auto bedCollider = std::make_shared<RectangleCollider>(bedMin, bedMax);
// collisionMgr.addCollider(bedCollider);
// Создаем линию коллизии по X (горизонтальная)
const float step = 20.0f; // Расстояние между точками коллизии
for(float x = 98.0f; x < 400.0f; x += step) {
auto point = std::make_shared<CircleCollider>(Vector3f{x, 0.0f, -200.0f}, 10.0f);
collisionMgr.addCollider(point);
}
// Создаем линию коллизии по Z (вертикальная)
for(float z = -200.0f; z > -400.0f; z -= step) {
auto point = std::make_shared<CircleCollider>(Vector3f{400.0f, 0.0f, z}, 10.0f);
collisionMgr.addCollider(point);
}
// Добавляем линию коллизии от (105, 0, -235) до (105, 0, -350)
const float lineStartZ = -235.0f;
const float lineEndZ = -350.0f;
const float stepLine = 5.0f; // Шаг между коллайдерами
const float colliderRadius = 5.0f; // Радиус каждого коллайдера
for (float z = lineStartZ; z >= lineEndZ; z -= stepLine) {
auto lineCollider = std::make_shared<CircleCollider>(Vector3f{105.0f, 0.0f, z}, colliderRadius);
collisionMgr.addCollider(lineCollider);
}
} }
void GameObjectManager::switch_room(int index){ void GameObjectManager::switch_room(int index){
@ -142,35 +193,27 @@ void GameObjectManager::switch_room(int index){
std::cout << "Current music" << rooms[current_room_index].sound_name << std::endl; std::cout << "Current music" << rooms[current_room_index].sound_name << std::endl;
} }
void GameObjectManager::handleEvent(const SDL_Event& event) { void GameObjectManager::handleEvent(const SDL_Event& event) {
// debug room switching // debug room switching
if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) { if (event.type == SDL_MOUSEBUTTONDOWN && event.button.button == SDL_BUTTON_RIGHT) {
switch_room(1); switch_room(1);
} }
else if (event.type == SDL_MOUSEBUTTONDOWN) { else if (event.type == SDL_MOUSEBUTTONDOWN) {
if (InventoryItem* item = GetItemSelected(true)) { const auto highlightedObjects = aoMgr.findByHighlighted(true);
} for (auto* ao : highlightedObjects) {
else { if (!ao) {
const auto highlightedObjects = aoMgr.findByHighlighted(true); continue;
}
for (auto* ao : highlightedObjects) { AddItemToInventory(ao->name, ao->activeObjectTexturePtr, objects_in_inventory+1);
if (!ao) { objects_in_inventory++;
continue;
aoMgr.removeByName(ao->name);
} }
// bx.Interpolate(animationCounter);
AddItemToInventory(ao->name, ao->activeObjectTexturePtr, objects_in_inventory+1); // animationCounter += 2;
objects_in_inventory++;
aoMgr.removeByName(ao->name);
} }
}
// bx.Interpolate(animationCounter);
// animationCounter += 2;
}
else if (event.type == SDL_MOUSEWHEEL) { else if (event.type == SDL_MOUSEWHEEL) {
static const float zoomstep = 1.0f; static const float zoomstep = 1.0f;
if (event.wheel.y > 0) { if (event.wheel.y > 0) {
@ -182,27 +225,24 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
if (Environment::zoom < zoomstep) { if (Environment::zoom < zoomstep) {
Environment::zoom = zoomstep; Environment::zoom = zoomstep;
} }
if (Environment::zoom > 4) if (Environment::zoom > 4) {
{
Environment::zoom = 4; Environment::zoom = 4;
} }
} }
else if (event.type == SDL_KEYDOWN) { else if (event.type == SDL_KEYDOWN) {
switch (event.key.keysym.sym) { switch (event.key.keysym.sym) {
case SDLK_SPACE: case SDLK_SPACE:
Environment::showMouse = !Environment::showMouse; Environment::showMouse = !Environment::showMouse;
if (Environment::showMouse) if (Environment::showMouse) {
{ SDL_SetRelativeMouseMode(SDL_FALSE);
SDL_SetRelativeMouseMode(SDL_FALSE); }
} else {
else SDL_SetRelativeMouseMode(SDL_TRUE);
{ lastMouseX = 0;
SDL_SetRelativeMouseMode(SDL_TRUE); lastMouseY = 0;
lastMouseX = 0; }
lastMouseY = 0; break;
}
break;
case SDLK_ESCAPE: case SDLK_ESCAPE:
case SDLK_q: case SDLK_q:
@ -214,8 +254,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
if (audioPlayer) { if (audioPlayer) {
audioPlayer->playSound("Звук-Идут-по-земле.ogg"); audioPlayer->playSound("Звук-Идут-по-земле.ogg");
} }
if (Environment::violaCurrentAnimation == 0) if (Environment::violaCurrentAnimation == 0) {
{
Environment::violaCurrentAnimation = 1; Environment::violaCurrentAnimation = 1;
Environment::violaLastWalkFrame = -1; Environment::violaLastWalkFrame = -1;
} }
@ -226,8 +265,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
if (audioPlayer) { if (audioPlayer) {
audioPlayer->playSound("Звук-Идут-по-земле.ogg"); audioPlayer->playSound("Звук-Идут-по-земле.ogg");
} }
if (Environment::violaCurrentAnimation == 0) if (Environment::violaCurrentAnimation == 0) {
{
Environment::violaCurrentAnimation = 1; Environment::violaCurrentAnimation = 1;
Environment::violaLastWalkFrame = -1; Environment::violaLastWalkFrame = -1;
} }
@ -238,8 +276,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
if (audioPlayer) { if (audioPlayer) {
audioPlayer->playSound("Звук-Идут-по-земле.ogg"); audioPlayer->playSound("Звук-Идут-по-земле.ogg");
} }
if (Environment::violaCurrentAnimation == 0) if (Environment::violaCurrentAnimation == 0) {
{
Environment::violaCurrentAnimation = 1; Environment::violaCurrentAnimation = 1;
Environment::violaLastWalkFrame = -1; Environment::violaLastWalkFrame = -1;
} }
@ -250,32 +287,21 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
if (audioPlayer) { if (audioPlayer) {
audioPlayer->playSound("Звук-Идут-по-земле.ogg"); audioPlayer->playSound("Звук-Идут-по-земле.ogg");
} }
if (Environment::violaCurrentAnimation == 0) if (Environment::violaCurrentAnimation == 0) {
{
Environment::violaCurrentAnimation = 1; Environment::violaCurrentAnimation = 1;
Environment::violaLastWalkFrame = -1; Environment::violaLastWalkFrame = -1;
} }
break; break;
case SDLK_1: case SDLK_1:
case SDLK_2: case SDLK_2:
case SDLK_3: {
case SDLK_4: int hot_key = (event.key.keysym.sym == SDLK_1) ? 1 : 2;
case SDLK_5:
case SDLK_6:
case SDLK_7:
case SDLK_8:
case SDLK_9:
{
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;
} }
} }
break; break;
// ...handle other keys... // ...handle other keys...
} }
} }
@ -284,10 +310,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
case SDLK_LEFT: case SDLK_LEFT:
case SDLK_a: case SDLK_a:
Environment::leftPressed = false; Environment::leftPressed = false;
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false) if (!Environment::leftPressed && !Environment::rightPressed && !Environment::upPressed && !Environment::downPressed) {
{ if (Environment::violaCurrentAnimation == 1) {
if (Environment::violaCurrentAnimation == 1)
{
Environment::violaCurrentAnimation = 0; Environment::violaCurrentAnimation = 0;
Environment::violaCurrentIdleFrame = -1; Environment::violaCurrentIdleFrame = -1;
} }
@ -296,10 +320,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
case SDLK_RIGHT: case SDLK_RIGHT:
case SDLK_d: case SDLK_d:
Environment::rightPressed = false; Environment::rightPressed = false;
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false) if (!Environment::leftPressed && !Environment::rightPressed && !Environment::upPressed && !Environment::downPressed) {
{ if (Environment::violaCurrentAnimation == 1) {
if (Environment::violaCurrentAnimation == 1)
{
Environment::violaCurrentAnimation = 0; Environment::violaCurrentAnimation = 0;
Environment::violaCurrentIdleFrame = -1; Environment::violaCurrentIdleFrame = -1;
} }
@ -308,10 +330,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
case SDLK_UP: case SDLK_UP:
case SDLK_w: case SDLK_w:
Environment::upPressed = false; Environment::upPressed = false;
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false) if (!Environment::leftPressed && !Environment::rightPressed && !Environment::upPressed && !Environment::downPressed) {
{ if (Environment::violaCurrentAnimation == 1) {
if (Environment::violaCurrentAnimation == 1)
{
Environment::violaCurrentAnimation = 0; Environment::violaCurrentAnimation = 0;
Environment::violaCurrentIdleFrame = -1; Environment::violaCurrentIdleFrame = -1;
} }
@ -320,10 +340,8 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
case SDLK_DOWN: case SDLK_DOWN:
case SDLK_s: case SDLK_s:
Environment::downPressed = false; Environment::downPressed = false;
if (Environment::leftPressed == false && Environment::rightPressed == false && Environment::upPressed == false && Environment::downPressed == false) if (!Environment::leftPressed && !Environment::rightPressed && !Environment::upPressed && !Environment::downPressed) {
{ if (Environment::violaCurrentAnimation == 1) {
if (Environment::violaCurrentAnimation == 1)
{
Environment::violaCurrentAnimation = 0; Environment::violaCurrentAnimation = 0;
Environment::violaCurrentIdleFrame = -1; Environment::violaCurrentIdleFrame = -1;
} }
@ -332,49 +350,39 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
} }
} }
if (event.type == SDL_MOUSEMOTION) { if (event.type == SDL_MOUSEMOTION) {
if (!Environment::showMouse) {
if (Environment::showMouse == false)
{
int mouseX, mouseY; int mouseX, mouseY;
SDL_GetRelativeMouseState(&mouseX, &mouseY); SDL_GetRelativeMouseState(&mouseX, &mouseY);
float diffX = 0.01f * mouseX; float diffX = 0.01f * mouseX;
float diffY = 0.01f * mouseY; float diffY = 0.01f * mouseY;
Environment::cameraPhi += diffX; Environment::cameraPhi += diffX;
if (Environment::settings_inverseVertical) if (Environment::settings_inverseVertical) {
{
Environment::cameraAlpha -= diffY; Environment::cameraAlpha -= diffY;
} }
else else {
{
Environment::cameraAlpha += diffY; Environment::cameraAlpha += diffY;
} }
if (Environment::cameraAlpha < 0.1 * M_PI / 2.0) if (Environment::cameraAlpha < 0.1 * M_PI / 2.0) {
{
Environment::cameraAlpha = 0.1 * M_PI / 2.0; Environment::cameraAlpha = 0.1 * M_PI / 2.0;
} }
else if (Environment::cameraAlpha > 0.9 * M_PI / 2.0) else if (Environment::cameraAlpha > 0.9 * M_PI / 2.0) {
{
Environment::cameraAlpha = 0.9 * M_PI / 2.0; Environment::cameraAlpha = 0.9 * M_PI / 2.0;
} }
} }
else else {
{
lastMouseX = event.motion.x; lastMouseX = event.motion.x;
lastMouseY = event.motion.y; lastMouseY = event.motion.y;
} }
} }
} }
void GameObjectManager::updateScene(size_t ms) { void GameObjectManager::updateScene(size_t ms) {
const float SPEED = 0.1f; const float SPEED = 0.1f;
Vector2f directionVector = { 0.f, SPEED }; //x and z Vector2f directionVector = { 0.f, SPEED }; // x and z
// Вычисляем новые координаты вектора // Вычисляем новые координаты вектора
float x_new = directionVector.v[0] * cos(Environment::cameraPhi) - directionVector.v[1] * sin(Environment::cameraPhi); float x_new = directionVector.v[0] * cos(Environment::cameraPhi) - directionVector.v[1] * sin(Environment::cameraPhi);
@ -384,7 +392,7 @@ void GameObjectManager::updateScene(size_t ms) {
directionVector.v[0] = x_new; directionVector.v[0] = x_new;
directionVector.v[1] = y_new; directionVector.v[1] = y_new;
//Only forward is allowed // Only forward is allowed
/* /*
if (Environment::leftPressed) { if (Environment::leftPressed) {
Environment::cameraShift.v[0] += SPEED * ms; Environment::cameraShift.v[0] += SPEED * ms;
@ -397,7 +405,8 @@ void GameObjectManager::updateScene(size_t ms) {
} }
if (Environment::downPressed) { if (Environment::downPressed) {
Environment::cameraShift.v[2] -= SPEED * ms; Environment::cameraShift.v[2] -= SPEED * ms;
}*/ }
*/
Vector3f newPosition = Environment::cameraShift; Vector3f newPosition = Environment::cameraShift;
if (Environment::upPressed) { if (Environment::upPressed) {
@ -418,10 +427,15 @@ void GameObjectManager::updateScene(size_t ms) {
} }
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]}; Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
// Проверяем, что новая позиция внутри разрешенной зоны // Заменяем проверку walkArea.isInside() на проверку через collisionMgr
if (walkArea.isInside(characterNewPos)) { if (!collisionMgr.checkCollision(characterNewPos)) {
Environment::cameraShift = newPosition; Environment::cameraShift = newPosition;
Environment::characterPos = characterNewPos; Environment::characterPos = characterNewPos;
std::cout << "Player position: x=" << characterNewPos.v[0]
<< ", y=" << characterNewPos.v[1]
<< ", z=" << characterNewPos.v[2] << "\r";
std::cout.flush(); // Чтобы обновлялось в той же строке
} }
for (auto& [key, obj] : aoMgr.activeObjectsEntities) { for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
@ -433,38 +447,30 @@ void GameObjectManager::updateScene(size_t ms) {
obj.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);
} }
if (Environment::violaCurrentAnimation == 0) if (Environment::violaCurrentAnimation == 0) {
{
Environment::violaCurrentIdleFrame += ms / 24.f; Environment::violaCurrentIdleFrame += ms / 24.f;
while (Environment::violaCurrentIdleFrame >= 40) while (Environment::violaCurrentIdleFrame >= 40) {
{
Environment::violaCurrentIdleFrame -= 40; Environment::violaCurrentIdleFrame -= 40;
} }
if (int(Environment::violaCurrentIdleFrame) != Environment::violaLastIdleFrame) if (int(Environment::violaCurrentIdleFrame) != Environment::violaLastIdleFrame) {
{
violaIdleModel.Interpolate(int(Environment::violaCurrentIdleFrame)); violaIdleModel.Interpolate(int(Environment::violaCurrentIdleFrame));
Environment::violaLastIdleFrame = int(Environment::violaCurrentIdleFrame); Environment::violaLastIdleFrame = int(Environment::violaCurrentIdleFrame);
} }
} }
else if (Environment::violaCurrentAnimation == 1) else if (Environment::violaCurrentAnimation == 1) {
{
Environment::violaCurrentWalkFrame += ms / 24.f; Environment::violaCurrentWalkFrame += ms / 24.f;
while (Environment::violaCurrentWalkFrame >= 30) while (Environment::violaCurrentWalkFrame >= 30) {
{
Environment::violaCurrentWalkFrame -= 30; Environment::violaCurrentWalkFrame -= 30;
} }
if (int(Environment::violaCurrentWalkFrame) != Environment::violaLastWalkFrame) if (int(Environment::violaCurrentWalkFrame) != Environment::violaLastWalkFrame) {
{
violaWalkModel.Interpolate(int(Environment::violaCurrentWalkFrame)); violaWalkModel.Interpolate(int(Environment::violaCurrentWalkFrame));
Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame); Environment::violaLastWalkFrame = int(Environment::violaCurrentWalkFrame);
} }
@ -472,14 +478,12 @@ 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 {
const int baseObjectSize = 32; // Base half-size // Простая проверка попадания точки в квадрат 64x64 вокруг центра объекта
const float scale = 1.0f; // Get scale from item if needed const int objectSize = 32; // Половина размера области выделения
const int scaledObjectSize = static_cast<int>(baseObjectSize * scale); return (screenX >= objectScreenX - objectSize &&
screenX <= objectScreenX + objectSize &&
return (screenX >= objectScreenX - scaledObjectSize && screenY >= objectScreenY - objectSize &&
screenX <= objectScreenX + scaledObjectSize && screenY <= objectScreenY + objectSize);
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) {
@ -505,7 +509,7 @@ void GameObjectManager::worldToScreenCoordinates(Vector3f objectPos,
int screenWidth, int screenHeight, int screenWidth, int screenHeight,
int& screenX, int& screenY) { int& screenX, int& screenY) {
Vector4f inx = { objectPos.v[0], objectPos.v[1], objectPos.v[2], 1.0f}; Vector4f inx = { objectPos.v[0], objectPos.v[1], objectPos.v[2], 1.0f };
Vector4f clipCoords = MultMatrixVector(projectionModelView, inx); Vector4f clipCoords = MultMatrixVector(projectionModelView, inx);
float ndcX = clipCoords.v[0] / clipCoords.v[3]; float ndcX = clipCoords.v[0] / clipCoords.v[3];

View File

@ -6,11 +6,11 @@
#include <vector> #include <vector>
#include "ActiveObject.h" #include "ActiveObject.h"
#include "Room.h" #include "Room.h"
#include "BoundaryBox.h" // Добавляем включение
#ifdef __linux__ #ifdef __linux__
#include <SDL2/SDL.h> #include <SDL2/SDL.h>
#endif #endif
#include "OpenGlExtensions.h" #include "OpenGlExtensions.h"
#include "BoundaryBox.h" // Добавляем новый include
namespace ZL { namespace ZL {
@ -68,7 +68,8 @@ private:
Matrix4f projectionModelView, Matrix4f projectionModelView,
int screenWidth, int screenHeight, int screenWidth, int screenHeight,
int& screenX, int& screenY); int& screenX, int& screenY);
BoundaryBox walkArea{800.0f, 800.0f}; // Изменяем размер с 400 на 800 BoundaryBox walkArea{800.0f, 800.0f}; // Зона для ходьбы 800x800
CollisionManager collisionMgr; // Добавляем менеджер коллизий
}; };
} // namespace ZL } // namespace ZL