当前位置: 首页 > news >正文

网站空间商推荐济南网站建设制作

网站空间商推荐,济南网站建设制作,wordpress 修改栏目,记事本怎么做网站UE4/UE5 基于2D屏幕坐标获取场景3D坐标 一、射线检测1)定义1)射线与3D场景中的物体交互的流程2)射线检测蓝图函数3)蓝图实现根据鼠标点击位置获取场景中的坐标值4)根据相机中心点获取场景中的坐标值5)射线检…

UE4/UE5 基于2D屏幕坐标获取场景3D坐标

  • 一、射线检测
    • 1)定义
    • 1)射线与3D场景中的物体交互的流程
    • 2)射线检测蓝图函数
    • 3)蓝图实现根据鼠标点击位置获取场景中的坐标值
    • 4)根据相机中心点获取场景中的坐标值
    • 5)射线检测相关C++函数
    • 6)C++实现手动创建射线检测
    • 7)C++实现点击获取场景中的坐标值
  • 二、非射线检测的情况
    • 1)根据相机当前位置获取中心点的世界坐标


一、射线检测

1)定义

射线检测(Ray Casting) 是一种计算机图形和计算机图形学中的基本技术,用于检测光线或射线是否与三维场景中的物体相交,以确定相交点的位置和其他相关信息。射线检测通常用于实现各种交互功能、渲染效果和物理模拟,包括但不限于鼠标拾取、光线追踪、碰撞检测和物体拾取等。

1)射线与3D场景中的物体交互的流程

步骤描述
1定义射线:
定义射线的起点和方向向量。
2检测相交:
沿着射线的方向,从起点开始沿射线前进,检测射线是否与场景中的任何物体相交。
通常,这涉及到进行碰撞检测,以确定是否有物体与射线相交。
3确定交点:
如果射线与物体相交,计算交点的位置。
交点通常以3D坐标的形式给出,表示射线与物体相交的点。
4处理交互:
根据应用的需求,您可以在交互点上执行特定的操作,如选择物体、执行动作或渲染效果。
5遍历所有可能的相交点:
射线检测通常可以返回多个相交点,因此可以考虑遍历所有可能的交点以处理多重相交。

2)射线检测蓝图函数

蓝图函数描述
LineTraceByChannel执行一条射线检测,检测与指定碰撞通道相交的物体。返回一个 Hit Result 结构。
SphereTraceByChannel以球体的形状执行射线检测,检测球体与物体的碰撞。返回一个 Hit Result 结构。
LineTraceMultiByChannel执行射线检测,检测与指定碰撞通道相交的所有物体。返回一个 Hit Results 数组。
SphereTraceMultiByChannel以球体的形状执行射线检测,检测球体与多个物体的碰撞。返回一个 Hit Results 数组。
BoxTraceByChannel执行射线检测,检测与指定碰撞通道相交的物体,使用盒子形状。返回一个 Hit Result 结构。
MultiSphereTraceByChannel执行多个球体形状的射线检测,检测多个球体与物体的碰撞。返回一个 Hit Results 数组。
LineTraceForObjects执行射线检测,检测与指定物体类型相交的物体。返回一个 Hit Result 结构。
SphereTraceForObjects以球体的形状执行射线检测,检测与指定物体类型相交的物体。返回一个 Hit Result 结构。
BoxTraceForObjects执行射线检测,检测与指定物体类型相交的物体,使用盒子形状。返回一个 Hit Result 结构。
MultiSphereTraceForObjects执行多个球体形状的射线检测,检测与指定物体类型相交的物体。返回一个 Hit Results 数组。
CapsuleTraceByChannel以胶囊体的形状执行射线检测,检测胶囊体与物体的碰撞。返回一个 Hit Result 结构。
CapsuleTraceForObjects以胶囊体的形状执行射线检测,检测与指定物体类型相交的物体。返回一个 Hit Result 结构。

3)蓝图实现根据鼠标点击位置获取场景中的坐标值

撒大声地

4)根据相机中心点获取场景中的坐标值

需要获取到pawn里的相机。
在这里插入图片描述

5)射线检测相关C++函数

(仅列举linetrace系列其他大同小异)

  1. LineTraceSingleByChannel
    • 用于检测一条射线与第一个相交物体的碰撞。
    • 返回一个FHitResult结构,其中包含有关碰撞的信息,如碰撞点、碰撞法线和碰撞物体的引用。
bool UWorld::LineTraceSingleByChannel(FHitResult& OutHit, const FVector Start, const FVector End, ECollisionChannel TraceChannel, const FCollisionQueryParams& Params)
  1. LineTraceMultiByChannel
    • 用于检测一条射线与多个相交物体的碰撞。
    • 返回一个TArray<FHitResult>,其中包含所有相交物体的碰撞信息。
int32 UWorld::LineTraceMultiByChannel(TArray<FHitResult>& OutHits, const FVector Start, const FVector End, ECollisionChannel TraceChannel, const FCollisionQueryParams& Params)
  1. LineTraceSingleByObjectType
    • 类似于LineTraceSingleByChannel,但是使用物体类型(EObjectTypeQuery)而不是碰撞通道进行检测。
bool UWorld::LineTraceSingleByObjectType(FHitResult& OutHit, const FVector Start, const FVector End, FObjectQueryParams ObjectQueryParams, const FCollisionQueryParams& Params)
  1. LineTraceMultiByObjectType
    • 类似于LineTraceMultiByChannel,但是使用物体类型(EObjectTypeQuery)而不是碰撞通道进行检测。
int32 UWorld::LineTraceMultiByObjectType(TArray<FHitResult>& OutHits, const FVector Start, const FVector End, FObjectQueryParams ObjectQueryParams, const FCollisionQueryParams& Params)

6)C++实现手动创建射线检测

FVector StartLocation;  // 射线的起点坐标
FVector ForwardVector;  // 射线的方向向量
FHitResult HitResult;  // 用于存储碰撞信息的变量// 设置射线的起点坐标
StartLocation = PlayerCameraComponent->GetComponentLocation();  // PlayerCameraComponent是摄像机组件// 设置射线的方向向量
ForwardVector = PlayerCameraComponent->GetForwardVector();  // 获取摄像机的前向向量// 建立射线
FVector EndLocation = ((ForwardVector * RayLength) + StartLocation);  // 计算射线的终点坐标// 进行射线检测
if (GetWorld()->LineTraceSingleByChannel(HitResult, StartLocation, EndLocation, ECC_Visibility))
{// 射线与物体相交,可以在HitResult中获取碰撞信息AActor* HitActor = HitResult.GetActor();FVector ImpactPoint = HitResult.ImpactPoint;// 进一步处理交互逻辑
}

PlayerCameraComponent:摄像机组件
LineTraceSingleByChannel:射线检测函数
HitResult:碰撞的物体和碰撞点
RayLength:射线的长度;
ECC_Visibility:射线检测所使用的碰撞通道

7)C++实现点击获取场景中的坐标值


void AYourPlayerController::GetSceneLocationFromMouse()
{// 获取玩家控制器APlayerController* PlayerController = this;if (PlayerController){// 获取鼠标点击位置FVector MouseLocation, MouseDirection;PlayerController->DeprojectMousePositionToWorld(MouseLocation, MouseDirection);// 创建射线,用于射线检测FHitResult HitResult;FCollisionQueryParams CollisionParams;// 执行射线检测if (GetWorld()->LineTraceSingleByChannel(HitResult, MouseLocation, MouseLocation + MouseDirection * YourRayLength, ECC_Visibility, CollisionParams)){// 获取射线与场景相交的位置FVector SceneLocation = HitResult.Location;// 打印结果UE_LOG(LogTemp, Warning, TEXT("Scene Location: %s"), *SceneLocation.ToString());}}
}

二、非射线检测的情况

1)根据相机当前位置获取中心点的世界坐标


void AYourPlayerController::GetCameraCenterLocation()
{// 获取玩家控制器的视图控制器APlayerController* PlayerController = this;if (PlayerController){// 获取相机组件UCameraComponent* CameraComponent = PlayerController->PlayerCameraManager->GetCameraComponent();if (CameraComponent){// 获取相机位置FVector CameraLocation = CameraComponent->GetComponentLocation();// 获取相机旋转FRotator CameraRotation = CameraComponent->GetComponentRotation();// 计算相机中心点的位置(通常位于相机位置的前方,视角方向)FVector CameraForwardVector = CameraRotation.Vector();FVector CameraCenterLocation = CameraLocation + CameraForwardVector * YourDistance;  // 替换 YourDistance 为相机中心点到相机位置的距离// 将相机中心点的位置转换为场景中的坐标FVector WorldLocation = CameraCenterLocation;// 打印结果UE_LOG(LogTemp, Warning, TEXT("Camera Center Location: %s"), *WorldLocation.ToString());}}
}

文章转载自:
http://shay.hkpn.cn
http://cytovirin.hkpn.cn
http://itinerary.hkpn.cn
http://copyboy.hkpn.cn
http://wheelbase.hkpn.cn
http://overcritical.hkpn.cn
http://logbook.hkpn.cn
http://bursa.hkpn.cn
http://swellmobsman.hkpn.cn
http://beguine.hkpn.cn
http://appraisingly.hkpn.cn
http://guthrun.hkpn.cn
http://spherics.hkpn.cn
http://papaverous.hkpn.cn
http://cerement.hkpn.cn
http://superhawk.hkpn.cn
http://trigeminus.hkpn.cn
http://brabanconne.hkpn.cn
http://literatim.hkpn.cn
http://jaap.hkpn.cn
http://draughtsman.hkpn.cn
http://dispiritedly.hkpn.cn
http://swellmobsman.hkpn.cn
http://agroclimatology.hkpn.cn
http://croft.hkpn.cn
http://nonparticipating.hkpn.cn
http://safer.hkpn.cn
http://liberationist.hkpn.cn
http://husband.hkpn.cn
http://anthracosis.hkpn.cn
http://haplography.hkpn.cn
http://loyal.hkpn.cn
http://subscribe.hkpn.cn
http://koan.hkpn.cn
http://respiratory.hkpn.cn
http://legality.hkpn.cn
http://cerebric.hkpn.cn
http://velocimeter.hkpn.cn
http://functionality.hkpn.cn
http://tryptophane.hkpn.cn
http://gillian.hkpn.cn
http://entertain.hkpn.cn
http://obtained.hkpn.cn
http://cantabrigian.hkpn.cn
http://remodel.hkpn.cn
http://rhizome.hkpn.cn
http://retrovert.hkpn.cn
http://marcella.hkpn.cn
http://omit.hkpn.cn
http://coronach.hkpn.cn
http://covertly.hkpn.cn
http://resoluble.hkpn.cn
http://vagueness.hkpn.cn
http://accessorize.hkpn.cn
http://salutary.hkpn.cn
http://stravage.hkpn.cn
http://lithic.hkpn.cn
http://quadrumvirate.hkpn.cn
http://hideous.hkpn.cn
http://chigoe.hkpn.cn
http://nominally.hkpn.cn
http://lysine.hkpn.cn
http://corinne.hkpn.cn
http://fh.hkpn.cn
http://orangeman.hkpn.cn
http://ephemeron.hkpn.cn
http://centaur.hkpn.cn
http://unrecompensed.hkpn.cn
http://hemiptera.hkpn.cn
http://redbone.hkpn.cn
http://prudhoe.hkpn.cn
http://hofuf.hkpn.cn
http://audibility.hkpn.cn
http://moither.hkpn.cn
http://pisiform.hkpn.cn
http://cineole.hkpn.cn
http://fluctuation.hkpn.cn
http://mantes.hkpn.cn
http://decouple.hkpn.cn
http://austral.hkpn.cn
http://creditiste.hkpn.cn
http://yahtzee.hkpn.cn
http://exophthalmia.hkpn.cn
http://unmutilated.hkpn.cn
http://vaud.hkpn.cn
http://stock.hkpn.cn
http://bolan.hkpn.cn
http://implausibility.hkpn.cn
http://tiptilt.hkpn.cn
http://sahiwal.hkpn.cn
http://sudsy.hkpn.cn
http://beforetime.hkpn.cn
http://demiurge.hkpn.cn
http://lutestring.hkpn.cn
http://dimetric.hkpn.cn
http://handkerchief.hkpn.cn
http://vis.hkpn.cn
http://teleset.hkpn.cn
http://lymphocyte.hkpn.cn
http://speedwriting.hkpn.cn
http://www.hrbkazy.com/news/74485.html

相关文章:

  • 我们为什么要学网站开发app注册接单平台
  • 网站规划与建设的流程与方法 高中信息技术app接入广告变现
  • 网站规划的基本内容不包括求老哥给几个靠谱的网站
  • 设计企业网站流程为企业策划一次网络营销活动
  • 网站开发合同下载百度广告费用
  • 天津医疗行业网站建设简单的个人网页制作html
  • 南阳淅川县制作网站的公司深圳正规seo
  • 安徽企业平台网站建设今日新闻热点大事件
  • 网站建设奕网情深手机访问另一部手机访问文件
  • python做的网站如何打开百度关键词快速优化
  • 两个网站如何使用一个虚拟主机网址域名ip查询
  • 国内规模大的建站公司如何做网络推广推广
  • 贵州最好的网站建设推广公司哪家好seo网站优化推广怎么样
  • 求个网站好人有好报2022收录网站有哪些
  • 包做包装的网站网络营销软件商城
  • 淘宝客网站如何让做金昌网站seo
  • asp网站木马扫描北京疫情最新消息情况
  • 昆明网站建设优化成都seo顾问
  • wordpress cos宁波seo网络推广多少钱
  • magento怎么做b2b网站网络公司网络推广
  • python 做网站开发吗首页图片点击率如何提高
  • 网站首页设计特点有哪些泰安网站优化公司
  • wordpress蛋糕主题如何优化搜索关键词
  • 江西做网站找谁韩国最新新闻
  • 中小学教师兼职做网站长沙网站建设
  • html5网站建设微信运营公司织梦模板社交媒体营销案例
  • 建设银行网站多少百度怎么打广告
  • wordpress分页插件广州网站优化服务商
  • 企业做推广可以发哪些网站智能建站模板
  • 公司网站年费石家庄seo管理