QT 和Ogre Demo

ogre的编译请参考链接https://blog.csdn.net/DdogYuan/article/details/79559667 或自行解决, 我用的vs2015 ,生成后将dll和头文件加入到QT的工程中即可(注意必须对应)

ogre自带的de'mo

参考链接:

http://wiki.ogre3d.org/Home

https://ogrecave.github.io/ogre/api/latest/tut__first_scene.html

该Demo使用的版本是ogre1.10.12 (32位) ,  Qt5.10.0 MSVC2015  32bit  Release  QT Creator 编译生成的

例程,完整ogre编译和使用步骤,

完整源码工程下载地址

https://download.csdn.net/download/gws09876/12136896

附qt ogreCamera操作类的代码,理解请看代码

#ifndef __SdkQtCameraMan_H__
#define __SdkQtCameraMan_H__#include "OgreCamera.h"
#include "OgreSceneNode.h"
#include "OgreFrameListener.h"#include <QKeyEvent>
#include <QMouseEvent>
#include <QDebug>// enum CameraStyle should be in other namespace than OgreBites::CameraStyle
namespace OgreQtBites
{enum CameraStyle   // enumerator values for different styles of camera movement{CS_FREELOOK,CS_ORBIT,CS_MANUAL};/*=============================================================================| Utility class for controlling the camera in samples.=============================================================================*/class SdkQtCameraMan{public:SdkQtCameraMan(Ogre::Camera* cam): mCamera(0), mTarget(0), mOrbiting(false), mZooming(false), mTopSpeed(150), mVelocity(Ogre::Vector3::ZERO), mGoingForward(false), mGoingBack(false), mGoingLeft(false), mGoingRight(false), mGoingUp(false), mGoingDown(false), mFastMove(false){setCamera(cam);setStyle(CS_FREELOOK);}virtual ~SdkQtCameraMan() {}/*-----------------------------------------------------------------------------| Swaps the camera on our camera man for another camera.-----------------------------------------------------------------------------*/virtual void setCamera(Ogre::Camera* cam){mCamera = cam;}virtual Ogre::Camera* getCamera(){return mCamera;}/*-----------------------------------------------------------------------------| Sets the target we will revolve around. Only applies for orbit style.-----------------------------------------------------------------------------*/virtual void setTarget(Ogre::SceneNode* target){if (target != mTarget){mTarget = target;if(target){setYawPitchDist(Ogre::Degree(0), Ogre::Degree(15), 150);mCamera->setAutoTracking(true, mTarget);}else{mCamera->setAutoTracking(false);}}}virtual Ogre::SceneNode* getTarget(){return mTarget;}/*-----------------------------------------------------------------------------| Sets the spatial offset from the target. Only applies for orbit style.-----------------------------------------------------------------------------*/virtual void setYawPitchDist(Ogre::Radian yaw, Ogre::Radian pitch, Ogre::Real dist){mCamera->setPosition(mTarget->_getDerivedPosition());mCamera->setOrientation(mTarget->_getDerivedOrientation());mCamera->yaw(yaw);mCamera->pitch(-pitch);mCamera->moveRelative(Ogre::Vector3(0, 0, dist));}/*-----------------------------------------------------------------------------| Sets the camera's top speed. Only applies for free-look style.-----------------------------------------------------------------------------*/virtual void setTopSpeed(Ogre::Real topSpeed){mTopSpeed = topSpeed;}virtual Ogre::Real getTopSpeed(){return mTopSpeed;}/*-----------------------------------------------------------------------------| Sets the movement style of our camera man.-----------------------------------------------------------------------------*/virtual void setStyle(CameraStyle style){if (mStyle != CS_ORBIT && style == CS_ORBIT){setTarget(mTarget ? mTarget : mCamera->getSceneManager()->getRootSceneNode());mCamera->setFixedYawAxis(true);manualStop();setYawPitchDist(Ogre::Degree(0), Ogre::Degree(15), 150);}else if (mStyle != CS_FREELOOK && style == CS_FREELOOK){mCamera->setAutoTracking(false);mCamera->setFixedYawAxis(true);}else if (mStyle != CS_MANUAL && style == CS_MANUAL){mCamera->setAutoTracking(false);manualStop();}mStyle = style;}virtual CameraStyle getStyle(){return mStyle;}/*-----------------------------------------------------------------------------| Manually stops the camera when in free-look mode.-----------------------------------------------------------------------------*/virtual void manualStop(){if (mStyle == CS_FREELOOK){mGoingForward = false;mGoingBack = false;mGoingLeft = false;mGoingRight = false;mGoingUp = false;mGoingDown = false;mVelocity = Ogre::Vector3::ZERO;}}virtual bool frameRenderingQueued(const Ogre::FrameEvent& evt){if (mStyle == CS_FREELOOK){// build our acceleration vector based on keyboard input compositeOgre::Vector3 accel = Ogre::Vector3::ZERO;if (mGoingForward) accel += mCamera->getDirection();if (mGoingBack) accel -= mCamera->getDirection();if (mGoingRight) accel += mCamera->getRight();if (mGoingLeft) accel -= mCamera->getRight();if (mGoingUp) accel += mCamera->getUp();if (mGoingDown) accel -= mCamera->getUp();// if accelerating, try to reach top speed in a certain timeOgre::Real topSpeed = mFastMove ? mTopSpeed * 20 : mTopSpeed;if (accel.squaredLength() != 0){accel.normalise();mVelocity += accel * topSpeed * evt.timeSinceLastFrame * 10;}// if not accelerating, try to stop in a certain timeelse mVelocity -= mVelocity * evt.timeSinceLastFrame * 10;Ogre::Real tooSmall = std::numeric_limits<Ogre::Real>::epsilon();// keep camera velocity below top speed and above epsilonif (mVelocity.squaredLength() > topSpeed * topSpeed){mVelocity.normalise();mVelocity *= topSpeed;}else if (mVelocity.squaredLength() < tooSmall * tooSmall)mVelocity = Ogre::Vector3::ZERO;if (mVelocity != Ogre::Vector3::ZERO) mCamera->move(mVelocity * evt.timeSinceLastFrame);}return true;}/*-----------------------------------------------------------------------------| Processes key presses for free-look style movement.-----------------------------------------------------------------------------*/virtual void injectKeyDown(const QKeyEvent& evt){if (mStyle == CS_FREELOOK){if (evt.key() == Qt::Key_W || evt.key() == Qt::Key_Up) mGoingForward = true;else if (evt.key() == Qt::Key_S || evt.key() == Qt::Key_Down) mGoingBack = true;else if (evt.key() == Qt::Key_A || evt.key() == Qt::Key_Left) mGoingLeft = true;else if (evt.key() == Qt::Key_D || evt.key() == Qt::Key_Right) mGoingRight = true;else if (evt.key() == Qt::Key_PageUp) mGoingUp = true;else if (evt.key() == Qt::Key_PageDown) mGoingDown = true;else if (evt.key() == Qt::Key_Shift) mFastMove = true;}}/*-----------------------------------------------------------------------------| Processes key releases for free-look style movement.-----------------------------------------------------------------------------*/virtual void injectKeyUp(const QKeyEvent& evt){if (mStyle == CS_FREELOOK){if (evt.key() == Qt::Key_W || evt.key() == Qt::Key_Up) mGoingForward = false;else if (evt.key() == Qt::Key_S || evt.key() == Qt::Key_Down) mGoingBack = false;else if (evt.key() == Qt::Key_A || evt.key() == Qt::Key_Left) mGoingLeft = false;else if (evt.key() == Qt::Key_D || evt.key() == Qt::Key_Right) mGoingRight = false;else if (evt.key() == Qt::Key_PageUp) mGoingUp = false;else if (evt.key() == Qt::Key_PageDown) mGoingDown = false;else if (evt.key() == Qt::Key_Shift) mFastMove = false;}}/*-----------------------------------------------------------------------------| Processes mouse movement differently for each style.-----------------------------------------------------------------------------*/virtual void injectMouseMove(int relX, int relY){
//            static int lastX = evt.x();
//            static int lastY = evt.y();
//            int relX = evt.x() - lastX;
//            int relY = evt.y() - lastY;
//            lastX = evt.x();
//            lastY = evt.y();if (mStyle == CS_ORBIT){Ogre::Real dist = (mCamera->getPosition() - mTarget->_getDerivedPosition()).length();if (mOrbiting)   // yaw around the target, and pitch locally{mCamera->setPosition(mTarget->_getDerivedPosition());mCamera->yaw(Ogre::Degree(-relX * 0.025f));mCamera->pitch(Ogre::Degree(-relY * 0.025f));mCamera->moveRelative(Ogre::Vector3(0, 0, dist));// don't let the camera go over the top or around the bottom of the target}else if (mZooming)  // move the camera toward or away from the target{// the further the camera is, the faster it movesmCamera->moveRelative(Ogre::Vector3(0, 0, relY * 0.004f * dist));}}else if (mStyle == CS_FREELOOK){mCamera->yaw(Ogre::Degree(-relX * 0.15f));mCamera->pitch(Ogre::Degree(-relY * 0.15f));}}/*-----------------------------------------------------------------------------| Processes mouse movement differently for each style.-----------------------------------------------------------------------------*/virtual void injectWheelMove(const QWheelEvent& evt){int relZ = evt.delta();if (mStyle == CS_ORBIT){Ogre::Real dist = (mCamera->getPosition() - mTarget->_getDerivedPosition()).length();if (relZ != 0)  // move the camera toward or away from the target{// the further the camera is, the faster it movesmCamera->moveRelative(Ogre::Vector3(0, 0, -relZ * 0.0008f * dist));}}}/*-----------------------------------------------------------------------------| Processes mouse presses. Only applies for orbit style.| Left button is for orbiting, and right button is for zooming.-----------------------------------------------------------------------------*/virtual void injectMouseDown(const QMouseEvent& evt){if (mStyle == CS_ORBIT){if (evt.buttons() & Qt::LeftButton) mOrbiting = true;else if (evt.buttons() & Qt::RightButton) mZooming = true;}}/*-----------------------------------------------------------------------------| Processes mouse releases. Only applies for orbit style.| Left button is for orbiting, and right button is for zooming.-----------------------------------------------------------------------------*/virtual void injectMouseUp(const QMouseEvent& evt){if (mStyle == CS_ORBIT){if (evt.buttons() & Qt::LeftButton) mOrbiting = false;else if (evt.buttons() & Qt::RightButton) mZooming = false;}}protected:Ogre::Camera* mCamera;CameraStyle mStyle;Ogre::SceneNode* mTarget;bool mOrbiting;bool mZooming;Ogre::Real mTopSpeed;Ogre::Vector3 mVelocity;bool mGoingForward;bool mGoingBack;bool mGoingLeft;bool mGoingRight;bool mGoingUp;bool mGoingDown;bool mFastMove;};
}#endif

QT 和Ogre Demo相关推荐

  1. Qt 2D painting Demo 的翻译

    目录名字 Qt 2D painting Demo 的翻译 Helper Class 定义 Helper Class 的实现 Widget Class 定义 Widget Class 实现 GLWidg ...

  2. Qt使用Ogre引擎开发3d项目

    对于个人开发者来说,选择开源工具应该是最好的选择. 此次选择 开源建模软件Blender + 开源3d渲染引擎Ogre + 开源程序框架Qt来实现. Ogre下载 https://www.ogre3d ...

  3. 从零开始做3D地图编辑器 基于QT与OGRE

    第一章 基础知识 注:文章里面有不少个人见解,欢迎大家一起互相讨论.希望高人能给予相应理解与意见建议. 在实际3D游戏开发中,编辑器是极其重要的一个部分,一个优秀健壮的编辑器,可以使项目事半功倍,而相 ...

  4. QT与OGRE做3D地图编辑器

    http://blog.163.com/modingfa_002/blog/static/1109254662010427114343461/ http://download.chinaprj.cn/ ...

  5. 从零开始做3D地图编辑器(基于QT与OGRE)

    第一章 基础知识 注:文章里面有不少个人见解,欢迎大家一起互相讨论.希望高人能给予相应理解与意见建议. 在实际3D游戏开发中,编辑器是极其重要的一个部分,一个优秀健壮的编辑器,可以使项目事半功倍,而相 ...

  6. (Qt项视图Demo)封装下链式结构(QListView)的MVC(MVD)用法

    对于一些数据量小的列表我们使用QListWidget往往能满足开发的需求,但是对于大数据量的展示来说(几十万,上百万)来说的话,全部加载是一个不是很合适的方法.因此我们使用MVC,这里可能应该叫MVD ...

  7. 从零开始做3D地图编辑器(六)(基于QT与OGRE)

    五.OGRE基础知识 友善提醒:如果你对OGRE比较了解,请自觉跳过此节. 本节并不打算提供详细的入门教程,只是对OGRE的简单介绍,如果需要OGRE的详细资料,请自行使用网络功能. 1.OGRE是什 ...

  8. Qt的打印机Demo

    先看看小Demo的效果: 总结: 1.QPrinterInfo类(提供了简单的打印机的信息,比如打印机的个数.各个打印机的名字.默认打印机名字等等) 代码: QPrinterInfo info;QSt ...

  9. Qt+VS2015 五子棋demo——以button按钮作为棋子实现单人五子棋

    实现功能 1.初始化棋盘(exe启动后,展示完整的棋盘) 2.重置功能:有重置按钮,点击重新初始化棋盘 3.计时功能:第一颗棋子落下后,开始计时,五颗棋子连在一起以后结束计时,并提示完成游戏 4.下棋 ...

  10. qt:热成像demo

    已经测试通过,内含源码和exe文件 添加链接描述

最新文章

  1. Unirest 轻量级的HTTP开发库
  2. 2019年最新深度强化学习PPT(DeepMind制作)
  3. c语言中字符减减自符意思,C语言中的自加自减运算
  4. python操作csv文件
  5. mysql 获取倒数第二_如何从MySQL中的表中获取倒数第二条记录?
  6. 我们和全球的朋友一起回家
  7. 华为云大数据存储的冗余方式是三副本_华为TaurusDB技术解读(转载)
  8. 流媒体服务器 NTV Media Server G3 电视回看功能赏析
  9. 爆火的Java面试题-kafka源码解析与实战豆瓣
  10. SQLserver锁和事务隔离级别的比较与使用
  11. UAV021(六):系统架构优化、SBUS协议、遥控器控制电机转动
  12. 连接共享打印机0xc00000bcb
  13. Activiti 7 配置及相关流程一站式介绍(包含基础流程及网关应用)
  14. 用了这些软件,写代码有了飞一般的速度
  15. 机器学习----高斯过程回归
  16. 粒子群算法(6)-----几个适应度评价函数
  17. 嵌入式研发人员核心竞争力分析
  18. 滤波器主要参数及特性
  19. Python3字典合并的几种方法
  20. 官方yolov5s.pt ,yolo5x.pt下载地址

热门文章

  1. C#中的Obsolete特性
  2. oracle11g64位怎么用sql,PLSQL Developer连接不上Oracle11g64位的解决办法
  3. 0008:《以色列:一个国家的诞生》读后感
  4. 红帽企业linux8,红帽发布企业版 Linux(RHEL) 8.0
  5. php wamp一键环境包,phpwind本地环境一键安装包Wamp 5.0使用说明
  6. 大小写字母的ASCII的对照转换
  7. esxi添加硬盘驱动
  8. 英语3500词(14/20)dynasty主题 (2022.1.26)
  9. explain ref_面试前一定要知道的MySQL命令【explain】
  10. Lab: Exploiting XSS to perform CSRF:利用XSS执行CSRF