Starting work on capsules.
This commit is contained in:
@ -8,4 +8,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
PRIVATE
|
||||
Collider3D.cpp
|
||||
CubeCollider.cpp
|
||||
CapsuleCollider.cpp
|
||||
)
|
35
src/dawn/scene/components/physics/3d/CapsuleCollider.cpp
Normal file
35
src/dawn/scene/components/physics/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(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;
|
||||
}
|
26
src/dawn/scene/components/physics/3d/CapsuleCollider.hpp
Normal file
26
src/dawn/scene/components/physics/3d/CapsuleCollider.hpp
Normal 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;
|
||||
};
|
||||
}
|
@ -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;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user