working with collisions
This commit is contained in:
parent
5c571578dd
commit
fe5d8c2f47
@ -80,7 +80,6 @@ public:
|
|||||||
|
|
||||||
bool checkCollision(const Vector3f& position) const {
|
bool checkCollision(const Vector3f& position) const {
|
||||||
// Проверяем границы комнаты
|
// Проверяем границы комнаты
|
||||||
std::cout << "checkCollision" << std::endl;
|
|
||||||
if (roomBoundary && !roomBoundary->isInside(position)) {
|
if (roomBoundary && !roomBoundary->isInside(position)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|||||||
@ -70,12 +70,12 @@ void GameObjectManager::initialize() {
|
|||||||
|
|
||||||
|
|
||||||
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)));
|
||||||
textMesh.Move(Vector3f{ 0, 93, 0 });
|
textMesh.Move(Vector3f{ 0, 93, 0 });
|
||||||
|
|
||||||
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);
|
||||||
@ -163,6 +163,9 @@ void GameObjectManager::initialize() {
|
|||||||
//SDL_ShowCursor(SDL_DISABLE);
|
//SDL_ShowCursor(SDL_DISABLE);
|
||||||
SDL_SetRelativeMouseMode(SDL_TRUE);
|
SDL_SetRelativeMouseMode(SDL_TRUE);
|
||||||
|
|
||||||
|
collisionMgr.setRoomBoundary(800, 800);
|
||||||
|
collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{80, 0, 200}, Vector3f{400, 0, 400}));
|
||||||
|
|
||||||
return true;
|
return true;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -370,7 +373,7 @@ void GameObjectManager::handleEvent(const SDL_Event& event) {
|
|||||||
Environment::cameraAlpha = 0.9 * M_PI / 2.0;
|
Environment::cameraAlpha = 0.9 * M_PI / 2.0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
else {checkCollision
|
else {
|
||||||
lastMouseX = event.motion.x;
|
lastMouseX = event.motion.x;
|
||||||
lastMouseY = event.motion.y;
|
lastMouseY = event.motion.y;
|
||||||
}
|
}
|
||||||
@ -424,16 +427,23 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
newPosition.v[0] += directionVector.v[1] * ms;
|
newPosition.v[0] += directionVector.v[1] * ms;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
|
Vector3f characterNewPos{-newPosition.v[0], -newPosition.v[1], -newPosition.v[2]};
|
||||||
|
|
||||||
|
std::cout << "Player position: x=" << characterNewPos.v[0]
|
||||||
|
<< ", y=" << characterNewPos.v[1]
|
||||||
|
<< ", z=" << characterNewPos.v[2] << "\r";
|
||||||
|
std::cout.flush();
|
||||||
|
|
||||||
// Заменяем проверку walkArea.isInside() на проверку через collisionMgr
|
// Заменяем проверку walkArea.isInside() на проверку через collisionMgr
|
||||||
if (!collisionMgr.checkCollision(characterNewPos)) {
|
if (collisionMgr.checkCollision(characterNewPos) == false) {
|
||||||
Environment::cameraShift = newPosition;
|
Environment::cameraShift = newPosition;
|
||||||
Environment::characterPos = characterNewPos;
|
Environment::characterPos = characterNewPos;
|
||||||
|
/*
|
||||||
std::cout << "Player position: x=" << characterNewPos.v[0]
|
std::cout << "Player position: x=" << characterNewPos.v[0]
|
||||||
<< ", y=" << characterNewPos.v[1]
|
<< ", y=" << characterNewPos.v[1]
|
||||||
<< ", z=" << characterNewPos.v[2] << "\r";
|
<< ", z=" << characterNewPos.v[2] << "\r";
|
||||||
std::cout.flush(); // Чтобы обновлялось в той же строке
|
std::cout.flush(); // Чтобы обновлялось в той же строке*/
|
||||||
}
|
}
|
||||||
|
|
||||||
for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
|
for (auto& [key, obj] : aoMgr.activeObjectsEntities) {
|
||||||
|
|||||||
@ -173,6 +173,7 @@
|
|||||||
<ClInclude Include="AnimatedModel.h" />
|
<ClInclude Include="AnimatedModel.h" />
|
||||||
<ClInclude Include="AudioPlayerAsync.h" />
|
<ClInclude Include="AudioPlayerAsync.h" />
|
||||||
<ClInclude Include="BoneAnimatedModel.h" />
|
<ClInclude Include="BoneAnimatedModel.h" />
|
||||||
|
<ClInclude Include="BoundaryBox.h" />
|
||||||
<ClInclude Include="Environment.h" />
|
<ClInclude Include="Environment.h" />
|
||||||
<ClInclude Include="Game.h" />
|
<ClInclude Include="Game.h" />
|
||||||
<ClInclude Include="GameObjectManager.h" />
|
<ClInclude Include="GameObjectManager.h" />
|
||||||
|
|||||||
@ -146,5 +146,8 @@
|
|||||||
<ClInclude Include="AudioPlayerAsync.h">
|
<ClInclude Include="AudioPlayerAsync.h">
|
||||||
<Filter>Header Files</Filter>
|
<Filter>Header Files</Filter>
|
||||||
</ClInclude>
|
</ClInclude>
|
||||||
|
<ClInclude Include="BoundaryBox.h">
|
||||||
|
<Filter>Header Files</Filter>
|
||||||
|
</ClInclude>
|
||||||
</ItemGroup>
|
</ItemGroup>
|
||||||
</Project>
|
</Project>
|
||||||
Loading…
Reference in New Issue
Block a user