创建一个3D模型程序,到这里基本已经算是完成,接下来只需要再做一点收尾工作,一个简单的3D程序就算完成。
下面是针对相机控制,光线的添加这两部分代码的补充。
编辑main.cpp,在其中添加如下代码
#include <QInputAspect> #include <QPointLight> #include <QFirstPersonCameraController> main() { Qt3DInput::QInputAspect *input = new Qt3DInput::QInputAspect; view->registerAspect(input); //QInputAspect负责创建物理设备并处理相关的作业,处理前端和后端节点之间的映射,负责根据当前输入设置建立要在特定时间运行的作业的对象。 Qt3DCore::QEntity *lightEntity = new Qt3DCore::QEntity(rootEntity); Qt3DRender::QPointLight *light = new Qt3DRender::QPointLight(lightEntity); light->setColor("white"); light->setIntensity(1); lightEntity->addComponent(light); Qt3DCore::QTransform *lightTransform = new Qt3DCore::QTransform(lightEntity); lightTransform->setTranslation(cameraEntity->position()); lightEntity->addComponent(lightTransform); //设置光源 Qt3DExtras::QFirstPersonCameraController *camController = new Qt3DExtras::QFirstPersonCameraController(rootEntity); camController->setCamera(cameraEntity); //相机第一人称视角控制 }
之后就可以拖动鼠标从不同的角度观测3D模型。
原文链接: https://www.cnblogs.com/leocc325/p/12983692.html
欢迎关注
微信关注下方公众号,第一时间获取干货硬货;公众号内回复【pdf】免费获取数百本计算机经典书籍;
也有高质量的技术群,里面有嵌入式、搜广推等BAT大佬
原创文章受到原创版权保护。转载请注明出处:https://www.ccppcoding.com/archives/351309
非原创文章文中已经注明原地址,如有侵权,联系删除
关注公众号【高性能架构探索】,第一时间获取最新文章
转载文章受原作者版权保护。转载请注明原作者出处!