Back to home page

EIC code displayed by LXR

 
 

    


File indexing completed on 2025-01-18 10:02:58

0001 // Copyright (c) 2020 OPEN CASCADE SAS
0002 //
0003 // This file is part of Open CASCADE Technology software library.
0004 //
0005 // This library is free software; you can redistribute it and/or modify it under
0006 // the terms of the GNU Lesser General Public License version 2.1 as published
0007 // by the Free Software Foundation, with special exception defined in the file
0008 // OCCT_LGPL_EXCEPTION.txt. Consult the file LICENSE_LGPL_21.txt included in OCCT
0009 // distribution for complete text of the license and disclaimer of any warranty.
0010 //
0011 // Alternatively, this file may be used under the terms of Open CASCADE
0012 // commercial license or contractual agreement.
0013 
0014 #ifndef _Aspect_OpenVRSession_HeaderFile
0015 #define _Aspect_OpenVRSession_HeaderFile
0016 
0017 #include <Aspect_XRSession.hxx>
0018 
0019 //! OpenVR wrapper implementing Aspect_XRSession interface.
0020 class Aspect_OpenVRSession : public Aspect_XRSession
0021 {
0022   DEFINE_STANDARD_RTTIEXT(Aspect_OpenVRSession, Aspect_XRSession)
0023 public:
0024 
0025   //! Return TRUE if an HMD may be presented on the system (e.g. to show VR checkbox in application GUI).
0026   //! This is fast check, and even if it returns TRUE, opening session may fail.
0027   Standard_EXPORT static bool IsHmdPresent();
0028 
0029 public:
0030 
0031   //! Empty constructor.
0032   Standard_EXPORT Aspect_OpenVRSession();
0033 
0034   //! Destructor.
0035   Standard_EXPORT virtual ~Aspect_OpenVRSession();
0036 
0037   //! Return TRUE if session is opened.
0038   Standard_EXPORT virtual bool IsOpen() const Standard_OVERRIDE;
0039 
0040   //! Initialize session.
0041   Standard_EXPORT virtual bool Open() Standard_OVERRIDE;
0042 
0043   //! Release session.
0044   Standard_EXPORT virtual void Close() Standard_OVERRIDE;
0045 
0046   //! Fetch actual poses of tracked devices.
0047   Standard_EXPORT virtual bool WaitPoses() Standard_OVERRIDE;
0048 
0049   //! Return recommended viewport Width x Height for rendering into VR.
0050   virtual NCollection_Vec2<int> RecommendedViewport() const Standard_OVERRIDE { return myRendSize; }
0051 
0052   //! Return transformation from eye to head.
0053   //! vr::GetEyeToHeadTransform() wrapper.
0054   Standard_EXPORT virtual NCollection_Mat4<double> EyeToHeadTransform (Aspect_Eye theEye) const Standard_OVERRIDE;
0055 
0056   //! Return projection matrix.
0057   Standard_EXPORT virtual NCollection_Mat4<double> ProjectionMatrix (Aspect_Eye theEye,
0058                                                                      double theZNear,
0059                                                                      double theZFar) const Standard_OVERRIDE;
0060 
0061   //! Return TRUE.
0062   virtual bool HasProjectionFrustums() const Standard_OVERRIDE { return true; }
0063 
0064   //! Receive XR events.
0065   Standard_EXPORT virtual void ProcessEvents() Standard_OVERRIDE;
0066 
0067   //! Submit texture eye to XR Composer.
0068   //! @param theTexture     [in] texture handle
0069   //! @param theGraphicsLib [in] graphics library in which texture handle is defined
0070   //! @param theColorSpace  [in] texture color space;
0071   //!                            sRGB means no color conversion by composer;
0072   //!                            Linear means to sRGB color conversion by composer
0073   //! @param theEye [in] eye to display
0074   //! @return FALSE on error
0075   Standard_EXPORT virtual bool SubmitEye (void* theTexture,
0076                                           Aspect_GraphicsLibrary theGraphicsLib,
0077                                           Aspect_ColorSpace theColorSpace,
0078                                           Aspect_Eye theEye) Standard_OVERRIDE;
0079 
0080   //! Query information.
0081   Standard_EXPORT virtual TCollection_AsciiString GetString (InfoString theInfo) const Standard_OVERRIDE;
0082 
0083   //! Return index of tracked device of known role.
0084   Standard_EXPORT virtual Standard_Integer NamedTrackedDevice (Aspect_XRTrackedDeviceRole theDevice) const Standard_OVERRIDE;
0085 
0086   //! Fetch data for digital input action (like button).
0087   Standard_EXPORT virtual Aspect_XRDigitalActionData GetDigitalActionData (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE;
0088 
0089   //! Fetch data for analog input action (like axis).
0090   Standard_EXPORT virtual Aspect_XRAnalogActionData GetAnalogActionData (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE;
0091 
0092   //! Fetch data for pose input action (like fingertip position).
0093   Standard_EXPORT virtual Aspect_XRPoseActionData GetPoseActionDataForNextFrame (const Handle(Aspect_XRAction)& theAction) const Standard_OVERRIDE;
0094 
0095   //! Set tracking origin.
0096   Standard_EXPORT virtual void SetTrackingOrigin (TrackingUniverseOrigin theOrigin) Standard_OVERRIDE;
0097 
0098 protected:
0099 
0100   //! Find location of default actions manifest file (based on CSF_OCCTResourcePath or CASROOT variables).
0101   Standard_EXPORT TCollection_AsciiString defaultActionsManifest();
0102 
0103   //! Release OpenVR device.
0104   Standard_EXPORT void closeVR();
0105 
0106   //! Update projection frustums.
0107   Standard_EXPORT virtual void updateProjectionFrustums();
0108 
0109   //! Init VR input.
0110   Standard_EXPORT virtual bool initInput();
0111 
0112   //! Handle tracked device activation.
0113   Standard_EXPORT virtual void onTrackedDeviceActivated (Standard_Integer theDeviceIndex);
0114 
0115   //! Handle tracked device deactivation.
0116   Standard_EXPORT virtual void onTrackedDeviceDeactivated (Standard_Integer theDeviceIndex);
0117 
0118   //! Handle tracked device update.
0119   Standard_EXPORT virtual void onTrackedDeviceUpdated (Standard_Integer theDeviceIndex);
0120 
0121   //! Trigger vibration.
0122   Standard_EXPORT virtual void triggerHapticVibrationAction (const Handle(Aspect_XRAction)& theAction,
0123                                                              const Aspect_XRHapticActionData& theParams) Standard_OVERRIDE;
0124 
0125   //! Return model for displaying device.
0126   Standard_EXPORT virtual Handle(Graphic3d_ArrayOfTriangles) loadRenderModel (Standard_Integer theDevice,
0127                                                                               Standard_Boolean theToApplyUnitFactor,
0128                                                                               Handle(Image_Texture)& theTexture) Standard_OVERRIDE;
0129 
0130 protected:
0131 
0132   //! Access vr::IVRSystem* - OpenVR session object.
0133   Standard_EXPORT void* getVRSystem() const;
0134 
0135 private:
0136 
0137   //! Internal fields
0138   struct VRContext;
0139   class VRImagePixmap;
0140   class VRTextureSource;
0141 
0142 protected:
0143 
0144   VRContext* myContext;
0145   TCollection_AsciiString myActionsManifest;
0146 
0147 };
0148 
0149 #endif // _Aspect_OpenVRSession_HeaderFile