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