Historique des modifications - Message

Message #11827

Sujet: Implémentation Oculus rift CV1


Type Date Auteur Contenu
Création du message 20-09-2017 21:39:51 Magun
Oh oh ! Salut Copland big_smile
ravi de te revoir dans le coin et de savoir que tu te relance dans l'aventure !

j'ai utiliser openvr qui est un genre de framework pour utiliser ce genre de device (occulus, steamvr)
mais avec openscenegraph, je pensse pas que ce soit difficile a porter sur irrlicht





Device.hDevice.cppTexture.hTexture.cpp
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
#ifndef _OSG_OPENVRDEVICE_H_
#define _OSG_OPENVRDEVICE_H_

#include <openvr/openvr.h>

#include <osg/Geode>
#include <osg/Texture2D>
#include <osg/Version>
#include <osg/FrameBufferObject>
#include <mutex>

#include "EventHandler.h"
#include "Texture.h"

namespace sacred
{
    namespace openvr
    {
        namespace device
        {
            class Device : public osg::Referenced
            {
                public:
                    typedef enum Eye_
                    {
                        LEFT = 0,
                        RIGHT = 1,
                        COUNT = 2
                    } Eye;

                    Device(float nearClip, float farClip, const float worldUnitsPerMetre = 1.0f, const int samples = 0);

                    void createRenderBuffers(osg::ref_ptr<osg::State> state);

                    void init();
                    void shutdown(osg::GraphicsContext *gc);

                    static bool hmdPresent();
                    bool hmdInitialized() const;

                    osg::Matrix projectionMatrixCenter() const;
                    osg::Matrix projectionMatrixLeft() const;
                    osg::Matrix projectionMatrixRight() const;

                    osg::Matrix projectionOffsetMatrixLeft() const;
                    osg::Matrix projectionOffsetMatrixRight() const;

                    osg::Matrix viewMatrixLeft() const;
                    osg::Matrix viewMatrixRight() const;

                    float nearClip() const
                    {
                        return m_nearClip;
                    }
                    float farClip() const
                    {
                        return m_farClip;
                    }

                    void resetSensorOrientation() const;
                    void updatePose();

                    osg::Vec3 position() const
                    {
                        return m_position;
                    }
                    osg::Quat orientation() const
                    {
                        return m_orientation;
                    }

                    osg::Camera *createRTTCamera(Device::Eye eye, osg::Transform::ReferenceFrame referenceFrame, const osg::Vec4 &clearColor, osg::GraphicsContext *gc = 0) const;

                    bool submitFrame();
                    void blitMirrorTexture(osg::GraphicsContext *gc);

                    osg::GraphicsContext::Traits *graphicsContextTraits() const;
                protected:
                    ~Device(); // Since we inherit from osg::Referenced we must make destructor protected

                    void calculateEyeAdjustment();
                    void calculateProjectionMatrices();

                    void trySetProcessAsHighPriority() const;

                    vr::IVRSystem *m_vrSystem;
                    vr::IVRRenderModels *m_vrRenderModels;
                    const float m_worldUnitsPerMetre;

                    //osg::ref_ptr<TextureBuffer> m_textureBuffer[2];
                    //osg::ref_ptr<MirrorTexture> m_mirrorTexture;
                    TextureBuffer *m_textureBuffer[2];
                    MirrorTexture *m_mirrorTexture;

                    osg::Matrixf m_leftEyeProjectionMatrix;
                    osg::Matrixf m_rightEyeProjectionMatrix;
                    osg::Vec3f m_leftEyeAdjust;
                    osg::Vec3f m_rightEyeAdjust;

                    osg::Vec3 m_position;
                    osg::Quat m_orientation;

                    float m_nearClip;
                    float m_farClip;
                    int m_samples;
                private:
                    std::string GetDeviceProperty(vr::TrackedDeviceProperty prop);
                    Device(const Device &); // Do not allow copy
                    Device &operator=(const Device &); // Do not allow assignment operator.
            };

            class RealizeOperation : public osg::GraphicsOperation
            {
                public:
                    explicit RealizeOperation(osg::ref_ptr<Device> device) :
                        osg::GraphicsOperation("OpenVRRealizeOperation", false), m_device(device), m_realized(false) {}

                    virtual void operator()(osg::GraphicsContext *gc);

                    bool realized() const
                    {
                        return m_realized;
                    }
                protected:
                    std::mutex  _mutex;
                    osg::observer_ptr<Device> m_device;
                    bool m_realized;
            };
        }
    }
}

#endif /* _OSG_OPENVRDEVICE_H_ */


et tu as quelques operations a faire pour le rendu:

Code c++ :


            // configure

            osg::ref_ptr<osg::Camera> camera = m_view->getCamera();
            osg::ref_ptr<osg::GraphicsContext> gc =  camera->getGraphicsContext();
            osg::ref_ptr<callback::Swap> swapCallback = new callback::Swap(m_device);

            gc->setSwapCallback(swapCallback);

            osg::Vec4 clearColor = camera->getClearColor();
            camera->setProjectionMatrix(m_device->projectionMatrixCenter());
            camera->setName("Main");

            m_cameraRTTLeft = m_device->createRTTCamera(device::Device::LEFT, osg::Camera::RELATIVE_RF, clearColor, gc);
            m_cameraRTTRight = m_device->createRTTCamera(device::Device::RIGHT, osg::Camera::RELATIVE_RF, clearColor, gc);
            m_cameraRTTLeft->setName("LeftRTT");
            m_cameraRTTRight->setName("RightRTT");

            m_view->addSlave(m_cameraRTTLeft.get(), m_device->projectionOffsetMatrixLeft(), m_device->viewMatrixLeft(), true);
            m_view->getSlave(0)._updateSlaveCallback = new callback::UpdateSlave(callback::UpdateSlave::LEFT_CAMERA, m_device.get(), swapCallback.get());

            m_view->addSlave(m_cameraRTTRight.get(), m_device->projectionOffsetMatrixRight(), m_device->viewMatrixRight(), true);
            m_view->getSlave(1)._updateSlaveCallback = new callback::UpdateSlave(callback::UpdateSlave::RIGHT_CAMERA, m_device.get(), swapCallback.get());

            m_view->setLightingMode(osg::View::SKY_LIGHT);
            camera->setGraphicsContext(nullptr);
			
            if(gui_handler)
            {				
                gui_handler->setCameraCallbacks(m_cameraRTTLeft.get());
                gui_handler->setCameraCallbacks(m_cameraRTTRight.get());
            }

               // update

               device::TextureBuffer *m_textureBuffer;
               osg::RenderInfo &renderInfo;

                m_textureBuffer->onPreRender(renderInfo);
                m_textureBuffer->onPostRender(renderInfo);

                // swapBuffersImplementation(osg::GraphicsContext *gc):

                m_device->submitFrame();
                m_device->blitMirrorTexture(gc);
                gc->swapBuffersImplementation();


                // updateSlave(osg::View &view, osg::View::Slave &slave)

                if(m_cameraType == LEFT_CAMERA)
                    m_device->updatePose();

                osg::Vec3 position = m_device->position();
                osg::Quat orientation = m_device->orientation();
                osg::Matrix viewOffset = (m_cameraType == LEFT_CAMERA) ? m_device->viewMatrixLeft() : m_device->viewMatrixRight();

                viewOffset.preMultRotate(orientation);
                viewOffset.setTrans(viewOffset.getTrans() + position);

                slave._viewOffset = viewOffset;
                slave.updateSlaveImplementation(view);


voila je t'ai mis un code un peux brute, tu me dit ce que tu arrive a en tirer wink
perso je suis passer par cmake + cygwin + openvr (avec steamvr) ce qui ma poser quelques soucis et j'ai du modifier les sources de openvr pour compiler correctement ...
evidement le but c'est de généré deux image décaler, ce qui pose des soucis de performances pour irrlicht qui cherche a re trier la scene et recalculer les mesh dynamique en fonction du changement de position de la camera
il faudras surment faire un patch pour optimiser un poils, cela dit, deux device irrlicht peut etre envisagable avec un partage des ressources entre les deux contexte opengl
et du coup proposer un device irrlicht "natif" wink

j'espère que ça te seras un peu utile wink

Retour

Options Liens officiels Caractéristiques Statistiques Communauté
Préférences cookies
Corrections
irrlicht
irrklang
irredit
irrxml
Propulsé par Django
xhtml 1.0
css 2.1
884 membres
1440 sujets
11337 messages
Dernier membre inscrit: Saidov17
161 invités en ligne
membre en ligne: -
RSS Feed