Removed physics for now.
This commit is contained in:
14
archive/physics_components/3d/CMakeLists.txt
Normal file
14
archive/physics_components/3d/CMakeLists.txt
Normal file
@ -0,0 +1,14 @@
|
||||
# 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
|
||||
)
|
35
archive/physics_components/3d/CapsuleCollider.cpp
Normal file
35
archive/physics_components/3d/CapsuleCollider.cpp
Normal file
@ -0,0 +1,35 @@
|
||||
// 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;
|
||||
}
|
28
archive/physics_components/3d/CapsuleCollider.hpp
Normal file
28
archive/physics_components/3d/CapsuleCollider.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
// 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;
|
||||
};
|
||||
}
|
37
archive/physics_components/3d/CharacterController3D.cpp
Normal file
37
archive/physics_components/3d/CharacterController3D.cpp
Normal file
@ -0,0 +1,37 @@
|
||||
// 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);
|
||||
}
|
23
archive/physics_components/3d/CharacterController3D.hpp
Normal file
23
archive/physics_components/3d/CharacterController3D.hpp
Normal file
@ -0,0 +1,23 @@
|
||||
// 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;
|
||||
};
|
||||
}
|
22
archive/physics_components/3d/Collider3D.cpp
Normal file
22
archive/physics_components/3d/Collider3D.cpp
Normal file
@ -0,0 +1,22 @@
|
||||
// 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;
|
||||
}
|
58
archive/physics_components/3d/Collider3D.hpp
Normal file
58
archive/physics_components/3d/Collider3D.hpp
Normal file
@ -0,0 +1,58 @@
|
||||
// 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;
|
||||
};
|
||||
}
|
32
archive/physics_components/3d/CubeCollider.cpp
Normal file
32
archive/physics_components/3d/CubeCollider.cpp
Normal file
@ -0,0 +1,32 @@
|
||||
// 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;
|
||||
}
|
28
archive/physics_components/3d/CubeCollider.hpp
Normal file
28
archive/physics_components/3d/CubeCollider.hpp
Normal file
@ -0,0 +1,28 @@
|
||||
// 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;
|
||||
};
|
||||
}
|
31
archive/physics_components/3d/SphereCollider.cpp
Normal file
31
archive/physics_components/3d/SphereCollider.cpp
Normal file
@ -0,0 +1,31 @@
|
||||
// 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
|
||||
);
|
||||
}
|
25
archive/physics_components/3d/SphereCollider.hpp
Normal file
25
archive/physics_components/3d/SphereCollider.hpp
Normal file
@ -0,0 +1,25 @@
|
||||
// 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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user