场景编辑器Atmospheric Directional Light UI

前言

项目工具需要做个一个可视化调整角度的UI。

这里想参考一下:Atmospheric Directional Lights的UI。

于是,查阅了一下源码,在这做一下记录。

一、相关源码

首先,在编辑器操作中,发现当DirectionalLight勾选了以下开关才可以改变上述UI的方向。

  • Atmosphere Sun Light

根据bUsedAsAtmosphereSunLight去查找如何被调用:

在在LevelEditorViewport.cpp文件中,可以追溯到函数:

static UDirectionalLightComponent* GetAtmosphericLight(const uint8  DesiredLightIndex, UWorld* ViewportWorld)

再继续追踪这个函数的使用,有以下几个地方:

InputKey函数中,发现这个是判断是否开启UI。

MouseMove中可以看到计算如下:可以大概猜测出,下面计算的是UI的方向。

接着可以看到UI的绘制部分:通过搜索UserIsControllingAtmosphericLightTimer

  • FLevelEditorViewportClient::Draw中具体代码如下:
// void FLevelEditorViewportClient::Draw(const FSceneView*  View,FPrimitiveDrawInterface* PDI)
if (UserIsControllingAtmosphericLightTimer > 0.0f)
{// Draw a gizmo helping to figure out where is the light when moving it using a shortcut.FQuat ViewRotation = FQuat(GetViewRotation());FVector ViewPosition = GetViewLocation();const float GizmoDistance = 50.0f;const float GizmoSideOffset = 15.0f;const float GizmoRadius = 10.0f;const float ThicknessLight = 0.05f;const float ThicknessBold = 0.2f;// Always draw the gizmo right in in front of the camera with a little side shift.const FVector X(1.0f, 0.0f, 0.0f);const FVector Y(0.0f, 1.0f, 0.0f);const FVector Z(0.0f, 0.0f, 1.0f);const FVector Base = ViewPosition + GizmoDistance * ViewRotation.GetForwardVector() + GizmoSideOffset * (-ViewRotation.GetUpVector() + ViewRotation.GetRightVector());// Draw world main axisFRotator IdentityX(0.0f, 0.0f, 0.0f);FRotator IdentityY(0.0f, 90.0f, 0.0f);FRotator IdentityZ(90.0f, 0.0f, 0.0f);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityX), Base), FColor(255, 0, 0, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityY), Base), FColor(0, 255, 0, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);DrawDirectionalArrow(PDI, FQuatRotationTranslationMatrix(FQuat(IdentityZ), Base), FColor(0, 0, 255, 127), GizmoRadius, 0.3f, SDPG_World, ThicknessBold);// Render polar coordinate circlesDrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 1.0f), GizmoRadius, 32, SDPG_World, ThicknessBold);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.75f), GizmoRadius*0.75f, 32, SDPG_World, ThicknessLight);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.50f), GizmoRadius*0.50f, 32, SDPG_World, ThicknessLight);DrawCircle(PDI, Base, X, Y, FLinearColor(0.2f, 0.2f, 0.25f), GizmoRadius*0.25f, 32, SDPG_World, ThicknessLight);DrawArc(PDI, Base, Z, Y, -90.0f, 90.0f, GizmoRadius, 32, FLinearColor(1.0f, 0.2f, 0.2f), SDPG_World);DrawArc(PDI, Base, Z, X, -90.0f, 90.0f, GizmoRadius, 32, FLinearColor(0.2f, 1.0f, 0.2f), SDPG_World);// Draw the light incoming light direction. The arrow is offset outward to help depth perception when it intersects with other gizmo elements.const FLinearColor ArrowColor = -UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector() * 0.5f + 0.5f;const FVector ArrowOrigin = Base - UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector()*GizmoRadius*1.25;const FQuatRotationTranslationMatrix ArrowToWorld(UserControlledAtmosphericLightMatrix.GetRotation(), ArrowOrigin);DrawDirectionalArrow(PDI, ArrowToWorld, ArrowColor, GizmoRadius, 0.3f, SDPG_World, ThicknessBold);// Now draw x, y and z axis to help getting a sense of depth when look at the vectors on screen.FVector LightArrowTip = -UserControlledAtmosphericLightMatrix.GetRotation().GetForwardVector()*GizmoRadius;FVector P0 = Base + LightArrowTip * FVector(1.0f, 0.0f, 0.0f);FVector P1 = Base + LightArrowTip * FVector(1.0f, 1.0f, 0.0f);FVector P2 = Base + LightArrowTip * FVector(1.0f, 1.0f, 1.0f);PDI->DrawLine(Base, P0, FLinearColor(1.0f, 0.0f, 0.0f), SDPG_World, ThicknessLight);PDI->DrawLine(P0, P1, FLinearColor(0.0f, 1.0f, 0.0f), SDPG_World, ThicknessLight);PDI->DrawLine(P1, P2, FLinearColor(0.0f, 0.0f, 1.0f), SDPG_World, ThicknessLight);
}

小结

  • LevelEditorViewport::InputKey,通过热键判断是否开启UI显示。
  • LevelEditorViewport::MouseMove,计算鼠标移动,来求得Transform矩阵用于渲染。
  • LevelEditorViewport::Draw,渲染调整角度的UI。

通过以上的代码分析,很快可以在场景编辑器中模仿实现一个简单的角度控制的UI。

参考文献

  • UE四元数

场景编辑器Atmospheric Directional Light UI相关推荐

  1. 如何使用CocoStudio场景编辑器制作魔卡幻想

    1 CocoStudio 场景编辑器 使用 CocoStudio 场景编辑器来创建游戏场景,其中包含游戏 UI 与动画,来定制一个游戏主界面. 2 使用 CocoStudio 完成<魔卡幻想&g ...

  2. 【cocos2d-x】如何使用CocoStudio场景编辑器制作魔卡幻想

    1 CocoStudio 场景编辑器 使用 CocoStudio 场景编辑器来创建游戏场景,其中包含游戏 UI 与动画,来定制一个游戏主界面. 2 使用 CocoStudio 完成<魔卡幻想&g ...

  3. Directional Light Map(Directional Irradiance)

    Light Map是一个比较经典的技术,目前来说应该是一般游戏引擎中的标配,它很好的在一种拟全局光效果的质量和效率上做了中和.不过目前用的更多.质量更好的应该是Directional Light Ma ...

  4. 16 CoCos Creator-Scene 场景编辑器

    1. 原文 https://docs.cocos.com/creator/manual/zh/getting-started/basics/editor-panels/scene.html 2. Sc ...

  5. threejs模型可视化编辑器_一个近乎无门槛、零基础的3D场景编辑器

    在这个大数据井喷.互联网爆炸的时代,如何抓住机遇.如何逆流而上或是站在浪潮顶峰?在BAT崛起之初,貌似很少有人选择走BAT当时的道路,那时的他们,选择的是逆流而上,当所有人都在搞实体经营,阿里选择了做 ...

  6. windows脚本编制引擎_从零开始的场景编辑器(二):脚本系统

    为什么需要一个脚本系统 一般来说,一个工程只需要一种编程语言就足够了.事实也确实如此,强大如C++,图形渲染(DX,OpenGL),数据库(levelDB,RocksDB),深度学习(Caffe,Te ...

  7. 征服的荣耀服务器维护,《征服的荣耀》:游戏提供了场景编辑器,但内容的充实仍需等待...

    中世纪题材的俯视角<这是我的战争>,玩家需在漫长的围城煎熬中艰难求生,同时在紧张的昼夜切换间搜集资源并规划建设方案.游戏在维持团队生存基础的考验之外引入了支援堡垒的守城设计,使得资源规划更 ...

  8. Silverlight游戏设计(Game Design):(二)场景编辑器让游戏开发更美好

    如果哪天光荣告诉我:<三国志>系列将终结,我会义无返顾的用余下那点青春继续诠释这部中国历史经典题材游戏,已无法细数它占据了我多少童年的回忆,就好比曾有那么一群满腔热血的<梦幻模拟战& ...

  9. Silverlight游戏设计(Game Design):(七)创建基于场景编辑器的新游戏Demo

    场景编辑器的功能强大且灵活,从设计之初我已毫不惭愧的将其定位到"让Silverlight游戏场景架设更简单.更快捷"这样一个高度.源码公布后,很多朋友均迫切想知道如何将其运用到实际 ...

最新文章

  1. 免费教材丨第56期:《深度学习导论及案例分析》、《谷歌黑板报-数学之美》
  2. 操作系统课设--具有二级索引的文件系统
  3. Android 实现九宫格、点击图片放大全屏浏览等
  4. Nuxt(一) Nuxt初步认识
  5. 小程序真机测试「启动参数」解析出错问题
  6. C语言:几种字符输入函数的区别
  7. 力改变物体形状举例_人教版八年级物理下册第七章《力》知识点大全
  8. 看看这帮猴子的伪原创工具
  9. 状态机与马尔科夫模型
  10. iOS传感器开发——为APP添加手机密码、指纹进行安全验证
  11. 6-vue-component
  12. python培训学费多少钱-福州Python培训大概多少钱?
  13. Camrea测试-- CTS测试
  14. java跳转到ie_ie跳转chrome(ie浏览器点击链接跳转谷歌浏览器)
  15. P1600 天天爱跑步 解题报告
  16. 关键词SEO优化技巧
  17. 右键快捷菜单压缩文件的消失问题解决办法!
  18. st8s003 c语言编译器,什么原因导致ST单片机STM8S003F3P6这个8位机缺货
  19. kettle的调度监控平台
  20. (二)ArcGIS JS 加载动态地图服务

热门文章

  1. 荣耀8怎样修改wifi服务器,华为荣耀路由设置教程【图解】
  2. 模拟一个盒子的拖动效果
  3. 清明,追思我身边故去的人
  4. js数组怎么删除指定元素?
  5. TCP、RPC与HTTP到底是何方神圣?!
  6. 转载:爸妈,如果我嫁不出去了...
  7. PS学习笔记------PS如何进行填充???
  8. oracle里面substr,Oracle substr函数用法
  9. Servlet的优缺点
  10. linux rpm安装补丁,linux下对rpm源码手工打补丁