UE4笔记-Collision与Trace相关
碰撞和射线追踪相关笔记,备查
Q.ECollisionChannel/ETraceTypeQuery/EObjectTypeQuery相互转换:
UEngineTypes::ConvertToObjectType();
UEngineTypes::ConvertToCollisionChannel();
UEngineTypes::ConvertToTraceType();
Q.高精度的射线捕获(使用UE::Geometry::*)对UE::Geometry::FDynamicMesh3进行射线捕获
// UE::Geometry::FDynamicMesh3 SourceMesh; UE::Geometry::FDynamicMeshAABBTree3 MeshAABBTree; bool *::RayHit( FVector RayOrigin, FVector RayDirection, FVector& WorldHitPoint, float& HitDistance, int& NearestTriangle, FVector& TriBaryCoords, float MaxDistance) { FTransform3d ActorToWorld(GetActorTransform()); FVector3d WorldDirection(RayDirection); WorldDirection.Normalize(); FRay3d LocalRay( ActorToWorld.InverseTransformPosition(static_cast<FVector3d>(RayOrigin)), ActorToWorld.InverseTransformVector(WorldDirection)); UE::Geometry::IMeshSpatial::FQueryOptions QueryOptions; if (MaxDistance > 0) { QueryOptions.MaxDistance = MaxDistance; } NearestTriangle = MeshAABBTree.FindNearestHitTriangle(LocalRay, QueryOptions); if (SourceMesh.IsTriangle(NearestTriangle)) { UE::Geometry::FIntrRay3Triangle3d InterQuery = UE::Geometry::TMeshQueries<FDynamicMesh3>::TriangleIntersection( SourceMesh, NearestTriangle, LocalRay); if (InterQuery.IntersectionType == EIntersectionType::Point) { HitDistance = InterQuery.RayParameter; WorldHitPoint = static_cast<FVector>(ActorToWorld.TransformPosition( LocalRay.PointAt(InterQuery.RayParameter))); TriBaryCoords = static_cast<FVector>(InterQuery.TriangleBaryCoords); return true; } } return false;
本文原创,不定时更新
可以随意转载到任何网站
~但是~ 转载也要按“基本法”
请注明原文出处和作者