Ara you OK?
我看你是思想出现了偏差
哇!你认出了错别单词!恭喜你获得一次向我支付宝充值助我重返欧洲的机会!
这个页面管关不掉了,你自己看着办吧

UE4 - C++ 射线捕捉

#include "Runtime/Engine/Classes/Kismet/KismetMathLibrary.h"

//省略大部分代码
void AMyFPS_Character::OnMoveingOrRot()
{
    GetActorLocation();
    //LineTraceSingle_NEW();
    if (GEngine != nullptr)
    {
        FHitResult hit;
        auto temp_startPos = GetActorLocation();
        auto temp_rota = GetActorRotation();

        auto temp_endPos = FRotationMatrix(temp_rota).GetScaledAxis(EAxis::X) * 500.0f; // + 
        //hit.
        m_bodyInstance.LineTrace(hit, temp_startPos, temp_endPos, false, false);
        if (hit.Actor != nullptr && hit.Actor != this)
        {
            m_operaTarget = hit.Actor;
        }
    }
}

//Exa 2
//In player controller class
 
//location the PC is focused on
const FVector Start = GetFocalLocation(); 
 
//256 units in facing direction of PC (256 units in front of the camera)
const FVector End = Start + GetControlRotation().Vector() * 256; 
 
//The trace data is stored here
FHitResult HitData(ForceInit);
 
//If Trace Hits anything
if(  UMyStaticFunctionLibrary::Trace(GetWorld(),GetPawn(),Start,End,HitData)  )
{
	//Print out the name of the traced actor
	if(HitData.GetActor())
	{
		ClientMessage(HitData.GetActor()->GetName());
 
	        //Print out distance from start of trace to impact point
	        ClientMessage("Trace Distance: " + FString::SanitizeFloat(HitData.Distance));
	}
}
 

 

 

Q.高精度的射线捕获(使用UE::Geometry::*)对UE::Geometry::FDynamicMesh3进行射线捕获(Tri细度)

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

 

posted @ 2015-12-08 18:03  林清  阅读(1760)  评论(0)    收藏  举报