Move collision box and model to the room itself
This commit is contained in:
parent
fe5d8c2f47
commit
a3075433f0
@ -15,6 +15,10 @@ public:
|
|||||||
// Прямоугольная граница комнаты
|
// Прямоугольная граница комнаты
|
||||||
class BoundaryBox {
|
class BoundaryBox {
|
||||||
public:
|
public:
|
||||||
|
BoundaryBox()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
BoundaryBox(float width, float height)
|
BoundaryBox(float width, float height)
|
||||||
: halfWidth(width/2)
|
: halfWidth(width/2)
|
||||||
, halfHeight(height/2) {}
|
, halfHeight(height/2) {}
|
||||||
@ -25,8 +29,8 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
float halfWidth;
|
float halfWidth = 0;
|
||||||
float halfHeight;
|
float halfHeight = 0;
|
||||||
};
|
};
|
||||||
|
|
||||||
// Круглая коллизия для объектов
|
// Круглая коллизия для объектов
|
||||||
@ -70,8 +74,13 @@ private:
|
|||||||
// Менеджер коллизий
|
// Менеджер коллизий
|
||||||
class CollisionManager {
|
class CollisionManager {
|
||||||
public:
|
public:
|
||||||
|
CollisionManager()
|
||||||
|
{
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
void setRoomBoundary(float width, float height) {
|
void setRoomBoundary(float width, float height) {
|
||||||
roomBoundary = std::make_unique<BoundaryBox>(width, height);
|
roomBoundary = BoundaryBox(width, height);
|
||||||
}
|
}
|
||||||
|
|
||||||
void addCollider(std::shared_ptr<Collidable> collider) {
|
void addCollider(std::shared_ptr<Collidable> collider) {
|
||||||
@ -80,7 +89,7 @@ public:
|
|||||||
|
|
||||||
bool checkCollision(const Vector3f& position) const {
|
bool checkCollision(const Vector3f& position) const {
|
||||||
// Проверяем границы комнаты
|
// Проверяем границы комнаты
|
||||||
if (roomBoundary && !roomBoundary->isInside(position)) {
|
if (!roomBoundary.isInside(position)) {
|
||||||
return true;
|
return true;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -94,7 +103,7 @@ public:
|
|||||||
}
|
}
|
||||||
|
|
||||||
private:
|
private:
|
||||||
std::unique_ptr<BoundaryBox> roomBoundary;
|
BoundaryBox roomBoundary;
|
||||||
std::vector<std::shared_ptr<Collidable>> colliders;
|
std::vector<std::shared_ptr<Collidable>> colliders;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|||||||
@ -33,7 +33,7 @@ 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"));
|
||||||
|
|
||||||
// Load models
|
// Load models
|
||||||
/*
|
/*
|
||||||
@ -47,7 +47,12 @@ void GameObjectManager::initialize() {
|
|||||||
|
|
||||||
loadingThread = std::thread([this]() {
|
loadingThread = std::thread([this]() {
|
||||||
|
|
||||||
textMesh = ZL::LoadFromTextFile("./oneroom001.txt");
|
preloadedRoomMeshArr.resize(1);
|
||||||
|
preloadedRoomMeshArr[0] = ZL::LoadFromTextFile("./oneroom001.txt");
|
||||||
|
preloadedRoomMeshArr[0].Scale(10);
|
||||||
|
preloadedRoomMeshArr[0].Move(Vector3f{ 0, 93, 0 });
|
||||||
|
|
||||||
|
|
||||||
violaIdleModel.LoadFromFile("./idleviola001.txt");
|
violaIdleModel.LoadFromFile("./idleviola001.txt");
|
||||||
violaWalkModel.LoadFromFile("./walkviolla001.txt");
|
violaWalkModel.LoadFromFile("./walkviolla001.txt");
|
||||||
sideThreadLoadingCompleted = true;
|
sideThreadLoadingCompleted = true;
|
||||||
@ -61,29 +66,6 @@ void GameObjectManager::initialize() {
|
|||||||
std::function<bool()> loadingFunction3 = [this]()
|
std::function<bool()> loadingFunction3 = [this]()
|
||||||
{
|
{
|
||||||
|
|
||||||
/*
|
|
||||||
testObjMesh = LoadFromObjFile("./chair_01.obj");
|
|
||||||
testObjMesh.Scale(10);
|
|
||||||
testObjMesh.SwapZandY();
|
|
||||||
testObjMeshMutable.data = testObjMesh;
|
|
||||||
testObjMeshMutable.RefreshVBO();*/
|
|
||||||
|
|
||||||
|
|
||||||
textMesh.Scale(10);
|
|
||||||
//textMesh.SwapZandY();
|
|
||||||
//textMesh.RotateByMatrix(QuatToMatrix(QuatFromRotateAroundX(M_PI * 0.5)));
|
|
||||||
textMesh.Move(Vector3f{ 0, 93, 0 });
|
|
||||||
|
|
||||||
//coneMesh = ZL::LoadFromTextFile("./cone001.txt"); // Add ZL:: namespace
|
|
||||||
//coneMesh.Scale(200);
|
|
||||||
|
|
||||||
|
|
||||||
textMeshMutable.AssignFrom(textMesh);
|
|
||||||
textMeshMutable.RefreshVBO();
|
|
||||||
//coneMeshMutable.AssignFrom(coneMesh);
|
|
||||||
//coneMeshMutable.RefreshVBO();
|
|
||||||
|
|
||||||
|
|
||||||
// Create active object
|
// Create active object
|
||||||
|
|
||||||
ActiveObject ao1;
|
ActiveObject ao1;
|
||||||
@ -123,6 +105,11 @@ void GameObjectManager::initialize() {
|
|||||||
room_1.objects.push_back(ao1);
|
room_1.objects.push_back(ao1);
|
||||||
room_1.sound_name = "Symphony No.6 (1st movement).ogg";
|
room_1.sound_name = "Symphony No.6 (1st movement).ogg";
|
||||||
room_1.roomLogic = createRoom1Logic();
|
room_1.roomLogic = createRoom1Logic();
|
||||||
|
room_1.textMesh = preloadedRoomMeshArr[0];
|
||||||
|
room_1.textMeshMutable.AssignFrom(room_1.textMesh);
|
||||||
|
room_1.collisionMgr.setRoomBoundary(800, 800);
|
||||||
|
room_1.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ 80, 0, 200 }, Vector3f{ 400, 0, 400 }));
|
||||||
|
|
||||||
rooms.push_back(room_1);
|
rooms.push_back(room_1);
|
||||||
aoMgr.addActiveObject(ao1);
|
aoMgr.addActiveObject(ao1);
|
||||||
|
|
||||||
@ -130,6 +117,11 @@ void GameObjectManager::initialize() {
|
|||||||
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 = createRoom2Logic();
|
||||||
|
room_2.textMesh = preloadedRoomMeshArr[0];
|
||||||
|
room_2.textMeshMutable.AssignFrom(room_2.textMesh);
|
||||||
|
room_2.collisionMgr.setRoomBoundary(800, 800);
|
||||||
|
room_2.collisionMgr.addCollider(std::make_shared<RectangleCollider>(Vector3f{ 80, 0, 200 }, Vector3f{ 400, 0, 400 }));
|
||||||
|
|
||||||
rooms.push_back(room_2);
|
rooms.push_back(room_2);
|
||||||
|
|
||||||
activeObjects = rooms[current_room_index].objects;
|
activeObjects = rooms[current_room_index].objects;
|
||||||
@ -152,7 +144,7 @@ void GameObjectManager::initialize() {
|
|||||||
inventoryIconMeshMutable.AssignFrom(inventoryIconMesh);
|
inventoryIconMeshMutable.AssignFrom(inventoryIconMesh);
|
||||||
inventoryIconMeshMutable.RefreshVBO();
|
inventoryIconMeshMutable.RefreshVBO();
|
||||||
|
|
||||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
//roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||||
|
|
||||||
AddItemToInventory("book1", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
|
AddItemToInventory("book1", std::make_shared<Texture>(CreateTextureDataFromBmp24("./Kitchen_ceramics.bmp")), objects_in_inventory + 1);
|
||||||
objects_in_inventory++;
|
objects_in_inventory++;
|
||||||
@ -163,9 +155,7 @@ 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;
|
||||||
|
|
||||||
};
|
};
|
||||||
@ -178,7 +168,7 @@ void GameObjectManager::initialize() {
|
|||||||
void GameObjectManager::switch_room(int index){
|
void GameObjectManager::switch_room(int index){
|
||||||
current_room_index = index;
|
current_room_index = index;
|
||||||
|
|
||||||
roomTexturePtr = rooms[current_room_index].roomTexture;
|
//roomTexturePtr = rooms[current_room_index].roomTexture;
|
||||||
|
|
||||||
|
|
||||||
//audioPlayer.reset(); // This deletes the current AudioPlayer
|
//audioPlayer.reset(); // This deletes the current AudioPlayer
|
||||||
@ -436,7 +426,7 @@ void GameObjectManager::updateScene(size_t ms) {
|
|||||||
std::cout.flush();
|
std::cout.flush();
|
||||||
|
|
||||||
// Заменяем проверку walkArea.isInside() на проверку через collisionMgr
|
// Заменяем проверку walkArea.isInside() на проверку через collisionMgr
|
||||||
if (collisionMgr.checkCollision(characterNewPos) == false) {
|
if (rooms[current_room_index].collisionMgr.checkCollision(characterNewPos) == false) {
|
||||||
Environment::cameraShift = newPosition;
|
Environment::cameraShift = newPosition;
|
||||||
Environment::characterPos = characterNewPos;
|
Environment::characterPos = characterNewPos;
|
||||||
/*
|
/*
|
||||||
|
|||||||
@ -4,10 +4,9 @@
|
|||||||
#include "AudioPlayerAsync.h"
|
#include "AudioPlayerAsync.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include <vector>
|
#include <vector>
|
||||||
#include <list> // Добавляем include для std::list
|
#include <list>
|
||||||
#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
|
||||||
@ -28,7 +27,7 @@ public:
|
|||||||
void checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView); // Добавляем новый метод
|
void checkMouseIntersection(int mouseX, int mouseY, const Matrix4f& projectionModelView); // Добавляем новый метод
|
||||||
|
|
||||||
std::shared_ptr<ZL::Texture> testObjTexturePtr;
|
std::shared_ptr<ZL::Texture> testObjTexturePtr;
|
||||||
std::shared_ptr<ZL::Texture> roomTexturePtr;
|
//std::shared_ptr<ZL::Texture> roomTexturePtr;
|
||||||
std::shared_ptr<ZL::Texture> coneTexturePtr;
|
std::shared_ptr<ZL::Texture> coneTexturePtr;
|
||||||
|
|
||||||
//ZL::VertexDataStruct colorCubeMesh;
|
//ZL::VertexDataStruct colorCubeMesh;
|
||||||
@ -43,11 +42,11 @@ public:
|
|||||||
ZL::BoneSystem violaWalkModel;
|
ZL::BoneSystem violaWalkModel;
|
||||||
ZL::VertexRenderStruct violaWalkModelMutable;
|
ZL::VertexRenderStruct violaWalkModelMutable;
|
||||||
|
|
||||||
ZL::VertexDataStruct textMesh;
|
std::vector<ZL::VertexDataStruct> preloadedRoomMeshArr;
|
||||||
ZL::VertexRenderStruct textMeshMutable;
|
|
||||||
|
|
||||||
ZL::VertexDataStruct coneMesh; // Раскомментировали
|
|
||||||
ZL::VertexRenderStruct coneMeshMutable; // Раскомментировали
|
//ZL::VertexDataStruct coneMesh; // Раскомментировали
|
||||||
|
//ZL::VertexRenderStruct coneMeshMutable; // Раскомментировали
|
||||||
|
|
||||||
std::vector<ZL::ActiveObject> activeObjects;
|
std::vector<ZL::ActiveObject> activeObjects;
|
||||||
std::vector<ZL::Room> rooms;
|
std::vector<ZL::Room> rooms;
|
||||||
@ -72,18 +71,19 @@ public:
|
|||||||
std::thread loadingThread;
|
std::thread loadingThread;
|
||||||
bool sideThreadLoadingCompleted = false;
|
bool sideThreadLoadingCompleted = false;
|
||||||
|
|
||||||
|
int current_room_index;
|
||||||
private:
|
private:
|
||||||
|
|
||||||
//int animationCounter = 0;
|
//int animationCounter = 0;
|
||||||
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
int lastMouseX = 0; // Добавляем переменные для хранения позиции мыши
|
||||||
int lastMouseY = 0;
|
int lastMouseY = 0;
|
||||||
int current_room_index;
|
|
||||||
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
|
bool isPointInObject(int screenX, int screenY, int objectScreenX, int objectScreenY) const;
|
||||||
void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод
|
void worldToScreenCoordinates(Vector3f objectPos, // Добавляем метод
|
||||||
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}; // Зона для ходьбы 800x800
|
BoundaryBox walkArea{800.0f, 800.0f}; // Зона для ходьбы 800x800
|
||||||
CollisionManager collisionMgr; // Добавляем менеджер коллизий
|
|
||||||
};
|
};
|
||||||
|
|
||||||
} // namespace ZL
|
} // namespace ZL
|
||||||
|
|||||||
@ -171,9 +171,8 @@ void RenderSystem::drawWorld(GameObjectManager& gameObjects) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
// Draw room
|
// Draw room
|
||||||
glBindTexture(GL_TEXTURE_2D, gameObjects.roomTexturePtr->getTexID());
|
glBindTexture(GL_TEXTURE_2D, gameObjects.rooms[gameObjects.current_room_index].roomTexture->getTexID());
|
||||||
renderer.DrawVertexRenderStruct(gameObjects.textMeshMutable);
|
renderer.DrawVertexRenderStruct(gameObjects.rooms[gameObjects.current_room_index].textMeshMutable);
|
||||||
|
|
||||||
|
|
||||||
Matrix4f latestProjectionModelView = renderer.GetProjectionModelViewMatrix();
|
Matrix4f latestProjectionModelView = renderer.GetProjectionModelViewMatrix();
|
||||||
|
|
||||||
|
|||||||
12
Room.h
12
Room.h
@ -4,8 +4,9 @@
|
|||||||
#include "Math.h"
|
#include "Math.h"
|
||||||
#include <memory>
|
#include <memory>
|
||||||
#include "ActiveObject.h"
|
#include "ActiveObject.h"
|
||||||
#include <functional>
|
|
||||||
|
|
||||||
|
#include <functional>
|
||||||
|
#include "BoundaryBox.h"
|
||||||
namespace ZL
|
namespace ZL
|
||||||
{
|
{
|
||||||
struct Room{
|
struct Room{
|
||||||
@ -13,7 +14,16 @@ struct Room{
|
|||||||
std::vector<ActiveObject> objects;
|
std::vector<ActiveObject> objects;
|
||||||
std::string sound_name;
|
std::string sound_name;
|
||||||
|
|
||||||
|
ZL::VertexDataStruct textMesh;
|
||||||
|
ZL::VertexRenderStruct textMeshMutable;
|
||||||
|
|
||||||
|
CollisionManager collisionMgr;
|
||||||
|
|
||||||
std::function<void(class GameObjectManager&, size_t)> roomLogic;
|
std::function<void(class GameObjectManager&, size_t)> roomLogic;
|
||||||
|
|
||||||
|
Room()
|
||||||
|
{
|
||||||
|
}
|
||||||
|
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|||||||
Loading…
Reference in New Issue
Block a user