Beispiel #1
0
    def initializeOculusRift(self):
        """
        This function initializes the Oculus Rift device and
        retrieves the device information and
        starts the sensor.
        """

        # Initialize the LibOVR (Oculus Rift SDK)
        oculusvr.ovr_Initialize()

        # Create an HMD device object using the first available HMD available
        self.HMD= oculusvr.ovrHmd_Create(0)

        # Check if there is no active device
        # If there is no active device initialize the debug mode
        if not self.HMD:
            self.HMD=oculusvr.ovrHmd_CreateDebug(True)

        # get more details about the device in the HMDDesc object
        # struct_ovrHmdDesc_ is eqaul to ovrHmdDesc of Oculus Rift C API
        self.HMDDesc=oculusvr.struct_ovrHmdDesc_()
        oculusvr.ovrHmd_GetDesc(self.HMD, oculusvr.byref(self.HMDDesc))

        # Start the sensor if possible
        self.isSensorEnabled_ = oculusvr.ovrHmd_StartSensor(self.HMD,
                                                            oculusvr.ovrSensorCap_Orientation | oculusvr.ovrSensorCap_YawCorrection,
                                                            oculusvr.ovrSensorCap_Orientation)
Beispiel #2
0
    def Render(self,graphContext,graphCanvas):
        """
        This function is called by the GraphCanvas object of Gluskap to render each frame
        :param graphContext: The GraphContext object used to draw the graph
        """

        # If rendering the first frame store the graphContext Object, load the first graph and remove Gluskap textures
        if self.isFirstRender_:
            self.isFirstRender_=False
            self.graphContext_=graphContext
            self.saveTextures()
            self.removeTextures()
            self.gotoNextGraph()

        # Check the gamepad status and apply it to camera
        self.applyGamePad(graphContext.camera)

        # Begin the Oculus Rift frame
        oculusvr.ovrHmd_BeginFrame(self.HMD,0)
        glBindFramebuffer(GL_FRAMEBUFFER, self.FrameBufferID) # Bind the frame buffer
        glClear(GL_COLOR_BUFFER_BIT | GL_DEPTH_BUFFER_BIT)

        for eye in range(0,2):
            eyeType=self.HMDDesc.EyeRenderOrder[eye]

            # Get the projection matrix
            projectionMatrix=oculusvr.ovrMatrix4f_Projection(self.HMDDesc.DefaultEyeFov[eyeType],1.0, 700.0, '\x01')

            # Apply the projection matrix
            glMatrixMode(GL_PROJECTION)
            glLoadMatrixf(projectionMatrix.toList())

            # Start the eye render and grab the sensor data in eyePose
            eyePose=oculusvr.ovrHmd_BeginEyeRender(self.HMD,eyeType)

            # Roatate the Gluskap camera based on Oculus Rift sensor data
            self.rotateCamera(graphContext.camera,eyePose)

            eyeTexture=self.EyeTextures[eyeType]
            # Configure the viewport
            glViewport(eyeTexture.RenderViewport.Pos.x, eyeTexture.RenderViewport.Pos.y,
                       eyeTexture.RenderViewport.Size.w, eyeTexture.RenderViewport.Size.h)

            if self.isPrintMessageStarted_:
                self.drawMessage("Printing...")
            elif self.isLoadingMessageStarted_:
                self.drawMessage("Loading...")
            else:
                # Draw the graph using Gluskap's drawing engine
                graphContext.draw()

            oculusvr.ovrHmd_EndEyeRender(self.HMD,eyeType,eyePose,oculusvr.byref(eyeTexture))

        glBindFramebuffer(GL_FRAMEBUFFER, 0) # Unbind the frame buffer
        graphCanvas.SwapBuffers()
        oculusvr.ovrHmd_EndFrame(self.HMD)