diff options
-rw-r--r-- | cameranodeobject.cpp | 41 | ||||
-rw-r--r-- | cameranodeobject.h | 51 | ||||
-rw-r--r-- | declarativeviewtexture.cpp | 1 | ||||
-rw-r--r-- | example.qml | 38 | ||||
-rw-r--r-- | ogrewidget.cpp | 18 | ||||
-rw-r--r-- | ogrewidget.h | 3 | ||||
-rw-r--r-- | qmlogre.pro | 8 | ||||
-rw-r--r-- | resources/data.zip (renamed from data.zip) | bin | 885163 -> 885163 bytes | |||
-rw-r--r-- | resources/example.qml | 311 | ||||
-rw-r--r-- | resources/logo.png (renamed from logo.png) | bin | 1478 -> 1478 bytes | |||
-rw-r--r-- | resources/move.gif | bin | 0 -> 921 bytes |
11 files changed, 424 insertions, 47 deletions
diff --git a/cameranodeobject.cpp b/cameranodeobject.cpp new file mode 100644 index 0000000..7fe7c4f --- /dev/null +++ b/cameranodeobject.cpp @@ -0,0 +1,41 @@ +#include "cameranodeobject.h" + +#include <OgreRoot.h> +#include <OgreSceneNode.h> +#include <OgreCamera.h> + +static const Ogre::Vector3 initialPosition(0, 0, 300); + +CameraNodeObject::CameraNodeObject(Ogre::Camera *cam, QObject *parent) : + QObject(parent), + m_camera(cam), + m_yaw(0), + m_pitch(0), + m_zoom(1) +{ + m_node = Ogre::Root::getSingleton().getSceneManager("mySceneManager")->getRootSceneNode()->createChildSceneNode(); + m_node->attachObject(cam); + cam->move(initialPosition); +} + +void CameraNodeObject::resetPosition() +{ + m_yaw = 0; + m_pitch = 0; + updateRotation(); +} + +void CameraNodeObject::updateRotation() +{ + m_node->resetOrientation(); + m_node->yaw(Ogre::Radian(Ogre::Degree(m_yaw))); + m_node->pitch(Ogre::Radian(Ogre::Degree(m_pitch))); +} + +void CameraNodeObject::setZoom(qreal z) +{ + m_zoom = z; + m_node->resetOrientation(); + m_camera->setPosition(initialPosition * (1 / m_zoom)); + updateRotation(); +} diff --git a/cameranodeobject.h b/cameranodeobject.h new file mode 100644 index 0000000..9c296fd --- /dev/null +++ b/cameranodeobject.h @@ -0,0 +1,51 @@ +#ifndef CAMERANODEOBJECT_H +#define CAMERANODEOBJECT_H + +#include <QObject> + +namespace Ogre { +class SceneNode; +class Camera; +} + +class CameraNodeObject : public QObject +{ + Q_OBJECT + Q_PROPERTY(qreal yaw READ yaw WRITE setYaw) + Q_PROPERTY(qreal pitch READ pitch WRITE setPitch) + Q_PROPERTY(qreal zoom READ zoom WRITE setZoom) +public: + explicit CameraNodeObject(Ogre::Camera *cam, QObject *parent = 0); + + Ogre::SceneNode *sceneNode() const + { return m_node; } + Ogre::Camera *camera() const + { return m_camera; } + + qreal yaw() const + { return m_yaw; } + qreal pitch() const + { return m_pitch; } + qreal zoom() const + { return m_zoom; } + void setYaw(qreal y) + { m_yaw = y; updateRotation(); } + void setPitch(qreal p) + { m_pitch = p; updateRotation(); } + void setZoom(qreal z); + +public Q_SLOTS: + void resetPosition(); + +private: + void updateRotation(); + + Ogre::SceneNode *m_node; + Ogre::Camera *m_camera; + + qreal m_yaw; + qreal m_pitch; + qreal m_zoom; +}; + +#endif // CAMERANODEOBJECT_H diff --git a/declarativeviewtexture.cpp b/declarativeviewtexture.cpp index 951c1e3..eb1ea08 100644 --- a/declarativeviewtexture.cpp +++ b/declarativeviewtexture.cpp @@ -32,6 +32,7 @@ DeclarativeViewTexture::DeclarativeViewTexture(QWidget *parent) : { setAttribute(Qt::WA_DontShowOnScreen); setOptimizationFlag(QGraphicsView::IndirectPainting); + setRenderHints(QPainter::Antialiasing | QPainter::TextAntialiasing | QPainter::SmoothPixmapTransform); glGenTextures(1, &m_textureId); } diff --git a/example.qml b/example.qml deleted file mode 100644 index 4fadfe5..0000000 --- a/example.qml +++ /dev/null @@ -1,38 +0,0 @@ -import Qt 4.7 - -Item { - id: item1 - width: 1024 - height: 768 - clip: true - - Rectangle { - id: rectangle1 - y: 193 - width: 135 - height: 412 - color: "#64ffffff" - radius: 20 - anchors.left: parent.left - anchors.leftMargin: 28 - anchors.verticalCenter: parent.verticalCenter - border.width: 3 - border.color: "#e6161616" - clip: true - - Image { - id: image1 - height: 40 - opacity: 0.4 - anchors.top: parent.top - anchors.topMargin: 14 - anchors.right: parent.right - anchors.rightMargin: 0 - anchors.left: parent.left - anchors.leftMargin: 0 - fillMode: "PreserveAspectFit" - smooth: true - source: "logo.png" - } - } -} diff --git a/ogrewidget.cpp b/ogrewidget.cpp index dfe1b5a..c62dd40 100644 --- a/ogrewidget.cpp +++ b/ogrewidget.cpp @@ -1,6 +1,7 @@ #include "ogrewidget.h" #include "declarativeviewtexture.h" +#include "cameranodeobject.h" #include <OgreRoot.h> #include <OgreRenderWindow.h> @@ -10,6 +11,7 @@ #include <OgreEntity.h> #include <OgreResourceGroupManager.h> #include <OgreMaterialManager.h> +#include <QtDeclarative/QDeclarativeContext> #include <QtCore/QDebug> #if defined(Q_WS_X11) @@ -23,6 +25,7 @@ OgreWidget::OgreWidget(QWidget *parent) : m_sceneManager(0), m_renderWindow(0), m_viewport(0), + m_cameraObject(0), m_QmlUI(0) { setAutoBufferSwap(false); @@ -48,6 +51,7 @@ OgreWidget::~OgreWidget() } delete m_root; + delete m_cameraObject; } void OgreWidget::paintGL() @@ -107,7 +111,8 @@ void OgreWidget::initializeGL() m_QmlUI = new DeclarativeViewTexture(this); m_QmlUI->setResizeMode(QDeclarativeView::SizeRootObjectToView); - m_QmlUI->setSource(QUrl("example.qml")); + m_QmlUI->setSource(QUrl("resources/example.qml")); + m_QmlUI->rootContext()->setContextProperty("Camera", m_cameraObject); } void OgreWidget::resizeGL(int w, int h) @@ -169,19 +174,18 @@ void OgreWidget::initOgre() m_renderWindow->setVisible(true); // Load resources - Ogre::ResourceGroupManager::getSingleton().addResourceLocation("data.zip", "Zip"); + Ogre::ResourceGroupManager::getSingleton().addResourceLocation("resources/data.zip", "Zip"); Ogre::ResourceGroupManager::getSingleton().initialiseAllResourceGroups(); // Setup scene m_sceneManager = m_root->createSceneManager(Ogre::ST_GENERIC, "mySceneManager"); m_camera = m_sceneManager->createCamera("myCamera"); - m_camera->setNearClipDistance(200); + m_camera->setNearClipDistance(1); m_camera->setFarClipDistance(99999); m_viewport = m_renderWindow->addViewport(m_camera); m_viewport->setBackgroundColour(Ogre::ColourValue(1, 1, 1)); m_viewport->setClearEveryFrame(true); m_camera->setAspectRatio(Ogre::Real(width()) / Ogre::Real(height())); - //m_camera->setFOVy(Ogre::Radian(Ogre::Degree(20))); // Setup content... @@ -194,6 +198,8 @@ void OgreWidget::initOgre() // create an ogre head entity and place it at the origin m_sceneManager->getRootSceneNode()->attachObject(m_sceneManager->createEntity("Head", "ogrehead.mesh")); - m_camera->move(Ogre::Vector3(0, 0, 300)); - m_camera->lookAt(0, 0, 0); + + // Setup the camera + m_cameraObject = new CameraNodeObject(m_camera); + m_cameraObject->camera()->setAutoTracking(true, m_sceneManager->getRootSceneNode()); } diff --git a/ogrewidget.h b/ogrewidget.h index d1a2ec4..abd01d3 100644 --- a/ogrewidget.h +++ b/ogrewidget.h @@ -16,6 +16,7 @@ class Viewport; class RenderTarget; } class DeclarativeViewTexture; +class CameraNodeObject; class OgreWidget : public QGLWidget { @@ -50,6 +51,8 @@ private: Ogre::RenderWindow *m_renderWindow; Ogre::Viewport *m_viewport; + CameraNodeObject *m_cameraObject; + DeclarativeViewTexture *m_QmlUI; }; diff --git a/qmlogre.pro b/qmlogre.pro index 62527c3..9f1ad7a 100644 --- a/qmlogre.pro +++ b/qmlogre.pro @@ -41,11 +41,13 @@ MOC_DIR = ./.moc SOURCES += main.cpp \ ogrewidget.cpp \ - declarativeviewtexture.cpp + declarativeviewtexture.cpp \ + cameranodeobject.cpp HEADERS += \ ogrewidget.h \ - declarativeviewtexture.h + declarativeviewtexture.h \ + cameranodeobject.h OTHER_FILES += \ - example.qml + resources/example.qml diff --git a/data.zip b/resources/data.zip Binary files differindex 02ef61f..02ef61f 100644 --- a/data.zip +++ b/resources/data.zip diff --git a/resources/example.qml b/resources/example.qml new file mode 100644 index 0000000..9ea6f64 --- /dev/null +++ b/resources/example.qml @@ -0,0 +1,311 @@ +import Qt 4.7 + +Item { + id: item1 + width: 1024 + height: 768 + clip: true + + Rectangle { + id: rectangle1 + width: 139 + height: 212 + radius: 15 + gradient: Gradient { + GradientStop { + id: gradientstop3 + position: 0 + color: "#6f6f6f" + } + + GradientStop { + id: gradientstop4 + position: 0.27 + color: "#141414" + } + + GradientStop { + id: gradientstop5 + position: 1 + color: "#50000000" + } + } + anchors.left: rectangle2.left + anchors.leftMargin: -5 + anchors.top: rectangle2.bottom + anchors.topMargin: 6 + z: 0 + border.width: 4 + border.color: "#1a1a1a" + clip: false + + Behavior on opacity { PropertyAnimation { } } + + Image { + id: image1 + width: 135 + height: 31 + opacity: 0.8 + anchors.top: parent.top + anchors.topMargin: 9 + anchors.right: parent.right + anchors.rightMargin: 0 + anchors.left: parent.left + anchors.leftMargin: 0 + fillMode: "PreserveAspectFit" + smooth: true + source: "logo.png" + } + + Rectangle { + id: rectangle3 + x: 89 + y: 95 + width: 24 + height: 26 + color: "#ffffff" + + MouseArea { + id: mouse_area1 + anchors.fill: parent + + onPressed: Camera.yaw += 10 + } + } + + Rectangle { + id: rectangle4 + x: 27 + y: 95 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area2 + anchors.fill: parent + + onPressed: Camera.yaw -= 10 + } + } + + Rectangle { + id: rectangle5 + x: 58 + y: 64 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area3 + anchors.fill: parent + + onPressed: Camera.pitch -= 10 + } + } + + Rectangle { + id: rectangle6 + x: 58 + y: 126 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area4 + x: 0 + y: -1 + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + anchors.leftMargin: 0 + anchors.topMargin: 0 + anchors.fill: parent + + onPressed: Camera.pitch += 10 + } + } + + Rectangle { + id: rectangle9 + x: 89 + y: 171 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area7 + x: 0 + y: 0 + anchors.fill: parent + anchors.topMargin: 0 + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + anchors.leftMargin: 0 + + onPressed: Camera.zoom += 0.15 + } + } + + Rectangle { + id: rectangle7 + x: 58 + y: 95 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area5 + x: 0 + y: -1 + anchors.fill: parent + anchors.topMargin: 0 + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + anchors.leftMargin: 0 + + onClicked: Camera.resetPosition() + } + } + + Rectangle { + id: rectangle8 + x: 27 + y: 171 + width: 24 + height: 26 + color: "#ffffff" + MouseArea { + id: mouse_area6 + x: 0 + y: -1 + anchors.fill: parent + anchors.topMargin: 0 + anchors.rightMargin: 0 + anchors.bottomMargin: 0 + anchors.leftMargin: 0 + + onPressed: Camera.zoom -= 0.15 + } + } + } + + Rectangle { + id: rectangle2 + x: 31 + y: 269 + width: 25 + height: 25 + radius: 5 + gradient: Gradient { + GradientStop { + position: 0 + color: "#c83e3e3e" + } + + GradientStop { + position: 1 + color: "#c8919191" + } + } + + border.width: 2 + border.color: "#1a1a1a" + z: -1 + + Image { + id: image2 + anchors.rightMargin: 5 + anchors.leftMargin: 5 + anchors.bottomMargin: 5 + anchors.topMargin: 5 + anchors.fill: parent + smooth: true + fillMode: "Stretch" + source: "move.gif" + } + + MouseArea { + anchors.fill: parent + drag.target: rectangle2 + drag.axis: "XandYAxis" + drag.minimumX: 0 + drag.minimumY: 0 + drag.maximumX: item1.width - rectangle2.width + drag.maximumY: item1.height - rectangle2.height + } + } + + Rectangle { + id: rectangle10 + width: 25 + radius: 5 + gradient: Gradient { + GradientStop { + id: gradientstop1 + position: 0 + color: "#c83e3e3e" + } + + GradientStop { + id: gradientstop2 + position: 1 + color: "#c8919191" + } + } + anchors.left: rectangle2.right + anchors.leftMargin: 6 + anchors.top: rectangle2.top + anchors.bottom: rectangle2.bottom + border.color: "#1a1a1a" + + MouseArea { + anchors.fill: parent + drag.minimumY: 0 + drag.axis: "XandYAxis" + drag.minimumX: 0 + drag.target: rectangle10 + drag.maximumY: item1.height - rectangle10.height + drag.maximumX: item1.width - rectangle10.width + + onClicked: item1.state = item1.state == '' ? 'State1' : '' + } + + Rectangle { + id: rectangle11 + x: 0 + y: -2 + radius: 12 + gradient: Gradient { + GradientStop { + position: 0 + color: "#5a5a5a" + } + + GradientStop { + position: 1 + color: "#000000" + } + } + rotation: -35 + anchors.rightMargin: 6 + anchors.bottomMargin: 6 + anchors.leftMargin: 6 + anchors.topMargin: 6 + anchors.fill: parent + } + border.width: 2 + z: -1 + } + states: [ + State { + name: "State1" + + PropertyChanges { + target: rectangle1 + opacity: 0 + } + } + ] + + + +} diff --git a/logo.png b/resources/logo.png Binary files differindex d75936b..d75936b 100644 --- a/logo.png +++ b/resources/logo.png diff --git a/resources/move.gif b/resources/move.gif Binary files differnew file mode 100644 index 0000000..6bddcad --- /dev/null +++ b/resources/move.gif |