Fixed collision listener bug & incorrect transform forward. Added collision tags to raycasts. #274
|
@ -63,7 +63,7 @@ namespace SHADE
|
|||
raycasts.clear();
|
||||
}
|
||||
|
||||
SHPhysicsRaycastResult SHPhysicsRaycaster::Raycast(const SHRay& ray, float distance) noexcept
|
||||
SHPhysicsRaycastResult SHPhysicsRaycaster::Raycast(const SHRay& ray, float distance, const SHCollisionTag& collisionTag) noexcept
|
||||
{
|
||||
// Reset temp
|
||||
temp = SHPhysicsRaycastResult{};
|
||||
|
@ -78,13 +78,13 @@ namespace SHADE
|
|||
// If distance in infinity, cast to the default max distance of 2 km.
|
||||
if (distance == std::numeric_limits<float>::infinity())
|
||||
{
|
||||
world->raycast(ray, this);
|
||||
world->raycast(ray, this, collisionTag);
|
||||
}
|
||||
else
|
||||
{
|
||||
const SHVec3 END_POINT = ray.position + ray.direction * distance;
|
||||
const rp3d::Ray RP3D_RAY{ ray.position, END_POINT };
|
||||
world->raycast(RP3D_RAY, this);
|
||||
world->raycast(RP3D_RAY, this, collisionTag);
|
||||
}
|
||||
|
||||
// If a hit was found, populate temp info for return.
|
||||
|
@ -98,7 +98,7 @@ namespace SHADE
|
|||
return temp;
|
||||
}
|
||||
|
||||
SHPhysicsRaycastResult SHPhysicsRaycaster::Linecast(const SHVec3& start, const SHVec3& end) noexcept
|
||||
SHPhysicsRaycastResult SHPhysicsRaycaster::Linecast(const SHVec3& start, const SHVec3& end, const SHCollisionTag& collisionTag) noexcept
|
||||
{
|
||||
temp = SHPhysicsRaycastResult{};
|
||||
temp.distance = SHVec3::Distance(start, end);
|
||||
|
@ -110,7 +110,7 @@ namespace SHADE
|
|||
}
|
||||
|
||||
const rp3d::Ray RP3D_RAY{ start, end };
|
||||
world->raycast(RP3D_RAY, this);
|
||||
world->raycast(RP3D_RAY, this, collisionTag);
|
||||
|
||||
if (temp.hit)
|
||||
{
|
||||
|
|
|
@ -19,6 +19,7 @@
|
|||
#include "Physics/PhysicsObject/SHPhysicsObjectManager.h"
|
||||
#include "Physics/SHPhysicsWorld.h"
|
||||
#include "SH_API.h"
|
||||
#include "SHCollisionTags.h"
|
||||
#include "SHPhysicsRaycastResult.h"
|
||||
|
||||
namespace SHADE
|
||||
|
@ -69,12 +70,14 @@ namespace SHADE
|
|||
(
|
||||
const SHRay& ray
|
||||
, float distance = std::numeric_limits<float>::infinity()
|
||||
, const SHCollisionTag& collisionTag = SHCollisionTag{}
|
||||
) noexcept;
|
||||
|
||||
SHPhysicsRaycastResult Linecast
|
||||
(
|
||||
const SHVec3& start
|
||||
, const SHVec3& end
|
||||
, const SHCollisionTag& collisionTag = SHCollisionTag{}
|
||||
) noexcept;
|
||||
|
||||
SHPhysicsRaycastResult ColliderRaycast
|
||||
|
|
|
@ -258,14 +258,14 @@ namespace SHADE
|
|||
}
|
||||
}
|
||||
|
||||
SHPhysicsRaycastResult SHPhysicsSystem::Raycast(const SHRay& ray, float distance) noexcept
|
||||
SHPhysicsRaycastResult SHPhysicsSystem::Raycast(const SHRay& ray, float distance, const SHCollisionTag& collisionTag) noexcept
|
||||
{
|
||||
return raycaster.Raycast(ray, distance);
|
||||
return raycaster.Raycast(ray, distance, collisionTag);
|
||||
}
|
||||
|
||||
SHPhysicsRaycastResult SHPhysicsSystem::Linecast(const SHVec3& start, const SHVec3& end) noexcept
|
||||
SHPhysicsRaycastResult SHPhysicsSystem::Linecast(const SHVec3& start, const SHVec3& end, const SHCollisionTag& collisionTag) noexcept
|
||||
{
|
||||
return raycaster.Linecast(start, end);
|
||||
return raycaster.Linecast(start, end, collisionTag);
|
||||
}
|
||||
|
||||
SHPhysicsRaycastResult SHPhysicsSystem::ColliderRaycast(EntityID eid, const SHRay& ray, float distance) noexcept
|
||||
|
|
|
@ -85,24 +85,28 @@ namespace SHADE
|
|||
* @brief Casts a ray into the world.
|
||||
* @param ray The ray to cast.
|
||||
* @param distance The distance to cast the ray. Defaults to infinity.
|
||||
* @param collisionTag The collision tag to use for filtering the raycast.
|
||||
* @return The result of the raycast.
|
||||
*/
|
||||
SHPhysicsRaycastResult Raycast
|
||||
(
|
||||
const SHRay& ray
|
||||
, float distance = std::numeric_limits<float>::infinity()
|
||||
, const SHCollisionTag& collisionTag = SHCollisionTag{}
|
||||
) noexcept;
|
||||
|
||||
/**
|
||||
* @brief Casts a bounded ray into the world.
|
||||
* @param start The starting point of the ray.
|
||||
* @param end The end point of the ray.
|
||||
* @param collisionTag The collision tag to use for filtering the bounded raycast.
|
||||
* @return The result of the raycast.
|
||||
*/
|
||||
SHPhysicsRaycastResult Linecast
|
||||
(
|
||||
const SHVec3& start
|
||||
, const SHVec3& end
|
||||
, const SHCollisionTag& collisionTag = SHCollisionTag{}
|
||||
) noexcept;
|
||||
|
||||
/**
|
||||
|
|
|
@ -20,6 +20,7 @@
|
|||
#include "Scripting/SHScriptEngine.h"
|
||||
|
||||
#include "Input/SHInputManager.h"
|
||||
#include "Physics/Collision/SHCollisionTagMatrix.h"
|
||||
|
||||
/*-------------------------------------------------------------------------------------*/
|
||||
/* Local Functions */
|
||||
|
@ -403,4 +404,13 @@ void testFunction()
|
|||
rb->AddForce(SHVec3::UnitX * forceModifier);
|
||||
}
|
||||
}
|
||||
|
||||
// Cast rays
|
||||
auto* tag = SHCollisionTagMatrix::GetTag(1);
|
||||
tag->SetLayerState(SHCollisionTag::Layer::_1, false);
|
||||
tag->SetLayerState(SHCollisionTag::Layer::_2, true);
|
||||
|
||||
SHRay ray { SHVec3{3.0f, 3.5f, 0.0f}, -SHVec3::UnitX };
|
||||
auto* physicsSystem = SHSystemManager::GetSystem<SHPhysicsSystem>();
|
||||
physicsSystem->Raycast(ray, std::numeric_limits<float>::infinity(), *tag);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue