Moved Scene implementation around

This commit is contained in:
2023-02-21 20:59:42 -08:00
parent cd686c2bd6
commit c065ab08b3
42 changed files with 540 additions and 459 deletions

View File

@ -0,0 +1,15 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Box.hpp"
using namespace Dawn;
bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max) {
return (
point.x >= min.x && point.x <= max.x &&
point.y >= min.y && point.y <= max.y
);
}

View File

@ -0,0 +1,20 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp"
namespace Dawn {
/**
* Checks if a given point is within the 2D Boundaries of an object.
*
* @param point Point to test.
* @param min Minimum point on the box.
* @param max Maximum point on the box.
* @return True if the point is within the box.
*/
static bool_t boxIsPointInside(glm::vec2 point, glm::vec2 min, glm::vec2 max);
}

View File

@ -0,0 +1,11 @@
# Copyright (c) 2023 Dominic Masters
#
# This software is released under the MIT License.
# https://opensource.org/licenses/MIT
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
Box.cpp
Ray2D.cpp
)

View File

@ -4,14 +4,9 @@
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "assert/assert.hpp
namespace Dawn {
class DawnGame;
class PhysicsManager {
public:
DawnGame *game;
PhysicsManager(DawnGame *game);
};
}

View File

View File

@ -0,0 +1,27 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "Ray2D.hpp"
using namespace Dawn;
Ray2D::Ray2D(glm::vec2 pos, glm::vec2 dir) :
position(pos),
direction(dir)
{
}
bool_t Ray2D::intersects(struct Ray2D ray, glm::vec2 *out) {
glm::vec2 j = this->position - ray.position;
float_t f = -ray.direction.x * direction.y + direction.x * ray.direction.y;
float_t s = (-direction.y * j.x + direction.x * j.y) / f;
float_t t = (ray.direction.x * j.y - ray.direction.y * j.x) / f;
if (s >= 0 && s <= 1 && t >= 0 && t <= 1) {
*out = position + (t * direction);
return true;
}
return false;
}

View File

@ -0,0 +1,31 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
namespace Dawn {
struct Ray2D {
const glm::vec2 position;
const glm::vec2 direction;
/**
* Constructs a new Ray 2D.
*
* @param position Position of this ray in 2D space.
* @param direction Direction from the origin in 2D space of this ray.
*/
Ray2D(glm::vec2 position, glm::vec2 direction);
/**
* Checks whether one ray is intersecting with another ray.
*
* @param ray The ray to check if this ray is intersecting.
* @param out The point in space where the two rays intersect.
* @return True if they intersect, otherwise false.
*/
bool_t intersects(struct Ray2D ray, glm::vec2 *out);
};
}

View File

@ -6,8 +6,9 @@
# Sources
target_sources(${DAWN_TARGET_NAME}
PRIVATE
PhysicsManager.cpp
ScenePhysicsManager.cpp
)
# Subdirs
add_subdirectory(2d)
add_subdirectory(3d)

View File

@ -3,11 +3,15 @@
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#include "PhysicsManager.hpp"
#include "game/DawnGame.hpp"
#include "ScenePhysicsManager.hpp"
#include "scene/Scene.hpp"
using namespace Dawn;
PhysicsManager::PhysicsManager(DawnGame *game) {
this->game = game;
ScenePhysicsManager::ScenePhysicsManager() {
}
void ScenePhysicsManager::update() {
}

View File

@ -0,0 +1,29 @@
// Copyright (c) 2023 Dominic Masters
//
// This software is released under the MIT License.
// https://opensource.org/licenses/MIT
#pragma once
#include "dawnlibs.hpp"
#include "scene/SceneItem.hpp"
typedef int64_t scenechunk_t;
#define SCENE_CHUNK_SIZE_2D 512
namespace Dawn {
class Scene;
class ScenePhysicsManager {
protected:
std::map<scenechunk_t, std::vector<SceneItem*>> chunkItems;
std::map<SceneItem*, std::vector<scenechunk_t>> itemChunks;
public:
ScenePhysicsManager();
void update();
friend class Scene;
};
}