Fixed raycast sphere.
This commit is contained in:
@ -9,4 +9,5 @@ target_sources(${DAWN_TARGET_NAME}
|
||||
Collider3D.cpp
|
||||
CubeCollider.cpp
|
||||
CapsuleCollider.cpp
|
||||
SphereCollider.cpp
|
||||
)
|
@ -17,7 +17,8 @@ namespace Dawn {
|
||||
|
||||
enum Collider3DType {
|
||||
COLLIDER3D_TYPE_CUBE,
|
||||
COLLIDER3D_TYPE_CAPSULE
|
||||
COLLIDER3D_TYPE_CAPSULE,
|
||||
COLLIDER3D_TYPE_SPHERE
|
||||
};
|
||||
|
||||
class Collider3D : public SceneItemComponent {
|
||||
|
31
src/dawn/scene/components/physics/3d/SphereCollider.cpp
Normal file
31
src/dawn/scene/components/physics/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(SceneItem *item) : Collider3D(item) {
|
||||
|
||||
}
|
||||
|
||||
enum Collider3DType SphereCollider::getColliderType() {
|
||||
return COLLIDER3D_TYPE_SPHERE;
|
||||
}
|
||||
|
||||
bool_t SphereCollider::performRaycast(
|
||||
struct Collider3DRayResult *result,
|
||||
struct Ray3D ray
|
||||
) {
|
||||
assertNotNull(result);
|
||||
|
||||
return raytestSphere(
|
||||
ray,
|
||||
{ .center = transform->getLocalPosition(), .radius = this->radius },
|
||||
&result->point,
|
||||
&result->normal,
|
||||
&result->distance
|
||||
);
|
||||
}
|
24
src/dawn/scene/components/physics/3d/SphereCollider.hpp
Normal file
24
src/dawn/scene/components/physics/3d/SphereCollider.hpp
Normal file
@ -0,0 +1,24 @@
|
||||
// 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:
|
||||
float_t radius = 1.0f;
|
||||
|
||||
SphereCollider(SceneItem *item);
|
||||
|
||||
enum Collider3DType getColliderType() override;
|
||||
};
|
||||
}
|
Reference in New Issue
Block a user