b40cdc2b |
1 | // Copyright (c) 2020 OPEN CASCADE SAS |
2 | // |
3 | // This file is part of Open CASCADE Technology software library. |
4 | // |
5 | // This library is free software; you can redistribute it and/or modify it under |
6 | // the terms of the GNU Lesser General Public License version 2.1 as published |
7 | // by the Free Software Foundation, with special exception defined in the file |
8 | // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT |
9 | // distribution for complete text of the license and disclaimer of any warranty. |
10 | // |
11 | // Alternatively, this file may be used under the terms of Open CASCADE |
12 | // commercial license or contractual agreement. |
13 | |
14 | #ifndef _Aspect_OpenVRSession_HeaderFile |
15 | #define _Aspect_OpenVRSession_HeaderFile |
16 | |
17 | #include <Aspect_XRSession.hxx> |
18 | |
19 | //! OpenVR wrapper implementing Aspect_XRSession interface. |
20 | class Aspect_OpenVRSession : public Aspect_XRSession |
21 | { |
22 | DEFINE_STANDARD_RTTIEXT(Aspect_OpenVRSession, Aspect_XRSession) |
23 | public: |
24 | |
25 | //! Return TRUE if an HMD may be presented on the system (e.g. to show VR checkbox in application GUI). |
26 | //! This is fast check, and even if it returns TRUE, opening session may fail. |
27 | Standard_EXPORT static bool IsHmdPresent(); |
28 | |
29 | public: |
30 | |
31 | //! Empty constructor. |
32 | Standard_EXPORT Aspect_OpenVRSession(); |
33 | |
34 | //! Destructor. |
35 | Standard_EXPORT virtual ~Aspect_OpenVRSession(); |
36 | |
37 | //! Return TRUE if session is opened. |
38 | Standard_EXPORT virtual bool IsOpen() const Standard_OVERRIDE; |
39 | |
40 | //! Initialize session. |
41 | Standard_EXPORT virtual bool Open() Standard_OVERRIDE; |
42 | |
43 | //! Release session. |
44 | Standard_EXPORT virtual void Close() Standard_OVERRIDE; |
45 | |
46 | //! Fetch actual poses of tracked devices. |
47 | Standard_EXPORT virtual bool WaitPoses() Standard_OVERRIDE; |
48 | |
49 | //! Return recommended viewport Width x Height for rendering into VR. |
50 | virtual NCollection_Vec2<int> RecommendedViewport() const Standard_OVERRIDE { return myRendSize; } |
51 | |
52 | //! Return transformation from eye to head. |
53 | //! vr::GetEyeToHeadTransform() wrapper. |
54 | Standard_EXPORT virtual NCollection_Mat4<double> EyeToHeadTransform (Aspect_Eye theEye) const Standard_OVERRIDE; |
55 | |
56 | //! Return projection matrix. |
57 | Standard_EXPORT virtual NCollection_Mat4<double> ProjectionMatrix (Aspect_Eye theEye, |
58 | double theZNear, |
59 | double theZFar) const Standard_OVERRIDE; |
60 | |
61 | //! Return TRUE. |
62 | virtual bool HasProjectionFrustums() const Standard_OVERRIDE { return true; } |
63 | |
64 | //! Receive XR events. |
65 | Standard_EXPORT virtual void ProcessEvents() Standard_OVERRIDE; |
66 | |
67 | //! Submit texture eye to XR Composer. |
68 | //! @param theTexture [in] texture handle |
69 | //! @param theGraphicsLib [in] graphics library in which texture handle is defined |
70 | //! @param theColorSpace [in] texture color space; |
71 | //! sRGB means no color conversion by composer; |
72 | //! Linear means to sRGB color conversion by composer |
73 | //! @param theEye [in] eye to display |
74 | //! @return FALSE on error |
75 | Standard_EXPORT virtual bool SubmitEye (void* theTexture, |
76 | Aspect_GraphicsLibrary theGraphicsLib, |
77 | Aspect_ColorSpace theColorSpace, |
78 | Aspect_Eye theEye) Standard_OVERRIDE; |
79 | |
80 | //! Query information. |
81 | Standard_EXPORT virtual TCollection_AsciiString GetString (InfoString theInfo) const Standard_OVERRIDE; |
82 | |
83 | //! Return index of tracked device of known role. |
84 | Standard_EXPORT virtual Standard_Integer NamedTrackedDevice (Aspect_XRTrackedDeviceRole theDevice) const Standard_OVERRIDE; |
85 | |
86 | //! Fetch data for digital input action (like button). |
87 | Standard_EXPORT virtual Aspect_XRDigitalActionData GetDigitalActionData (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE; |
88 | |
89 | //! Fetch data for analog input action (like axis). |
90 | Standard_EXPORT virtual Aspect_XRAnalogActionData GetAnalogActionData (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE; |
91 | |
92 | //! Fetch data for pose input action (like fingertip position). |
93 | Standard_EXPORT virtual Aspect_XRPoseActionData GetPoseActionDataForNextFrame (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE; |
94 | |
95 | //! Set tracking origin. |
96 | Standard_EXPORT virtual void SetTrackingOrigin (TrackingUniverseOrigin theOrigin) Standard_OVERRIDE; |
97 | |
98 | protected: |
99 | |
100 | //! Find location of default actions manifest file (based on CSF_OCCTResourcePath or CASROOT variables). |
101 | Standard_EXPORT TCollection_AsciiString defaultActionsManifest(); |
102 | |
103 | //! Release OpenVR device. |
104 | Standard_EXPORT void closeVR(); |
105 | |
106 | //! Update projection frustums. |
107 | Standard_EXPORT virtual void updateProjectionFrustums(); |
108 | |
109 | //! Init VR input. |
110 | Standard_EXPORT virtual bool initInput(); |
111 | |
112 | //! Handle tracked device activation. |
113 | Standard_EXPORT virtual void onTrackedDeviceActivated (Standard_Integer theDeviceIndex); |
114 | |
115 | //! Handle tracked device deactivation. |
116 | Standard_EXPORT virtual void onTrackedDeviceDeactivated (Standard_Integer theDeviceIndex); |
117 | |
118 | //! Handle tracked device update. |
119 | Standard_EXPORT virtual void onTrackedDeviceUpdated (Standard_Integer theDeviceIndex); |
120 | |
121 | //! Trigger vibration. |
122 | Standard_EXPORT virtual void triggerHapticVibrationAction (const Handle(Aspect_XRAction)& theAction, |
123 | const Aspect_XRHapticActionData& theParams) Standard_OVERRIDE; |
124 | |
125 | //! Return model for displaying device. |
126 | Standard_EXPORT virtual Handle(Graphic3d_ArrayOfTriangles) loadRenderModel (Standard_Integer theDevice, |
127 | Standard_Boolean theToApplyUnitFactor, |
128 | Handle(Image_Texture)& theTexture) Standard_OVERRIDE; |
129 | |
130 | protected: |
131 | |
132 | //! Access vr::IVRSystem* - OpenVR session object. |
133 | Standard_EXPORT void* getVRSystem() const; |
134 | |
135 | private: |
136 | |
137 | //! Internal fields |
138 | struct VRContext; |
139 | class VRImagePixmap; |
140 | class VRTextureSource; |
141 | |
142 | protected: |
143 | |
144 | VRContext* myContext; |
145 | TCollection_AsciiString myActionsManifest; |
146 | |
147 | }; |
148 | |
149 | #endif // _Aspect_OpenVRSession_HeaderFile |