kolliziya dobavlena
This commit is contained in:
parent
54d0af8afb
commit
c31139fdec
20
BoundaryBox.h
Normal file
20
BoundaryBox.h
Normal file
@ -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;
|
||||||
|
};
|
||||||
|
}
|
||||||
@ -399,26 +399,30 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
Environment::cameraShift.v[2] -= SPEED * ms;
|
Environment::cameraShift.v[2] -= SPEED * ms;
|
||||||
}*/
|
}*/
|
||||||
|
|
||||||
|
Vector3f newPosition = Environment::cameraShift;
|
||||||
if (Environment::upPressed) {
|
if (Environment::upPressed) {
|
||||||
Environment::cameraShift.v[0] += directionVector.v[0] * ms;
|
newPosition.v[0] += directionVector.v[0] * ms;
|
||||||
Environment::cameraShift.v[2] += directionVector.v[1] * ms;
|
newPosition.v[2] += directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
if (Environment::downPressed) {
|
if (Environment::downPressed) {
|
||||||
Environment::cameraShift.v[0] -= directionVector.v[0] * ms;
|
newPosition.v[0] -= directionVector.v[0] * ms;
|
||||||
Environment::cameraShift.v[2] -= directionVector.v[1] * ms;
|
newPosition.v[2] -= directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
if (Environment::rightPressed) {
|
if (Environment::rightPressed) {
|
||||||
Environment::cameraShift.v[2] += directionVector.v[0] * ms;
|
newPosition.v[2] += directionVector.v[0] * ms;
|
||||||
Environment::cameraShift.v[0] -= directionVector.v[1] * ms;
|
newPosition.v[0] -= directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
if (Environment::leftPressed) {
|
if (Environment::leftPressed) {
|
||||||
Environment::cameraShift.v[2] -= directionVector.v[0] * ms;
|
newPosition.v[2] -= directionVector.v[0] * ms;
|
||||||
Environment::cameraShift.v[0] += directionVector.v[1] * ms;
|
newPosition.v[0] += directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
Environment::characterPos.v[0] = -Environment::cameraShift.v[0];
|
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
|
||||||
Environment::characterPos.v[1] = -Environment::cameraShift.v[1];
|
// Проверяем, что новая позиция внутри разрешенной зоны
|
||||||
Environment::characterPos.v[2] = -Environment::cameraShift.v[2];
|
if (walkArea.isInside(characterNewPos)) {
|
||||||
|
Environment::cameraShift = newPosition;
|
||||||
|
Environment::characterPos = characterNewPos;
|
||||||
|
}
|
||||||
|
|
||||||
for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
|
for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
|
||||||
float dist = sqrtf(
|
float dist = sqrtf(
|
||||||
|
|||||||
@ -10,6 +10,7 @@
|
|||||||
#include <SDL2/SDL.h>
|
#include <SDL2/SDL.h>
|
||||||
#endif
|
#endif
|
||||||
#include "OpenGlExtensions.h"
|
#include "OpenGlExtensions.h"
|
||||||
|
#include "BoundaryBox.h" // Добавляем новый include
|
||||||
|
|
||||||
namespace ZL {
|
namespace ZL {
|
||||||
|
|
||||||
@ -67,6 +68,7 @@ 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
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
8
shaders/fragment.glsl
Normal file
8
shaders/fragment.glsl
Normal file
@ -0,0 +1,8 @@
|
|||||||
|
#version 130
|
||||||
|
|
||||||
|
in vec2 texCoord;
|
||||||
|
uniform sampler2D textureSampler;
|
||||||
|
|
||||||
|
void main() {
|
||||||
|
gl_FragColor = texture2D(textureSampler, texCoord);
|
||||||
|
}
|
||||||
14
shaders/vertex.glsl
Normal file
14
shaders/vertex.glsl
Normal file
@ -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;
|
||||||
|
}
|
||||||
Loading…
Reference in New Issue
Block a user