Starting work on capsules.

This commit is contained in:
2023-03-16 22:30:57 -07:00
parent c6391f1111
commit 11af9d147a
13 changed files with 435 additions and 70 deletions

View File

@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
PRIVATE
Collider3D.cpp
CubeCollider.cpp
CapsuleCollider.cpp
)

View 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(SceneItem *item) : Collider3D(item) {
}
bool_t CapsuleCollider::performRaycast(
struct Collider3DRayResult *result,
struct Ray3D ray
) {
assertNotNull(result);
return raytestCapsule(
ray,
{
.height = this->height,
.radius = this->radius,
.origin = this->transform->getWorldPosition()
},
&result->point,
&result->normal,
&result->distance
);
}
enum Collider3DType CapsuleCollider::getColliderType() {
return COLLIDER3D_TYPE_CAPSULE;
}

View File

@ -0,0 +1,26 @@
// 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:
float_t height = 1;
float_t radius = 0.5f;
CapsuleCollider(SceneItem *item);
enum Collider3DType getColliderType() override;
};
}

View File

@ -1,53 +1,54 @@
// 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;
};
enum Collider3DType {
COLLIDER3D_TYPE_CUBE
};
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(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;
};
// 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;
};
enum Collider3DType {
COLLIDER3D_TYPE_CUBE,
COLLIDER3D_TYPE_CAPSULE
};
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(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;
};
}