sweep sphere

This commit is contained in:
Mikulas Florek 2023-10-01 17:49:07 +02:00
parent e4ee5e8573
commit 105f2325b6
3 changed files with 19 additions and 1 deletions

View File

@ -140,6 +140,7 @@ end
declare class physics_module
raycast : (physics_module, any --[[Vec3]], any --[[Vec3]], number, any --[[EntityPtr]]) -> any --[[struct Lumix::EntityPtr]]
sweepSphere : (physics_module, any --[[DVec3]], number, any --[[Vec3]], number, any --[[EntityPtr]], number) -> any --[[struct Lumix::EntityPtr]]
setGravity : (physics_module, any --[[Vec3]]) -> ()
end
@ -558,7 +559,7 @@ declare Editor: {
addAction : (ActionDesc) -> (),
createEntityEx : (any) -> Entity,
scene_view : SceneView,
asset_browser : AssetBrowser
asset_browser : AssetBrowser
}
declare LumixAPI: {

View File

@ -2392,6 +2392,21 @@ struct PhysicsModuleImpl final : PhysicsModule
PhysicsModuleImpl* module;
};
EntityPtr sweepSphere(const DVec3& pos, float radius, const Vec3& dir, float distance, EntityPtr ignored, i32 layer) override {
PxSweepBuffer hit;
physx::PxSphereGeometry sphere(radius);
physx::PxTransform transform(toPhysx(pos), physx::PxIdentity);
Filter filter;
filter.entity = ignored;
filter.layer = layer;
filter.module = this;
PxQueryFilterData filter_data;
filter_data.flags = PxQueryFlag::eDYNAMIC | PxQueryFlag::eSTATIC | PxQueryFlag::ePREFILTER;
if (!m_scene->sweep(sphere, transform, toPhysx(dir), distance, hit, physx::PxHitFlag::eDEFAULT, filter_data, &filter)) return INVALID_ENTITY;
if (!hit.hasBlock) return INVALID_ENTITY;
const EntityRef hit_entity = {(int)(intptr_t)hit.block.actor->userData};
return hit_entity;
}
bool raycastEx(const Vec3& origin,
const Vec3& dir,
@ -3949,6 +3964,7 @@ void PhysicsModule::reflect() {
LUMIX_MODULE(PhysicsModuleImpl, "physics")
.LUMIX_FUNC(raycast)
.LUMIX_FUNC(sweepSphere)
.LUMIX_FUNC(setGravity)
.LUMIX_CMP(D6Joint, "d6_joint", "Physics / Joint / D6")
.LUMIX_PROP(JointConnectedBody, "Connected body")

View File

@ -91,6 +91,7 @@ struct LUMIX_PHYSICS_API PhysicsModule : IModule
virtual void forceUpdateDynamicActors(float time_delta) = 0;
virtual const Array<EntityRef>& getDynamicActors() = 0;
virtual void render() = 0;
virtual EntityPtr sweepSphere(const DVec3& pos, float radius, const Vec3& dir, float distance, EntityPtr ignored, i32 layer) = 0;
virtual EntityPtr raycast(const Vec3& origin, const Vec3& dir, float distance, EntityPtr ignore_entity) = 0;
virtual bool raycastEx(const Vec3& origin, const Vec3& dir, float distance, RaycastHit& result, EntityPtr ignored, int layer) = 0;
virtual void setGravity(const Vec3& gravity) = 0;