def _init_vr(self):
     # initialize vr interface
     openvr.init(openvr.VRApplication_Scene)
     self._width, self._height =(2048, 1280)#openvr.IVRSystem().getRecommendedRenderTargetSize()
     print("VR Interace Open")
     self._overlay = openvr.IVROverlay().createOverlay("VR_Overlay", "VROverlay")
     
     openvr.IVROverlay().setOverlayFromFile(self._overlay, 'PATH TO FILE HERE' )
     self._position_vr_overlay()
Beispiel #2
0
    def __init__(self, name):
        self._name = name
        image_default_path = os.path.abspath(
            os.path.join(os.path.dirname(__file__), '..', 'images'))
        image_file = os.path.join(image_default_path, name + '.png')
        default_image_file = os.path.join(image_default_path, 'default.png')
        print("Looking for a SharedPlayspace avatar in {}".format(image_file))
        if os.path.exists(image_file):
            print("Found it!")
            self._image_file = image_file
        else:
            print("Not found! Using default! {}".format(default_image_file))
            self._image_file = default_image_file

        self.sys = openvr.VRSystem()
        self.vroverlay = openvr.IVROverlay()
        result, self.ovr = self.vroverlay.createOverlay(
            self._name.encode(), self._name.encode())
        check_result(self.vroverlay.setOverlayColor(self.ovr, 1, 1, 1))
        check_result(self.vroverlay.setOverlayAlpha(self.ovr, 1))
        check_result(self.vroverlay.setOverlayWidthInMeters(self.ovr, 0.3))
        check_result(
            self.vroverlay.setOverlayFromFile(self.ovr,
                                              self._image_file.encode()))
        check_result(self.vroverlay.showOverlay(self.ovr))
 def _position_vr_overlay(self):        # initialize overlay & setup transform to fix overlay to display viewport
     Transform_Type= (ctypes.c_float * 4) * 3
     transform = Transform_Type()
     transform[0][0]  = 1
     transform[0][1]  = 0
     transform[0][2]  = 0
     transform[0][3]  = 0
     
     transform[1][0] = 0
     transform[1][1] = 1
     transform[1][2] = 0
     transform[1][3] = 0
     
     transform[2][0] = 0
     transform[2][1] = 0
     transform[2][2] = 1
     transform[2][3] = -1
     self._hmd_transform = openvr.HmdMatrix34_t()
     self._hmd_transform.m = transform
     
 #set overlay to be fixed to hmd viewport
     openvr.IVROverlay().setOverlayTransformTrackedDeviceRelative(
           self._overlay,
           0,
           self._hmd_transform)
    def update(self):
        self._update_texture()
        glBindFramebuffer(GL_FRAMEBUFFER, self._fbo)
        glViewport(0, 0, self._width, self._height)
        self._draw()
        glBindFramebuffer(GL_FRAMEBUFFER, 0)

        glBindTexture(GL_TEXTURE_2D, self._view_tex)
#         openvr.IVROverlay().setOverlayFlag(
#             self._overlay,
#             openvr.VROverlayFlags_SortWithNonSceneOverlays,
#             True)
        openvr.IVROverlay().showOverlay(self._overlay)
        self._overlay_tex = openvr.Texture_t()
        self._overlay_tex.handle = self._view_tex
        self._overlay_tex.eType = openvr.TextureType_OpenGL
        self._overlay_tex.eColorSpace = openvr.ColorSpace_Auto    
#         openvr.IVROverlay().setOverlayColor(self._overlay, 1.0, 1.0, 1.0)
        openvr.IVROverlay().setOverlayTexture(self._overlay, self._overlay_tex)
        openvr.IVRCompositor().submit(openvr.Eye_Right,self._overlay_tex)
Beispiel #5
0
    def __init__(self, x=0, y=-0.4, z=-0.35, size=0.55):
        self.vrsys = openvr.VRSystem()
        self.vroverlay = openvr.IVROverlay()
        result, self.wheel = self.vroverlay.createOverlay(
            'keyiiii'.encode(), 'keyiiii'.encode())
        check_result(result)

        check_result(self.vroverlay.setOverlayColor(self.wheel, 1, 1, 1))
        check_result(self.vroverlay.setOverlayAlpha(self.wheel, 1))
        check_result(self.vroverlay.setOverlayWidthInMeters(self.wheel, size))

        this_dir = os.path.abspath(os.path.dirname(__file__))
        wheel_img = os.path.join(this_dir, 'media', 'steering_wheel.png')

        check_result(
            self.vroverlay.setOverlayFromFile(self.wheel, wheel_img.encode()))

        result, transform = self.vroverlay.setOverlayTransformAbsolute(
            self.wheel, openvr.TrackingUniverseSeated)

        transform[0][0] = 1.0
        transform[0][1] = 0.0
        transform[0][2] = 0.0
        transform[0][3] = x

        transform[1][0] = 0.0
        transform[1][1] = 1.0
        transform[1][2] = 0.0
        transform[1][3] = y

        transform[2][0] = 0.0
        transform[2][1] = 0.0
        transform[2][2] = 1.0
        transform[2][3] = z

        self.transform = transform
        self.size = size

        fn = self.vroverlay.function_table.setOverlayTransformAbsolute
        pmatTrackingOriginToOverlayTransform = transform
        result = fn(self.wheel, openvr.TrackingUniverseSeated,
                    openvr.byref(pmatTrackingOriginToOverlayTransform))

        check_result(result)
        check_result(self.vroverlay.showOverlay(self.wheel))
Beispiel #6
0
    def __init__(self, left_ctr, right_ctr):
        self._handl_closed = False
        self._handr_closed = False
        self.left_ctr = left_ctr
        self.right_ctr = right_ctr
        hand_size = 0.15

        self.vrsys = openvr.VRSystem()
        self.vroverlay = openvr.IVROverlay()

        result, self.l_ovr = self.vroverlay.createOverlay(
            'left_hand'.encode(), 'left_hand'.encode())
        result, self.r_ovr = self.vroverlay.createOverlay(
            'right_hand'.encode(), 'right_hand'.encode())

        check_result(self.vroverlay.setOverlayColor(self.l_ovr, 1, 1, 1))
        check_result(self.vroverlay.setOverlayColor(self.r_ovr, 1, 1, 1))
        check_result(self.vroverlay.setOverlayAlpha(self.l_ovr, 1))
        check_result(self.vroverlay.setOverlayAlpha(self.r_ovr, 1))
        check_result(
            self.vroverlay.setOverlayWidthInMeters(self.l_ovr, hand_size))
        check_result(
            self.vroverlay.setOverlayWidthInMeters(self.r_ovr, hand_size))

        this_dir = os.path.abspath(os.path.dirname(__file__))

        self.l_open_png = os.path.join(this_dir, 'media', 'hand_open_l.png')
        self.r_open_png = os.path.join(this_dir, 'media', 'hand_open_r.png')
        self.l_close_png = os.path.join(this_dir, 'media', 'hand_closed_l.png')
        self.r_close_png = os.path.join(this_dir, 'media', 'hand_closed_r.png')

        check_result(
            self.vroverlay.setOverlayFromFile(self.l_ovr,
                                              self.l_open_png.encode()))
        check_result(
            self.vroverlay.setOverlayFromFile(self.r_ovr,
                                              self.r_open_png.encode()))

        result, transform = self.vroverlay.setOverlayTransformTrackedDeviceRelative(
            self.l_ovr, self.left_ctr.id)
        result, transform = self.vroverlay.setOverlayTransformTrackedDeviceRelative(
            self.r_ovr, self.right_ctr.id)

        transform[0][0] = 1.0
        transform[0][1] = 0.0
        transform[0][2] = 0.0
        transform[0][3] = 0

        transform[1][0] = 0.0
        transform[1][1] = 1.0
        transform[1][2] = 0.0
        transform[1][3] = 0

        transform[2][0] = 0.0
        transform[2][1] = 0.0
        transform[2][2] = 1.0
        transform[2][3] = 0

        self.transform = transform

        rotate = initRotationMatrix(0, -pi / 2)
        self.transform = matMul33(rotate, self.transform)

        fn = self.vroverlay.function_table.setOverlayTransformTrackedDeviceRelative
        result = fn(self.l_ovr, self.left_ctr.id, openvr.byref(self.transform))
        result = fn(self.r_ovr, self.right_ctr.id,
                    openvr.byref(self.transform))

        check_result(result)
        check_result(self.vroverlay.showOverlay(self.l_ovr))
        check_result(self.vroverlay.showOverlay(self.r_ovr))
Beispiel #7
0
leftId = openvr.VRSystem().getTrackedDeviceIndexForControllerRole(
    openvr.TrackedControllerRole_LeftHand)
rightId = openvr.VRSystem().getTrackedDeviceIndexForControllerRole(
    openvr.TrackedControllerRole_RightHand)


def to_percent(value):
    return str(value * 100)[0:2]


def writefile(left, right):
    datafile = open("../storage/ovr.txt", "w")
    left = to_percent(left)
    right = to_percent(right)
    datafile.write("{:2s}.{:2s}".format(str(left), str(right)))
    datafile.close()


while True:
    overlay = openvr.IVROverlay()
    notification = openvr.IVRNotifications()
    left_battery = openvr.VRSystem().getFloatTrackedDeviceProperty(
        leftId, openvr.Prop_DeviceBatteryPercentage_Float)
    right_battery = openvr.VRSystem().getFloatTrackedDeviceProperty(
        rightId, openvr.Prop_DeviceBatteryPercentage_Float)

    writefile(left_battery, right_battery)

    time.sleep(60)