diff --git a/AudioPlayerAsync.cpp b/AudioPlayerAsync.cpp index 1d09b37..f79c232 100644 --- a/AudioPlayerAsync.cpp +++ b/AudioPlayerAsync.cpp @@ -16,6 +16,7 @@ void AudioPlayerAsync::resetAsync() { std::unique_lock lock(mtx); taskQueue.push([this]() { //audioPlayerMutex.lock(); + audioPlayer.reset(); audioPlayer = std::make_unique(); //audioPlayerMutex.unlock(); }); diff --git a/BoundaryBox.h b/BoundaryBox.h new file mode 100644 index 0000000..cede401 --- /dev/null +++ b/BoundaryBox.h @@ -0,0 +1,20 @@ +#pragma once +#include "Math.h" + +namespace ZL { +class BoundaryBox { +public: + BoundaryBox(float width, float height) + : halfWidth(width/2) + , halfHeight(height/2) {} + + bool isInside(const Vector3f& position) const { + return (position.v[0] >= -halfWidth && position.v[0] <= halfWidth && + position.v[2] >= -halfHeight && position.v[2] <= halfHeight); + } + +private: + float halfWidth; + float halfHeight; +}; +} diff --git a/GameObjectManager.cpp b/GameObjectManager.cpp index d2e5430..9fb6626 100644 --- a/GameObjectManager.cpp +++ b/GameObjectManager.cpp @@ -410,26 +410,30 @@ void GameObjectManager::updateScene(size_t ms) { Environment::cameraShift.v[2] -= SPEED * ms; }*/ + Vector3f newPosition = Environment::cameraShift; if (Environment::upPressed) { - Environment::cameraShift.v[0] += directionVector.v[0] * ms; - Environment::cameraShift.v[2] += directionVector.v[1] * ms; + newPosition.v[0] += directionVector.v[0] * ms; + newPosition.v[2] += directionVector.v[1] * ms; } if (Environment::downPressed) { - Environment::cameraShift.v[0] -= directionVector.v[0] * ms; - Environment::cameraShift.v[2] -= directionVector.v[1] * ms; + newPosition.v[0] -= directionVector.v[0] * ms; + newPosition.v[2] -= directionVector.v[1] * ms; } if (Environment::rightPressed) { - Environment::cameraShift.v[2] += directionVector.v[0] * ms; - Environment::cameraShift.v[0] -= directionVector.v[1] * ms; + newPosition.v[2] += directionVector.v[0] * ms; + newPosition.v[0] -= directionVector.v[1] * ms; } if (Environment::leftPressed) { - Environment::cameraShift.v[2] -= directionVector.v[0] * ms; - Environment::cameraShift.v[0] += directionVector.v[1] * ms; + newPosition.v[2] -= directionVector.v[0] * ms; + newPosition.v[0] += directionVector.v[1] * ms; } - Environment::characterPos.v[0] = -Environment::cameraShift.v[0]; - Environment::characterPos.v[1] = -Environment::cameraShift.v[1]; - Environment::characterPos.v[2] = -Environment::cameraShift.v[2]; + Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]}; + // Проверяем, что новая позиция внутри разрешенной зоны + if (walkArea.isInside(characterNewPos)) { + Environment::cameraShift = newPosition; + Environment::characterPos = characterNewPos; + } for (auto& [key, obj] : aoMgr.activeObjectsEntities) { float dist = sqrtf( diff --git a/GameObjectManager.h b/GameObjectManager.h index a56bc5a..1c30493 100644 --- a/GameObjectManager.h +++ b/GameObjectManager.h @@ -10,8 +10,12 @@ #include #endif #include "OpenGlExtensions.h" + #include +#include "BoundaryBox.h" // Добавляем новый include + + namespace ZL { class GameObjectManager { @@ -71,6 +75,7 @@ private: Matrix4f projectionModelView, int screenWidth, int screenHeight, int& screenX, int& screenY); + BoundaryBox walkArea{800.0f, 800.0f}; // Изменяем размер с 400 на 800 }; } // namespace ZL diff --git a/shaders/fragment.glsl b/shaders/fragment.glsl new file mode 100644 index 0000000..06e764e --- /dev/null +++ b/shaders/fragment.glsl @@ -0,0 +1,8 @@ +#version 130 + +in vec2 texCoord; +uniform sampler2D textureSampler; + +void main() { + gl_FragColor = texture2D(textureSampler, texCoord); +} diff --git a/shaders/vertex.glsl b/shaders/vertex.glsl new file mode 100644 index 0000000..23d289a --- /dev/null +++ b/shaders/vertex.glsl @@ -0,0 +1,14 @@ +#version 130 + +in vec3 position; +in vec2 texcoord; + +uniform mat4 projection; +uniform mat4 modelView; + +out vec2 texCoord; + +void main() { + gl_Position = projection * modelView * vec4(position, 1.0); + texCoord = texcoord; +}