def update(self, headset_pose, x, y, z): h_x = headset_pose.m[0][3] h_y = headset_pose.m[1][3] h_z = headset_pose.m[2][3] dst = ((h_x - x)**2 + (h_y - y)**2 + (h_z - z)**2)**0.5 if dst < min_dst: dst = min_dst if dst > max_dst: dst = max_dst dst_norm = 1 - (dst - min_dst) / max_dst alpha = (dst_norm * (min_alpha - max_alpha)) + max_alpha rotate = initRotationMatrix(0, 0) transform = matMul33(rotate, headset_pose) transform.m[0][3] = float(x) transform.m[1][3] = float(y) transform.m[2][3] = float(z) ulOverlayHandle = self.ovr eTrackingOrigin = openvr.TrackingUniverseRawAndUncalibrated fn = self.vroverlay.function_table.setOverlayTransformAbsolute pmatTrackingOriginToOverlayTransform = transform result = fn(ulOverlayHandle, eTrackingOrigin, openvr.byref(pmatTrackingOriginToOverlayTransform)) check_result(result) check_result(self.vroverlay.setOverlayAlpha(self.ovr, alpha))
def move(self, point, size): self.transform[0][3] = point.x self.transform[1][3] = point.y self.transform[2][3] = point.z print(point.x, point.y, point.z) self.size = size fn = self.vroverlay.function_table.setOverlayTransformAbsolute fn(self.wheel, openvr.TrackingUniverseSeated, openvr.byref(self.transform)) check_result(self.vroverlay.setOverlayWidthInMeters(self.wheel, size))
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))
def rotate(self, angles, axis=[2,]): try: self.rotation_matrix except AttributeError: self.rotation_matrix = openvr.HmdMatrix34_t() if not isinstance(angles, list): angles = [angles, ] if not isinstance(axis, list): axis = [axis, ] result = copy.copy(self.transform) for angle, ax in zip(angles, axis): initRotationMatrix(ax, -angle, self.rotation_matrix) result = matMul33(self.rotation_matrix, result) fn = self.vroverlay.function_table.setOverlayTransformAbsolute fn(self.wheel, openvr.TrackingUniverseSeated, openvr.byref(result))
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))