Removed physics for now.
This commit is contained in:
@ -10,10 +10,9 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Scene::Scene(std::weak_ptr<DawnGame> game) {
|
||||
Scene::Scene(const std::weak_ptr<DawnGame> game) {
|
||||
this->game = game;
|
||||
this->nextId = 0;
|
||||
this->physics = new ScenePhysicsManager(this);
|
||||
}
|
||||
|
||||
void Scene::update() {
|
||||
@ -39,8 +38,6 @@ std::shared_ptr<SceneItem> Scene::createSceneItem() {
|
||||
}
|
||||
|
||||
Scene::~Scene() {
|
||||
delete this->physics;
|
||||
|
||||
// Invoke cleanup.
|
||||
auto it = this->items.begin();
|
||||
while(it != this->items.end()) {
|
||||
|
@ -5,9 +5,6 @@
|
||||
|
||||
#pragma once
|
||||
#include "asset/Asset.hpp"
|
||||
#include "display/shader/ShaderManager.hpp"
|
||||
#include "scene/debug/SceneDebugLine.hpp"
|
||||
#include "physics/ScenePhysicsManager.hpp"
|
||||
#include "state/StateEvent.hpp"
|
||||
#include "state/StateOwner.hpp"
|
||||
|
||||
@ -19,6 +16,7 @@ namespace Dawn {
|
||||
|
||||
typedef int32_t sceneitemid_t;
|
||||
|
||||
// Scene Item Forwarders
|
||||
template<class T>
|
||||
std::shared_ptr<T> _sceneForwardGetComponent(std::shared_ptr<SceneItem> item);
|
||||
|
||||
@ -35,7 +33,6 @@ namespace Dawn {
|
||||
|
||||
public:
|
||||
std::weak_ptr<DawnGame> game;
|
||||
ScenePhysicsManager *physics;
|
||||
StateEvent<float_t> eventSceneUpdate;
|
||||
StateEvent<float_t> eventSceneUnpausedUpdate;
|
||||
|
||||
@ -44,7 +41,7 @@ namespace Dawn {
|
||||
*
|
||||
* @param game Reference to the game that this scene belongs to.
|
||||
*/
|
||||
Scene(std::weak_ptr<DawnGame> game);
|
||||
Scene(const std::weak_ptr<DawnGame> game);
|
||||
|
||||
/**
|
||||
* Perform a one frame synchronous tick on the current scene. This may
|
||||
|
@ -9,12 +9,12 @@
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SceneItem::SceneItem(std::weak_ptr<Scene> scene, sceneitemid_t id) :
|
||||
SceneItem::SceneItem(const std::weak_ptr<Scene> scene, const sceneitemid_t id) :
|
||||
transformLocal(1.0f),
|
||||
transformWorld(1.0f)
|
||||
transformWorld(1.0f),
|
||||
scene(scene),
|
||||
id(id)
|
||||
{
|
||||
this->id = id;
|
||||
this->scene = scene;
|
||||
this->updateLocalValuesFromLocalTransform();
|
||||
}
|
||||
|
||||
@ -96,7 +96,6 @@ void SceneItem::updateWorldTransformFromLocalTransform() {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void SceneItem::updateLocalTransformFromWorldTransform() {
|
||||
glm::mat4 parentMat(1.0f);
|
||||
auto parent = this->getParent();
|
||||
|
@ -41,9 +41,8 @@ namespace Dawn {
|
||||
void updateChildrenTransforms();
|
||||
|
||||
public:
|
||||
std::weak_ptr<Scene> scene;
|
||||
sceneitemid_t id;
|
||||
// I have no idea if I'm keeping this
|
||||
const std::weak_ptr<Scene> scene;
|
||||
const sceneitemid_t id;
|
||||
StateEvent<> eventTransformUpdated;
|
||||
|
||||
/**
|
||||
@ -53,7 +52,7 @@ namespace Dawn {
|
||||
* @param scene Weak pointer to the Scene that this SceneItem belongs to.
|
||||
* @param id Scene Item ID that the Scene assigned this SceneItem.
|
||||
*/
|
||||
SceneItem(std::weak_ptr<Scene> scene, sceneitemid_t id);
|
||||
SceneItem(const std::weak_ptr<Scene> scene, const sceneitemid_t id);
|
||||
|
||||
/**
|
||||
* Called by the Scene the frame after we were constructed so we can begin
|
||||
|
@ -35,10 +35,6 @@ std::shared_ptr<DawnGame> SceneItemComponent::getGame() {
|
||||
return game;
|
||||
}
|
||||
|
||||
ScenePhysicsManager * SceneItemComponent::getPhysics() {
|
||||
return this->getScene()->physics;
|
||||
}
|
||||
|
||||
void SceneItemComponent::onStart() {
|
||||
|
||||
}
|
||||
|
@ -51,13 +51,6 @@ namespace Dawn {
|
||||
*/
|
||||
std::shared_ptr<DawnGame> getGame();
|
||||
|
||||
/**
|
||||
* Shorthand to return the physics manager that the scene this item
|
||||
* belongs to, belongs to.
|
||||
* @return The scene physics manager.
|
||||
*/
|
||||
ScenePhysicsManager * getPhysics();
|
||||
|
||||
/**
|
||||
* Same as init, but intended for your subclass to override.
|
||||
*/
|
||||
|
@ -7,6 +7,5 @@
|
||||
add_subdirectory(debug)
|
||||
add_subdirectory(display)
|
||||
add_subdirectory(example)
|
||||
add_subdirectory(physics)
|
||||
add_subdirectory(scene)
|
||||
add_subdirectory(ui)
|
@ -7,7 +7,6 @@
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "display/RenderTarget.hpp"
|
||||
#include "scene/Scene.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum CameraType {
|
||||
|
@ -4,6 +4,7 @@
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "util/flag.hpp"
|
||||
#include "display/Tileset.hpp"
|
||||
#include "scene/components/display/mesh/QuadMeshHost.hpp"
|
||||
|
||||
|
@ -1,16 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "BoxCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
BoxCollider::BoxCollider(std::weak_ptr<SceneItem> item) : Collider2D(item) {
|
||||
|
||||
}
|
||||
|
||||
enum Collider2DType BoxCollider::getColliderType() {
|
||||
return COLLIDER2D_TYPE_BOX;
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider2D.hpp"
|
||||
#include "physics/2d/Box.hpp"
|
||||
#include "physics/2d/Physics2D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class BoxCollider : public Collider2D {
|
||||
public:
|
||||
// @optional
|
||||
glm::vec2 min = glm::vec2(-0.5f, -0.5f);
|
||||
// @optional
|
||||
glm::vec2 max = glm::vec2( 0.5f, 0.5f);
|
||||
|
||||
BoxCollider(std::weak_ptr<SceneItem> item);
|
||||
enum Collider2DType getColliderType() override;
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# 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
|
||||
BoxCollider.cpp
|
||||
Collider2D.cpp
|
||||
CharacterController2D.cpp
|
||||
SolidController2D.cpp
|
||||
TriggerController2D.cpp
|
||||
)
|
@ -1,92 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CharacterController2D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
CharacterController2D::CharacterController2D(std::weak_ptr<SceneItem> i) :
|
||||
SceneItemComponent(i)
|
||||
{
|
||||
}
|
||||
|
||||
void CharacterController2D::onStart() {
|
||||
useEvent([&](float_t delta){
|
||||
// if(velocity == glm::vec2(0, 0)) return;
|
||||
|
||||
// Common variables
|
||||
auto item = this->item.lock();
|
||||
auto myCollider = item->getComponent<Collider2D>();
|
||||
|
||||
// Friction
|
||||
velocity -= velocity * friction * delta;
|
||||
|
||||
// Solid Collision Check
|
||||
glm::vec2 moveAmount;
|
||||
if(myCollider == nullptr) {
|
||||
moveAmount = velocity;
|
||||
} else {
|
||||
// Perform sweep
|
||||
auto allColliders = getScene()->findComponents<SolidController2D>();
|
||||
auto itColliders = allColliders.begin();
|
||||
|
||||
struct CharacterController2DCollisionEventInfo info;
|
||||
bool_t result = false;
|
||||
|
||||
// Check for collisions, definitely not working 100% yet
|
||||
while(itColliders != allColliders.end()) {
|
||||
auto c = *itColliders;
|
||||
++itColliders;
|
||||
auto cItem = c->item.lock();
|
||||
if(cItem == item || cItem->isChildOf(item)) continue;
|
||||
result = c->getCollidingResult(
|
||||
velocity,
|
||||
myCollider,
|
||||
info.normal,
|
||||
info.entryTime,
|
||||
info.exitTime,
|
||||
info.entryPoint,
|
||||
info.exitPoint
|
||||
) && info.entryTime <= delta;
|
||||
|
||||
if(result) {
|
||||
info.collider = c;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if(result) {
|
||||
moveAmount = glm::vec2(0, 0);
|
||||
velocity = glm::vec2(0, 0);
|
||||
this->eventCollision.invoke(info);
|
||||
} else {
|
||||
moveAmount = velocity;
|
||||
}
|
||||
}
|
||||
|
||||
if(moveAmount != glm::vec2(0, 0)) {
|
||||
item->setLocalPosition(
|
||||
item->getLocalPosition() + (glm::vec3(moveAmount.x, 0, moveAmount.y) * delta)
|
||||
);
|
||||
}
|
||||
|
||||
// Now perform trigger collision check
|
||||
auto allTriggers = getScene()->findComponents<TriggerController2D>();
|
||||
auto itTriggers = allTriggers.begin();
|
||||
while(itTriggers != allTriggers.end()) {
|
||||
auto c = *itTriggers;
|
||||
++itTriggers;
|
||||
auto cItem = c->item.lock();
|
||||
if(cItem == item || cItem->isChildOf(item)) continue;
|
||||
if(c->getCollidingResult(myCollider)) {
|
||||
c->eventTriggerEnter.invoke(this);
|
||||
}
|
||||
}
|
||||
|
||||
// Stop velocity near zero.
|
||||
if(mathAbs<float_t>(velocity.x) <= 0.001f) velocity.x = 0;
|
||||
if(mathAbs<float_t>(velocity.y) <= 0.001f) velocity.y = 0;
|
||||
}, getScene()->eventSceneUpdate);
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "SolidController2D.hpp"
|
||||
#include "TriggerController2D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct CharacterController2DCollisionEventInfo {
|
||||
std::shared_ptr<SolidController2D> collider;
|
||||
glm::vec2 normal;
|
||||
float_t entryTime;
|
||||
float_t exitTime;
|
||||
glm::vec2 entryPoint;
|
||||
glm::vec2 exitPoint;
|
||||
};
|
||||
|
||||
class CharacterController2D : public SceneItemComponent {
|
||||
public:
|
||||
// @optional
|
||||
glm::vec2 velocity = glm::vec2(0, 0);
|
||||
// @optional
|
||||
float_t friction = 12.0f;
|
||||
|
||||
StateEvent<struct CharacterController2DCollisionEventInfo> eventCollision;
|
||||
|
||||
CharacterController2D(std::weak_ptr<SceneItem> i);
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -1,13 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Collider2D.hpp"
|
||||
#include "BoxCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Collider2D::Collider2D(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
|
||||
|
||||
}
|
@ -1,34 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "physics/2d/Box.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
enum Collider2DType {
|
||||
COLLIDER2D_TYPE_BOX
|
||||
};
|
||||
|
||||
struct Collider2DAxisAlignedCollidingResult {
|
||||
glm::vec2 normal;
|
||||
float_t entryTime;
|
||||
float_t exitTime;
|
||||
glm::vec2 entryPoint;
|
||||
glm::vec2 exitPoint;
|
||||
};
|
||||
|
||||
class Collider2D : public SceneItemComponent {
|
||||
public:
|
||||
Collider2D(std::weak_ptr<SceneItem> item);
|
||||
|
||||
/**
|
||||
* Returns which type of collider this is.
|
||||
*
|
||||
* @return The collider type that this is.
|
||||
*/
|
||||
virtual enum Collider2DType getColliderType() = 0;
|
||||
};
|
||||
}
|
@ -1,69 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SolidController2D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SolidController2D::SolidController2D(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> SolidController2D::getDependencies() {
|
||||
return {
|
||||
(this->collider = item.lock()->getComponent<Collider2D>())
|
||||
};
|
||||
}
|
||||
|
||||
bool_t SolidController2D::getCollidingResult(
|
||||
glm::vec2 movement,
|
||||
std::shared_ptr<Collider2D> movingObject,
|
||||
glm::vec2 &normal,
|
||||
float_t &entryTime,
|
||||
float_t &exitTime,
|
||||
glm::vec2 &entryPoint,
|
||||
glm::vec2 &exitPoint
|
||||
) {
|
||||
assertNotNull(this->collider, "SolidController2D::getCollidingResult: Collider cannot be null");
|
||||
assertNotNull(movingObject, "SolidController2D::getCollidingResult: Moving object cannot be null");
|
||||
if(movement.x == 0 && movement.y == 0) return false;
|
||||
|
||||
auto myPos = physics3Dto2D(movingObject->item.lock()->getWorldPosition());
|
||||
|
||||
// Check what the moving object is
|
||||
switch(movingObject->getColliderType()) {
|
||||
case COLLIDER2D_TYPE_BOX: {
|
||||
auto box1 = std::static_pointer_cast<BoxCollider>(movingObject);
|
||||
assertNotNull(box1, "SolidController2D::getCollidingResult: Moving object is not a BoxCollider");
|
||||
|
||||
// Box VS (this)?
|
||||
switch(this->collider->getColliderType()) {
|
||||
case COLLIDER2D_TYPE_BOX: {
|
||||
auto box2 = std::static_pointer_cast<BoxCollider>(this->collider);
|
||||
assertNotNull(box2, "SolidController2D::getCollidingResult: Collider is not a BoxCollider");
|
||||
auto otherPos = physics3Dto2D(box2->item.lock()->getWorldPosition());
|
||||
|
||||
return boxCheckCollision(
|
||||
myPos, box1->min, box1->max,
|
||||
otherPos, box2->min, box2->max,
|
||||
movement,
|
||||
normal, entryTime, exitTime, entryPoint, exitPoint
|
||||
);
|
||||
}
|
||||
|
||||
default: {
|
||||
assertUnreachable("SolidController2D::getCollidingResult: Collider type not implemented");
|
||||
}
|
||||
}
|
||||
break;
|
||||
}
|
||||
|
||||
default: {
|
||||
assertUnreachable("SolidController2D::getCollidingResult: Moving object type not implemented");
|
||||
}
|
||||
}
|
||||
|
||||
assertUnreachable("SolidController2D::getCollidingResult: Should never reach this point");
|
||||
return false;
|
||||
}
|
@ -1,42 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider2D.hpp"
|
||||
#include "BoxCollider.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SolidController2D : public SceneItemComponent {
|
||||
public:
|
||||
std::shared_ptr<Collider2D> collider;
|
||||
|
||||
SolidController2D(std::weak_ptr<SceneItem> item);
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
|
||||
|
||||
/**
|
||||
* Gets the result of checking if two collider bodies are intersecting.
|
||||
* This is performed WITH movement to return entry and exit times.
|
||||
*
|
||||
* @param result Where to store the results of the calculation.
|
||||
* @param movement Movement operation that THIS object is performing.
|
||||
* @param movingObject Moving Object Collider that is being compared.
|
||||
* @param normal Output normal of the intersection.
|
||||
* @param entryTime Output entry time when the two objects will intersect.
|
||||
* @param exitTime Output exit time when the object will pass through.
|
||||
* @param entryPoint Output point in 2D space where object will enter.
|
||||
* @param exitPoint Output point where object will have passed through.
|
||||
* @return True if the two objects will intersect at move otherwise false.
|
||||
*/
|
||||
bool_t getCollidingResult(
|
||||
glm::vec2 movement,
|
||||
std::shared_ptr<Collider2D> movingObject,
|
||||
glm::vec2 &normal,
|
||||
float_t &entryTime,
|
||||
float_t &exitTime,
|
||||
glm::vec2 &entryPoint,
|
||||
glm::vec2 &exitPoint
|
||||
);
|
||||
};
|
||||
}
|
@ -1,51 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "TriggerController2D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
TriggerController2D::TriggerController2D(std::weak_ptr<SceneItem> i) : SceneItemComponent(i) {
|
||||
|
||||
}
|
||||
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> TriggerController2D::getDependencies() {
|
||||
return {
|
||||
(this->collider = this->item.lock()->getComponent<Collider2D>())
|
||||
};
|
||||
}
|
||||
|
||||
bool_t TriggerController2D::getCollidingResult(std::shared_ptr<Collider2D> movingObject) {
|
||||
assertNotNull(this->collider, "TriggerController2D::getCollidingResult: Collider cannot be null");
|
||||
assertNotNull(movingObject, "TriggerController2D::getCollidingResult: Moving object cannot be null");
|
||||
|
||||
switch(movingObject->getColliderType()) {
|
||||
case COLLIDER2D_TYPE_BOX: {
|
||||
auto box1 = std::static_pointer_cast<BoxCollider>(movingObject);
|
||||
assertNotNull(box1, "TriggerController2D::getCollidingResult: Moving object is not a BoxCollider");
|
||||
|
||||
// Box VS ?
|
||||
switch(collider->getColliderType()) {
|
||||
case COLLIDER2D_TYPE_BOX: {
|
||||
auto box2 = std::static_pointer_cast<BoxCollider>(collider);
|
||||
assertNotNull(box2, "TriggerController2D::getCollidingResult: Collider is not a BoxCollider");
|
||||
return boxIsBoxColliding(
|
||||
physics3Dto2D(box1->item.lock()->getWorldPosition()), box1->min, box1->max,
|
||||
physics3Dto2D(box2->item.lock()->getWorldPosition()), box2->min, box2->max
|
||||
);
|
||||
}
|
||||
|
||||
default: {
|
||||
assertUnreachable("TriggerController2D::getCollidingResult: Collider type not implemented");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
default: {
|
||||
assertUnreachable("TriggerController2D::getCollidingResult: Moving object type not implemented");
|
||||
return false;
|
||||
}
|
||||
}
|
||||
}
|
@ -1,27 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider2D.hpp"
|
||||
#include "BoxCollider.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class CharacterController2D;
|
||||
|
||||
class TriggerController2D : public SceneItemComponent {
|
||||
public:
|
||||
std::shared_ptr<Collider2D> collider;
|
||||
StateEvent<CharacterController2D*> eventTriggerEnter;
|
||||
|
||||
TriggerController2D(std::weak_ptr<SceneItem> i);
|
||||
std::vector<std::shared_ptr<SceneItemComponent>> getDependencies() override;
|
||||
|
||||
/**
|
||||
* Returns whether or not the given moving object is colliding with this
|
||||
* trigger collider.
|
||||
*/
|
||||
bool_t getCollidingResult(std::shared_ptr<Collider2D> movingObject);
|
||||
};
|
||||
}
|
@ -1,14 +0,0 @@
|
||||
# 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
|
||||
Collider3D.cpp
|
||||
CubeCollider.cpp
|
||||
CapsuleCollider.cpp
|
||||
SphereCollider.cpp
|
||||
CharacterController3D.cpp
|
||||
)
|
@ -1,35 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CapsuleCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
CapsuleCollider::CapsuleCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
|
||||
|
||||
}
|
||||
|
||||
bool_t CapsuleCollider::performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) {
|
||||
assertNotNull(result, "CapsuleCollider::performRaycast: Result cannot be null");
|
||||
|
||||
return raytestCapsule(
|
||||
ray,
|
||||
{
|
||||
.height = this->height,
|
||||
.radius = this->radius,
|
||||
.origin = item.lock()->getWorldPosition()
|
||||
},
|
||||
&result->point,
|
||||
&result->normal,
|
||||
&result->distance
|
||||
);
|
||||
}
|
||||
|
||||
enum Collider3DType CapsuleCollider::getColliderType() {
|
||||
return COLLIDER3D_TYPE_CAPSULE;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider3D.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class CapsuleCollider : public Collider3D {
|
||||
protected:
|
||||
bool_t performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) override;
|
||||
|
||||
public:
|
||||
// @optional
|
||||
float_t height = 1;
|
||||
// @optional
|
||||
float_t radius = 0.5f;
|
||||
|
||||
CapsuleCollider(std::weak_ptr<SceneItem> item);
|
||||
|
||||
enum Collider3DType getColliderType() override;
|
||||
};
|
||||
}
|
@ -1,37 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CharacterController3D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
CharacterController3D::CharacterController3D(std::weak_ptr<SceneItem> item) :
|
||||
SceneItemComponent(item)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
void CharacterController3D::onStart() {
|
||||
useEvent([&](float_t delta){
|
||||
auto item = this->item.lock();
|
||||
|
||||
// Friction
|
||||
velocity -= glm::vec3(velocity.x, 0, velocity.z) * friction * delta;
|
||||
|
||||
// Gravity
|
||||
velocity += this->gravity * delta;
|
||||
|
||||
auto myCollider = item->getComponent<Collider3D>();
|
||||
auto colliders = getScene()->findComponents<Collider3D>();
|
||||
auto itCollider = colliders.begin();
|
||||
// while(itCollider != colliders.end()) {
|
||||
// (*itCollider)->
|
||||
// ++itCollider;
|
||||
// }
|
||||
|
||||
// Move / Update
|
||||
item->setLocalPosition(item->getLocalPosition() + (velocity * delta));
|
||||
}, getScene()->eventSceneUpdate);
|
||||
}
|
@ -1,23 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class CharacterController3D : public SceneItemComponent {
|
||||
public:
|
||||
// @optional
|
||||
glm::vec3 velocity = glm::vec3(0, 0, 0);
|
||||
// @optional
|
||||
glm::vec3 gravity = glm::vec3(0, -1, 0);
|
||||
// @optional
|
||||
float_t friction = 12.0f;
|
||||
|
||||
CharacterController3D(std::weak_ptr<SceneItem> item);
|
||||
|
||||
void onStart() override;
|
||||
};
|
||||
}
|
@ -1,22 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "Collider3D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
Collider3D::Collider3D(std::weak_ptr<SceneItem> item) : SceneItemComponent(item) {
|
||||
|
||||
}
|
||||
|
||||
bool_t Collider3D::raycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) {
|
||||
assertNotNull(result, "Collider3D::raycast: Result cannot be null");
|
||||
if(!this->performRaycast(result, ray)) return false;
|
||||
result->collider = this;
|
||||
return true;
|
||||
}
|
@ -1,58 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "scene/SceneItemComponent.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
struct Collider3DRayResult {
|
||||
glm::vec3 point;
|
||||
float_t distance;
|
||||
glm::vec3 normal;
|
||||
Collider3D *collider;
|
||||
};
|
||||
|
||||
struct Collider3DAABBSweepResult {
|
||||
};
|
||||
|
||||
enum Collider3DType {
|
||||
COLLIDER3D_TYPE_CUBE,
|
||||
COLLIDER3D_TYPE_CAPSULE,
|
||||
COLLIDER3D_TYPE_SPHERE
|
||||
};
|
||||
|
||||
class Collider3D : public SceneItemComponent {
|
||||
protected:
|
||||
/**
|
||||
* Internal per-collider raycast implementation. Same arguments as
|
||||
* Collider3D::raycast()
|
||||
*/
|
||||
virtual bool_t performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) = 0;
|
||||
|
||||
public:
|
||||
Collider3D(std::weak_ptr<SceneItem> item);
|
||||
|
||||
/**
|
||||
* Perform a raycast against this collider.
|
||||
*
|
||||
* @param result Where to store the result of the raycast collision
|
||||
* @param ray The ray to cast against.
|
||||
* @return True if the ray intercepts this collider, otherwise false.
|
||||
*/
|
||||
bool_t raycast(struct Collider3DRayResult *result, struct Ray3D ray);
|
||||
|
||||
/**
|
||||
* Returns which type of collider this is. Useful for performing dynamic
|
||||
* casting in your event listeners.
|
||||
*
|
||||
* @return The collider type this is.
|
||||
*/
|
||||
virtual enum Collider3DType getColliderType() = 0;
|
||||
};
|
||||
}
|
@ -1,32 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "CubeCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
CubeCollider::CubeCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
|
||||
|
||||
}
|
||||
|
||||
bool_t CubeCollider::performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) {
|
||||
assertNotNull(result, "CubeCollider::performRaycast: Result cannot be null");
|
||||
|
||||
return Dawn::raytestCube(
|
||||
ray,
|
||||
{ .min = this->min, .max = this->max },
|
||||
item.lock()->getWorldTransform(),
|
||||
&result->point,
|
||||
&result->normal,
|
||||
&result->distance
|
||||
);
|
||||
}
|
||||
|
||||
enum Collider3DType CubeCollider::getColliderType() {
|
||||
return COLLIDER3D_TYPE_CUBE;
|
||||
}
|
@ -1,28 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider3D.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class CubeCollider : public Collider3D {
|
||||
protected:
|
||||
bool_t performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) override;
|
||||
|
||||
public:
|
||||
// @optional
|
||||
glm::vec3 min = glm::vec3(-0.5f, -0.5f, -0.5f);
|
||||
// @optional
|
||||
glm::vec3 max = glm::vec3(0.5f, 0.5f, 0.5f);
|
||||
|
||||
CubeCollider(std::weak_ptr<SceneItem> item);
|
||||
|
||||
enum Collider3DType getColliderType() override;
|
||||
};
|
||||
}
|
@ -1,31 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#include "SphereCollider.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
SphereCollider::SphereCollider(std::weak_ptr<SceneItem> item) : Collider3D(item) {
|
||||
|
||||
}
|
||||
|
||||
enum Collider3DType SphereCollider::getColliderType() {
|
||||
return COLLIDER3D_TYPE_SPHERE;
|
||||
}
|
||||
|
||||
bool_t SphereCollider::performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) {
|
||||
assertNotNull(result, "SphereCollider::performRaycast: Result cannot be null");
|
||||
|
||||
return raytestSphere(
|
||||
ray,
|
||||
{ .center = item.lock()->getLocalPosition(), .radius = this->radius },
|
||||
&result->point,
|
||||
&result->normal,
|
||||
&result->distance
|
||||
);
|
||||
}
|
@ -1,25 +0,0 @@
|
||||
// Copyright (c) 2023 Dominic Masters
|
||||
//
|
||||
// This software is released under the MIT License.
|
||||
// https://opensource.org/licenses/MIT
|
||||
|
||||
#pragma once
|
||||
#include "Collider3D.hpp"
|
||||
|
||||
namespace Dawn {
|
||||
class SphereCollider : public Collider3D {
|
||||
protected:
|
||||
bool_t performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) override;
|
||||
|
||||
public:
|
||||
// @optional
|
||||
float_t radius = 1.0f;
|
||||
|
||||
SphereCollider(std::weak_ptr<SceneItem> item);
|
||||
|
||||
enum Collider3DType getColliderType() override;
|
||||
};
|
||||
}
|
@ -1,8 +0,0 @@
|
||||
# Copyright (c) 2023 Dominic Masters
|
||||
#
|
||||
# This software is released under the MIT License.
|
||||
# https://opensource.org/licenses/MIT
|
||||
|
||||
# Subdirs
|
||||
add_subdirectory(2d)
|
||||
add_subdirectory(3d)
|
@ -5,6 +5,7 @@
|
||||
|
||||
#include "UISimpleMenu.hpp"
|
||||
#include "game/DawnGame.hpp"
|
||||
#include "physics/3d/Ray3D.hpp"
|
||||
|
||||
using namespace Dawn;
|
||||
|
||||
@ -108,9 +109,9 @@ void UISimpleMenu::onStart() {
|
||||
ray,
|
||||
glm::vec2(0, 0), size,
|
||||
highlight->item.lock()->getWorldTransform(),
|
||||
&point,
|
||||
&normal,
|
||||
&distance
|
||||
point,
|
||||
normal,
|
||||
distance
|
||||
)) continue;
|
||||
|
||||
this->menu->menuX = item->menuX;
|
||||
|
Reference in New Issue
Block a user