2021-09-13 15:53:43 +03:00
|
|
|
//
|
|
|
|
// Created by Иван Ильин on 13.01.2021.
|
|
|
|
//
|
|
|
|
|
|
|
|
#ifndef ENGINE_WORLD_H
|
|
|
|
#define ENGINE_WORLD_H
|
|
|
|
|
|
|
|
#include <map>
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
#include "Camera.h"
|
2021-10-22 19:42:32 +03:00
|
|
|
#include "Screen.h"
|
2021-09-19 11:25:10 +03:00
|
|
|
#include "physics/RigidBody.h"
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
struct IntersectionInformation final {
|
|
|
|
const Vec3D pointOfIntersection;
|
|
|
|
const double distanceToObject;
|
|
|
|
const Triangle intersectedTriangle;
|
|
|
|
const ObjectNameTag objectName;
|
|
|
|
const std::shared_ptr<RigidBody> obj;
|
|
|
|
const bool intersected;
|
|
|
|
};
|
|
|
|
|
2021-10-12 20:18:56 +03:00
|
|
|
class World final {
|
2021-09-13 15:53:43 +03:00
|
|
|
private:
|
2021-10-17 10:21:10 +03:00
|
|
|
std::map<ObjectNameTag, std::shared_ptr<RigidBody>> _objects;
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-31 11:39:08 +03:00
|
|
|
void checkCollision(const ObjectNameTag &tag);
|
2021-11-09 22:54:20 +03:00
|
|
|
public:
|
|
|
|
World() = default;
|
2021-10-31 11:39:08 +03:00
|
|
|
|
2021-09-19 11:25:10 +03:00
|
|
|
void update();
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2022-02-24 07:11:04 +03:00
|
|
|
std::shared_ptr<RigidBody> addBody(std::shared_ptr<RigidBody> mesh);
|
2021-10-31 11:39:08 +03:00
|
|
|
std::shared_ptr<RigidBody> body(const ObjectNameTag &tag);
|
|
|
|
void removeBody(const ObjectNameTag &tag);
|
2022-02-24 07:11:04 +03:00
|
|
|
std::shared_ptr<RigidBody> loadBody(const ObjectNameTag &tag, const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1});
|
2021-11-09 22:54:20 +03:00
|
|
|
void loadMap(const std::string &filename, const Vec3D &scale = Vec3D{1, 1, 1});
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
// std::string skipTags is a string that consist of all objects we want to skip in ray casting
|
2021-10-31 11:39:08 +03:00
|
|
|
IntersectionInformation rayCast(const Vec3D &from, const Vec3D &to, const std::string &skipTags = "");
|
2021-09-13 15:53:43 +03:00
|
|
|
|
2021-10-22 19:42:32 +03:00
|
|
|
std::map<ObjectNameTag, std::shared_ptr<RigidBody>>::iterator begin() { return _objects.begin(); }
|
|
|
|
std::map<ObjectNameTag, std::shared_ptr<RigidBody>>::iterator end() { return _objects.end(); }
|
2021-09-13 15:53:43 +03:00
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
#endif //INC_3DZAVR_WORLD_H
|