Fixed raycast sphere.

This commit is contained in:
2023-03-18 22:58:26 -07:00
parent d97d19f93c
commit 765c9015ae
9 changed files with 249 additions and 189 deletions

View File

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

View File

@ -17,7 +17,8 @@ namespace Dawn {
enum Collider3DType {
COLLIDER3D_TYPE_CUBE,
COLLIDER3D_TYPE_CAPSULE
COLLIDER3D_TYPE_CAPSULE,
COLLIDER3D_TYPE_SPHERE
};
class Collider3D : public SceneItemComponent {

View 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
);
}

View 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;
};
}