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